pvanand commited on
Commit
5ed7976
·
verified ·
1 Parent(s): 005cbc2

Update document_generator_v2.py

Browse files
Files changed (1) hide show
  1. document_generator_v2.py +19 -8
document_generator_v2.py CHANGED
@@ -607,26 +607,37 @@ async def generate_document_outline_endpoint(
607
  ai_client = AIClient()
608
  document_generator = DocumentGenerator(ai_client)
609
  vision_tools = VisionTools(ai_client)
610
-
611
  try:
 
612
  image_context = ""
613
  if images:
614
  image_context = await vision_tools.extract_images_info(images)
615
-
616
  # Store the image_context in the cache
617
- cache_key = f"image_context_{conversation_id}"
618
- await FastAPICache.get_backend().set(cache_key, image_context, expire=3600) # Cache for 1 hour
619
-
 
 
 
 
 
 
 
 
 
620
  json_document = document_generator.generate_document_outline(
621
  query,
622
  template,
623
- image_context=image_context
 
624
  )
625
-
626
  if json_document is None:
627
  raise HTTPException(status_code=500, detail="Failed to generate a valid document outline")
628
-
629
  return JsonDocumentResponse(json_document=json_document)
 
630
  except Exception as e:
631
  raise HTTPException(status_code=500, detail=str(e))
632
 
 
607
  ai_client = AIClient()
608
  document_generator = DocumentGenerator(ai_client)
609
  vision_tools = VisionTools(ai_client)
610
+
611
  try:
612
+ # Handle image processing
613
  image_context = ""
614
  if images:
615
  image_context = await vision_tools.extract_images_info(images)
 
616
  # Store the image_context in the cache
617
+ image_cache_key = f"image_context_{conversation_id}"
618
+ await FastAPICache.get_backend().set(image_cache_key, image_context, expire=3600) # Cache for 1 hour
619
+
620
+ # Handle document processing using the new load_documents function
621
+ documents_list = []
622
+ if documents:
623
+ documents_list = await load_documents(documents)
624
+ # Store the documents_list in the cache
625
+ docs_cache_key = f"documents_list_{conversation_id}"
626
+ await FastAPICache.get_backend().set(docs_cache_key, documents_list, expire=3600) # Cache for 1 hour
627
+
628
+ # Generate document outline
629
  json_document = document_generator.generate_document_outline(
630
  query,
631
  template,
632
+ image_context=image_context,
633
+ documents_context=documents_list
634
  )
635
+
636
  if json_document is None:
637
  raise HTTPException(status_code=500, detail="Failed to generate a valid document outline")
638
+
639
  return JsonDocumentResponse(json_document=json_document)
640
+
641
  except Exception as e:
642
  raise HTTPException(status_code=500, detail=str(e))
643