Soumik555 commited on
Commit
1211e2b
·
1 Parent(s): 0d56c08

only groq

Browse files
Files changed (1) hide show
  1. controller.py +62 -62
controller.py CHANGED
@@ -342,25 +342,25 @@ async def csv_chat(request: Dict, authorization: str = Header(None)):
342
  generate_report = request.get("generate_report")
343
  chat_id = request.get("chat_id")
344
 
345
- if generate_report is True:
346
- report_files = await generate_csv_report(csv_url, query, chat_id)
347
- if report_files is not None:
348
- return {"answer": jsonable_encoder(report_files)}
349
-
350
- if if_initial_chat_question(query):
351
- answer = await asyncio.to_thread(
352
- langchain_csv_chat, decoded_url, query, False
353
- )
354
- logger.info("langchain_answer:", answer)
355
- return {"answer": jsonable_encoder(answer)}
356
 
357
- # Orchestrate the execution
358
- if detailed_answer is True:
359
- orchestrator_answer = await asyncio.to_thread(
360
- csv_orchestrator_chat, decoded_url, query, conversation_history, chat_id
361
- )
362
- if orchestrator_answer is not None:
363
- return {"answer": jsonable_encoder(orchestrator_answer)}
364
 
365
  # Process with groq_chat first
366
  groq_answer = await asyncio.to_thread(groq_chat, decoded_url, query)
@@ -369,13 +369,13 @@ async def csv_chat(request: Dict, authorization: str = Header(None)):
369
  if process_answer(groq_answer) == "Empty response received.":
370
  return {"answer": "Sorry, I couldn't find relevant data..."}
371
 
372
- if process_answer(groq_answer):
373
- lang_answer = await asyncio.to_thread(
374
- langchain_csv_chat, decoded_url, query, False
375
- )
376
- if process_answer(lang_answer):
377
- return {"answer": "error"}
378
- return {"answer": jsonable_encoder(lang_answer)}
379
 
380
  return {"answer": jsonable_encoder(groq_answer)}
381
 
@@ -584,35 +584,35 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
584
  generate_report = request.get("generate_report", False)
585
  chat_id = request.get("chat_id", "")
586
 
587
- if generate_report is True:
588
- report_files = await generate_csv_report(csv_url, query, chat_id)
589
- if report_files is not None:
590
- return {"orchestrator_response": jsonable_encoder(report_files)}
591
 
592
  loop = asyncio.get_running_loop()
593
- # First, try the langchain-based method if the question qualifies
594
- if if_initial_chart_question(query):
595
- langchain_result = await loop.run_in_executor(
596
- process_executor, langchain_csv_chart, csv_url, query, True
597
- )
598
- logger.info("Langchain chart result:", langchain_result)
599
- if isinstance(langchain_result, list) and len(langchain_result) > 0:
600
- unique_file_name =f'{str(uuid.uuid4())}.png'
601
- logger.info("Uploading the chart to supabase...")
602
- image_public_url = await upload_file_to_supabase(f"{langchain_result[0]}", unique_file_name, chat_id=chat_id)
603
- logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
604
- os.remove(langchain_result[0])
605
- return {"image_url": image_public_url}
606
- # return FileResponse(langchain_result[0], media_type="image/png")
607
 
608
- # Use orchestrator to handle the user's chart query first
609
- if detailed_answer is True:
610
- orchestrator_answer = await asyncio.to_thread(
611
- csv_orchestrator_chat, csv_url, query, conversation_history, chat_id
612
- )
613
 
614
- if orchestrator_answer is not None:
615
- return {"orchestrator_response": jsonable_encoder(orchestrator_answer)}
616
 
617
  # Next, try the groq-based method
