|
9 | 9 | OUTPUT_DIR = "output/tools"
|
10 | 10 |
|
11 | 11 |
|
12 |
| -class ArtifactType(Enum): |
| 12 | +class DocumentType(Enum): |
13 | 13 | PDF = "pdf"
|
14 | 14 | HTML = "html"
|
15 | 15 |
|
@@ -98,7 +98,7 @@ class ArtifactType(Enum):
|
98 | 98 | """
|
99 | 99 |
|
100 | 100 |
|
101 |
| -class ArtifactGenerator: |
| 101 | +class DocumentGenerator: |
102 | 102 | @classmethod
|
103 | 103 | def _generate_html_content(cls, original_content: str) -> str:
|
104 | 104 | """
|
@@ -159,36 +159,36 @@ def _generate_html(cls, html_content: str) -> str:
|
159 | 159 | )
|
160 | 160 |
|
161 | 161 | @classmethod
|
162 |
| - def generate_artifact( |
163 |
| - cls, original_content: str, artifact_type: str, file_name: str |
| 162 | + def generate_document( |
| 163 | + cls, original_content: str, document_type: str, file_name: str |
164 | 164 | ) -> str:
|
165 | 165 | """
|
166 | 166 | To generate artifact as PDF or HTML file.
|
167 | 167 | Parameters:
|
168 | 168 | original_content: str (markdown style)
|
169 |
| - artifact_type: str (pdf or html) specify the type of the file format based on the use case |
| 169 | + document_type: str (pdf or html) specify the type of the file format based on the use case |
170 | 170 | file_name: str (name of the artifact file) must be a valid file name, no extensions needed
|
171 | 171 | Returns:
|
172 | 172 | str (URL to the artifact file): A file URL ready to serve.
|
173 | 173 | """
|
174 | 174 | try:
|
175 |
| - artifact_type = ArtifactType(artifact_type.lower()) |
| 175 | + document_type = DocumentType(document_type.lower()) |
176 | 176 | except ValueError:
|
177 | 177 | raise ValueError(
|
178 |
| - f"Invalid artifact type: {artifact_type}. Must be 'pdf' or 'html'." |
| 178 | + f"Invalid document type: {document_type}. Must be 'pdf' or 'html'." |
179 | 179 | )
|
180 | 180 | # Always generate html content first
|
181 | 181 | html_content = cls._generate_html_content(original_content)
|
182 | 182 |
|
183 | 183 | # Based on the type of artifact, generate the corresponding file
|
184 |
| - if artifact_type == ArtifactType.PDF: |
| 184 | + if document_type == DocumentType.PDF: |
185 | 185 | content = cls._generate_pdf(html_content)
|
186 | 186 | file_extension = "pdf"
|
187 |
| - elif artifact_type == ArtifactType.HTML: |
| 187 | + elif document_type == DocumentType.HTML: |
188 | 188 | content = BytesIO(cls._generate_html(html_content).encode("utf-8"))
|
189 | 189 | file_extension = "html"
|
190 | 190 | else:
|
191 |
| - raise ValueError(f"Unexpected artifact type: {artifact_type}") |
| 191 | + raise ValueError(f"Unexpected document type: {document_type}") |
192 | 192 |
|
193 | 193 | file_name = cls._validate_file_name(file_name)
|
194 | 194 | file_path = os.path.join(OUTPUT_DIR, f"{file_name}.{file_extension}")
|
@@ -226,4 +226,4 @@ def _validate_file_name(file_name: str) -> str:
|
226 | 226 |
|
227 | 227 |
|
228 | 228 | def get_tools(**kwargs):
|
229 |
| - return [FunctionTool.from_defaults(ArtifactGenerator.generate_artifact)] |
| 229 | + return [FunctionTool.from_defaults(DocumentGenerator.generate_document)] |
0 commit comments