Spaces:
Sleeping
Sleeping
Update document_generator.py
Browse files- document_generator.py +19 -11
document_generator.py
CHANGED
@@ -257,27 +257,35 @@ router = APIRouter()
|
|
257 |
class DocumentRequest(BaseModel):
|
258 |
query: str
|
259 |
|
260 |
-
class
|
261 |
json_document: Dict
|
|
|
|
|
262 |
markdown_document: str
|
263 |
|
264 |
@cache(expire=600*24*7)
|
265 |
-
@router.post("/generate-document", response_model=
|
266 |
-
async def
|
267 |
ai_client = AIClient()
|
268 |
document_generator = DocumentGenerator(ai_client)
|
269 |
-
|
270 |
try:
|
271 |
-
# Generate the document
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
json_document = document_generator.generate_document(request.query)
|
273 |
-
|
274 |
# Convert to Markdown
|
275 |
markdown_document = MarkdownConverter.convert_to_markdown(json_document["Document"])
|
276 |
-
|
277 |
-
return DocumentResponse(
|
278 |
-
json_document=json_document,
|
279 |
-
markdown_document=markdown_document
|
280 |
-
)
|
281 |
except Exception as e:
|
282 |
raise HTTPException(status_code=500, detail=str(e))
|
283 |
|
|
|
257 |
class DocumentRequest(BaseModel):
|
258 |
query: str
|
259 |
|
260 |
+
class JsonDocumentResponse(BaseModel):
|
261 |
json_document: Dict
|
262 |
+
|
263 |
+
class MarkdownDocumentResponse(BaseModel):
|
264 |
markdown_document: str
|
265 |
|
266 |
@cache(expire=600*24*7)
|
267 |
+
@router.post("/generate-document/json", response_model=JsonDocumentResponse)
|
268 |
+
async def generate_json_document_endpoint(request: DocumentRequest):
|
269 |
ai_client = AIClient()
|
270 |
document_generator = DocumentGenerator(ai_client)
|
|
|
271 |
try:
|
272 |
+
# Generate the JSON document
|
273 |
+
json_document = document_generator.generate_document(request.query)
|
274 |
+
return JsonDocumentResponse(json_document=json_document)
|
275 |
+
except Exception as e:
|
276 |
+
raise HTTPException(status_code=500, detail=str(e))
|
277 |
+
|
278 |
+
@cache(expire=600*24*7)
|
279 |
+
@router.post("/generate-document/markdown", response_model=MarkdownDocumentResponse)
|
280 |
+
async def generate_markdown_document_endpoint(request: DocumentRequest):
|
281 |
+
ai_client = AIClient()
|
282 |
+
document_generator = DocumentGenerator(ai_client)
|
283 |
+
try:
|
284 |
+
# Generate the JSON document
|
285 |
json_document = document_generator.generate_document(request.query)
|
|
|
286 |
# Convert to Markdown
|
287 |
markdown_document = MarkdownConverter.convert_to_markdown(json_document["Document"])
|
288 |
+
return MarkdownDocumentResponse(markdown_document=markdown_document)
|
|
|
|
|
|
|
|
|
289 |
except Exception as e:
|
290 |
raise HTTPException(status_code=500, detail=str(e))
|
291 |
|