618
  groq_result = await loop.run_in_executor(
@@ -629,18 +629,18 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
629
  # return FileResponse(groq_result, media_type="image/png")
630
 
631
  # Fallback: try langchain-based again
632
- logger.error("Groq chart generation failed, trying langchain....")
633
- langchain_paths = await loop.run_in_executor(
634
- process_executor, langchain_csv_chart, csv_url, query, True
635
- )
636
- logger.info("Fallback langchain chart result:", langchain_paths)
637
- if isinstance(langchain_paths, list) and len(langchain_paths) > 0:
638
- unique_file_name =f'{str(uuid.uuid4())}.png'
639
- logger.info("Uploading the chart to supabase...")
640
- image_public_url = await upload_file_to_supabase(f"{langchain_paths[0]}", unique_file_name, chat_id=chat_id)
641
- logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
642
- os.remove(langchain_paths[0])
643
- return {"image_url": image_public_url}
644
  # return FileResponse(langchain_paths[0], media_type="image/png")
645
  else:
646
  logger.error("All chart generation methods failed")
 
342
  generate_report = request.get("generate_report")
343
  chat_id = request.get("chat_id")
344
 
345
+ # if generate_report is True:
346
+ # report_files = await generate_csv_report(csv_url, query, chat_id)
347
+ # if report_files is not None:
348
+ # return {"answer": jsonable_encoder(report_files)}
349
+
350
+ # if if_initial_chat_question(query):
351
+ # answer = await asyncio.to_thread(
352
+ # langchain_csv_chat, decoded_url, query, False
353
+ # )
354
+ # logger.info("langchain_answer:", answer)
355
+ # return {"answer": jsonable_encoder(answer)}
356
 
357
+ # # Orchestrate the execution
358
+ # if detailed_answer is True:
359
+ # orchestrator_answer = await asyncio.to_thread(
360
+ # csv_orchestrator_chat, decoded_url, query, conversation_history, chat_id
361
+ # )
362
+ # if orchestrator_answer is not None:
363
+ # return {"answer": jsonable_encoder(orchestrator_answer)}
364
 
365
  # Process with groq_chat first
366
  groq_answer = await asyncio.to_thread(groq_chat, decoded_url, query)
 
369
  if process_answer(groq_answer) == "Empty response received.":
370
  return {"answer": "Sorry, I couldn't find relevant data..."}
371
 
372
+ # if process_answer(groq_answer):
373
+ # lang_answer = await asyncio.to_thread(
374
+ # langchain_csv_chat, decoded_url, query, False
375
+ # )
376
+ # if process_answer(lang_answer):
377
+ # return {"answer": "error"}
378
+ # return {"answer": jsonable_encoder(lang_answer)}
379
 
380
  return {"answer": jsonable_encoder(groq_answer)}
381
 
 
584
  generate_report = request.get("generate_report", False)
585
  chat_id = request.get("chat_id", "")
586
 
587
+ # if generate_report is True:
588
+ # report_files = await generate_csv_report(csv_url, query, chat_id)
589
+ # if report_files is not None:
590
+ # return {"orchestrator_response": jsonable_encoder(report_files)}
591
 
592
  loop = asyncio.get_running_loop()
593
+ # # First, try the langchain-based method if the question qualifies
594
+ # if if_initial_chart_question(query):
595
+ # langchain_result = await loop.run_in_executor(
596
+ # process_executor, langchain_csv_chart, csv_url, query, True
597
+ # )
598
+ # logger.info("Langchain chart result:", langchain_result)
599
+ # if isinstance(langchain_result, list) and len(langchain_result) > 0:
600
+ # unique_file_name =f'{str(uuid.uuid4())}.png'
601
+ # logger.info("Uploading the chart to supabase...")
602
+ # image_public_url = await upload_file_to_supabase(f"{langchain_result[0]}", unique_file_name, chat_id=chat_id)
603
+ # logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
604
+ # os.remove(langchain_result[0])
605
+ # return {"image_url": image_public_url}
606
+ # # return FileResponse(langchain_result[0], media_type="image/png")
607
 
608
+ # # Use orchestrator to handle the user's chart query first
609
+ # if detailed_answer is True:
610
+ # orchestrator_answer = await asyncio.to_thread(
611
+ # csv_orchestrator_chat, csv_url, query, conversation_history, chat_id
612
+ # )
613
 
614
+ # if orchestrator_answer is not None:
615
+ # return {"orchestrator_response": jsonable_encoder(orchestrator_answer)}
616
 
617
  # Next, try the groq-based method
618
  groq_result = await loop.run_in_executor(
 
629
  # return FileResponse(groq_result, media_type="image/png")
630
 
631
  # Fallback: try langchain-based again
632
+ # logger.error("Groq chart generation failed, trying langchain....")
633
+ # langchain_paths = await loop.run_in_executor(
634
+ # process_executor, langchain_csv_chart, csv_url, query, True
635
+ # )
636
+ # logger.info("Fallback langchain chart result:", langchain_paths)
637
+ # if isinstance(langchain_paths, list) and len(langchain_paths) > 0:
638
+ # unique_file_name =f'{str(uuid.uuid4())}.png'
639
+ # logger.info("Uploading the chart to supabase...")
640
+ # image_public_url = await upload_file_to_supabase(f"{langchain_paths[0]}", unique_file_name, chat_id=chat_id)
641
+ # logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
642
+ # os.remove(langchain_paths[0])
643
+ # return {"image_url": image_public_url}
644
  # return FileResponse(langchain_paths[0], media_type="image/png")
645
  else:
646
  logger.error("All chart generation methods failed")