Skip to content

Commit

Permalink
rename artifact to document generator tool
Browse files Browse the repository at this point in the history
  • Loading branch information
leehuwuj committed Sep 27, 2024
1 parent 6c1d47e commit 6182b5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion helpers/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const supportedTools: Tool[] = [
name: TOOL_SYSTEM_PROMPT_ENV_VAR,
description: "System prompt for DuckDuckGo search tool.",
value: `You are a DuckDuckGo search agent.
You can use the duckduckgo search tool to get information from the web to answer user questions.
You can use the duckduckgo search tool to get information or images from the web to answer user questions.
For better results, you can specify the region parameter to get results from a specific region but it's optional.`,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
OUTPUT_DIR = "output/tools"


class ArtifactType(Enum):
class DocumentType(Enum):
PDF = "pdf"
HTML = "html"

Expand Down Expand Up @@ -98,7 +98,7 @@ class ArtifactType(Enum):
"""


class ArtifactGenerator:
class DocumentGenerator:
@classmethod
def _generate_html_content(cls, original_content: str) -> str:
"""
Expand Down Expand Up @@ -159,36 +159,36 @@ def _generate_html(cls, html_content: str) -> str:
)

@classmethod
def generate_artifact(
cls, original_content: str, artifact_type: str, file_name: str
def generate_document(
cls, original_content: str, document_type: str, file_name: str
) -> str:
"""
To generate artifact as PDF or HTML file.
Parameters:
original_content: str (markdown style)
artifact_type: str (pdf or html) specify the type of the file format based on the use case
document_type: str (pdf or html) specify the type of the file format based on the use case
file_name: str (name of the artifact file) must be a valid file name, no extensions needed
Returns:
str (URL to the artifact file): A file URL ready to serve.
"""
try:
artifact_type = ArtifactType(artifact_type.lower())
document_type = DocumentType(document_type.lower())
except ValueError:
raise ValueError(
f"Invalid artifact type: {artifact_type}. Must be 'pdf' or 'html'."
f"Invalid document type: {document_type}. Must be 'pdf' or 'html'."
)
# Always generate html content first
html_content = cls._generate_html_content(original_content)

# Based on the type of artifact, generate the corresponding file
if artifact_type == ArtifactType.PDF:
if document_type == DocumentType.PDF:
content = cls._generate_pdf(html_content)
file_extension = "pdf"
elif artifact_type == ArtifactType.HTML:
elif document_type == DocumentType.HTML:
content = BytesIO(cls._generate_html(html_content).encode("utf-8"))
file_extension = "html"
else:
raise ValueError(f"Unexpected artifact type: {artifact_type}")
raise ValueError(f"Unexpected document type: {document_type}")

file_name = cls._validate_file_name(file_name)
file_path = os.path.join(OUTPUT_DIR, f"{file_name}.{file_extension}")
Expand Down Expand Up @@ -226,4 +226,4 @@ def _validate_file_name(file_name: str) -> str:


def get_tools(**kwargs):
return [FunctionTool.from_defaults(ArtifactGenerator.generate_artifact)]
return [FunctionTool.from_defaults(DocumentGenerator.generate_document)]

0 comments on commit 6182b5a

Please sign in to comment.