Skip to content

Commit

Permalink
update tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
luiztauffer committed Nov 12, 2023
1 parent 028d000 commit 7d490be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion pieces/TextTaggingPiece/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class InputModel(BaseModel):
"""
input_text: str = Field(
description='Source text to be tagged.',
json_schema_extra={"from_upstream": "always"}
)
openai_model: LLMModelType = Field(
default=LLMModelType.gpt_3_5_turbo,
Expand Down
18 changes: 17 additions & 1 deletion pieces/TextTaggingPiece/piece.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,23 @@ def piece_function(self, input_data: InputModel, secrets_data: SecretsModel):
schema=schema,
llm=llm
)

res = chain.run(input_text)

# Format display result as markdown
self.format_display_result(input_data, res)

return OutputModel(**res)

def format_display_result(self, input_data: InputModel, result: dict):
md_text = """## Tags\n"""
for k, v in result.items():
md_text += f"""**{k}**: {v}\n"""
md_text += "\n"
md_text += f"""**Input text**: {input_data.input_text}\n"""
file_path = f"{self.results_path}/display_result.md"
with open(file_path, "w") as f:
f.write(md_text)
self.display_result = {
"file_type": "md",
"file_path": file_path
}

0 comments on commit 7d490be

Please sign in to comment.