Spaces:
Sleeping
Sleeping
Update document_generator.py
Browse files- document_generator.py +8 -30
document_generator.py
CHANGED
@@ -11,7 +11,6 @@ OUTPUT IN FOLLOWING JSON FORMAT enclosed in <output> tags
|
|
11 |
"Author": "Author Name",
|
12 |
"Date": "YYYY-MM-DD",
|
13 |
"Version": "1.0",
|
14 |
-
|
15 |
"Sections": [
|
16 |
{
|
17 |
"SectionNumber": "1",
|
@@ -52,7 +51,6 @@ OUTPUT IN FOLLOWING JSON FORMAT enclosed in <output> tags
|
|
52 |
"Author": "Author Name",
|
53 |
"Date": "YYYY-MM-DD",
|
54 |
"Version": "1.0",
|
55 |
-
|
56 |
"Sections": [
|
57 |
{
|
58 |
"SectionNumber": "1",
|
@@ -163,7 +161,7 @@ from typing import List, Dict, Optional, Any, Callable, Union
|
|
163 |
from openai import OpenAI
|
164 |
import logging
|
165 |
import functools
|
166 |
-
from fastapi import APIRouter, HTTPException, Request, UploadFile, File
|
167 |
from fastapi.responses import StreamingResponse
|
168 |
from pydantic import BaseModel
|
169 |
from fastapi_cache.decorator import cache
|
@@ -456,17 +454,12 @@ class JsonDocumentResponse(BaseModel):
|
|
456 |
class JsonDocumentRequest(BaseModel):
|
457 |
query: str
|
458 |
template: bool = False
|
459 |
-
images: Optional[List[
|
460 |
-
documents: Optional[List[Union[UploadFile, str]]] = None
|
461 |
-
conversation_id: str = ""
|
462 |
-
|
463 |
-
class Config:
|
464 |
-
arbitrary_types_allowed = True
|
465 |
|
466 |
class MarkdownDocumentRequest(BaseModel):
|
467 |
json_document: Dict
|
468 |
query: str
|
469 |
-
|
470 |
|
471 |
MESSAGE_DELIMITER = b"\n---DELIMITER---\n"
|
472 |
|
@@ -535,10 +528,9 @@ async def generate_document_stream(document_generator: DocumentGenerator, docume
|
|
535 |
|
536 |
db_manager.update_database("elevatics", query, markdown_document)
|
537 |
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
):
|
542 |
ai_client = AIClient()
|
543 |
document_generator = DocumentGenerator(ai_client)
|
544 |
|
@@ -556,21 +548,9 @@ async def generate_document_outline_endpoint(
|
|
556 |
|
557 |
|
558 |
@cache(expire=600*24*7)
|
559 |
-
@router.post("/generate-document/json"
|
560 |
-
async def generate_document_outline_endpoint(
|
561 |
-
query: str,
|
562 |
-
template: bool = False,
|
563 |
-
images: Optional[List[UploadFile]] = File(None),
|
564 |
-
documents: Optional[List[UploadFile]] = File(None),
|
565 |
-
conversation_id: str = ""
|
566 |
):
|
567 |
-
request = JsonDocumentRequest(
|
568 |
-
query=query,
|
569 |
-
template=template,
|
570 |
-
images=images,
|
571 |
-
documents=documents,
|
572 |
-
conversation_id=conversation_id
|
573 |
-
)
|
574 |
ai_client = AIClient()
|
575 |
document_generator = DocumentGenerator(ai_client)
|
576 |
vision_tools = VisionTools(ai_client)
|
@@ -651,8 +631,6 @@ async def get_last_observations(limit: int = 10, format: str = "json"):
|
|
651 |
raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")
|
652 |
|
653 |
|
654 |
-
|
655 |
-
|
656 |
###########################################
|
657 |
class MarkdownDocumentResponse(BaseModel):
|
658 |
markdown_document: str
|
|
|
11 |
"Author": "Author Name",
|
12 |
"Date": "YYYY-MM-DD",
|
13 |
"Version": "1.0",
|
|
|
14 |
"Sections": [
|
15 |
{
|
16 |
"SectionNumber": "1",
|
|
|
51 |
"Author": "Author Name",
|
52 |
"Date": "YYYY-MM-DD",
|
53 |
"Version": "1.0",
|
|
|
54 |
"Sections": [
|
55 |
{
|
56 |
"SectionNumber": "1",
|
|
|
161 |
from openai import OpenAI
|
162 |
import logging
|
163 |
import functools
|
164 |
+
from fastapi import APIRouter, HTTPException, Request, UploadFile, File
|
165 |
from fastapi.responses import StreamingResponse
|
166 |
from pydantic import BaseModel
|
167 |
from fastapi_cache.decorator import cache
|
|
|
454 |
class JsonDocumentRequest(BaseModel):
|
455 |
query: str
|
456 |
template: bool = False
|
457 |
+
images: Optional[List[UploadFile]] = File(None)
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
class MarkdownDocumentRequest(BaseModel):
|
460 |
json_document: Dict
|
461 |
query: str
|
462 |
+
template: bool = False
|
463 |
|
464 |
MESSAGE_DELIMITER = b"\n---DELIMITER---\n"
|
465 |
|
|
|
528 |
|
529 |
db_manager.update_database("elevatics", query, markdown_document)
|
530 |
|
531 |
+
|
532 |
+
@router.post("/generate-document/markdown-stream")
|
533 |
+
async def generate_markdown_document_stream_endpoint(request: MarkdownDocumentRequest):
|
|
|
534 |
ai_client = AIClient()
|
535 |
document_generator = DocumentGenerator(ai_client)
|
536 |
|
|
|
548 |
|
549 |
|
550 |
@cache(expire=600*24*7)
|
551 |
+
@router.post("/generate-document/json")
|
552 |
+
async def generate_document_outline_endpoint(request: jsonDocumentRequest):
|
|
|
|
|
|
|
|
|
|
|
553 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
ai_client = AIClient()
|
555 |
document_generator = DocumentGenerator(ai_client)
|
556 |
vision_tools = VisionTools(ai_client)
|
|
|
631 |
raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")
|
632 |
|
633 |
|
|
|
|
|
634 |
###########################################
|
635 |
class MarkdownDocumentResponse(BaseModel):
|
636 |
markdown_document: str
|