Soumik555 commited on
Commit
f9007e5
·
1 Parent(s): 41675f1

test new groq agent

Browse files
Files changed (1) hide show
  1. controller.py +30 -11
controller.py CHANGED
@@ -34,6 +34,7 @@ from orchestrator_agent import csv_orchestrator_chat_gemini
34
  from python_code_executor_service import CsvChatResult, PythonExecutor
35
  from supabase_service import upload_file_to_supabase
36
  from cerebras_csv_agent import query_csv_agent_cerebras
 
37
  from util_service import _prompt_generator, process_answer
38
  from fastapi.middleware.cors import CORSMiddleware
39
 
@@ -441,17 +442,30 @@ async def csv_chat(request: Dict, authorization: str = Header(None)):
441
  logger.info("Processing detailed answer with orchestrator...")
442
  return await handle_detailed_answer(decoded_url, query, conversation_history, chat_id)
443
 
444
- # Process with standard CSV agent (Cerebras)
445
- logger.info("Processing with standard CSV agent (Cerebras)...")
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  try:
447
- result = await query_csv_agent_cerebras(decoded_url, query, chat_id)
448
- logger.info(f"Standard CSV agent (Cerebras) result: {str(result)[:200]}...")
449
  if result is not None and result != "":
450
  return {"answer": result}
451
  else:
452
- logger.warning("Standard CSV agent (Cerebras) returned empty or None result")
453
  except Exception as e:
454
- logger.error(f"Standard CSV agent (Cerebras) failed: {str(e)}")
455
 
456
  # Fallback to langchain
457
  logger.info("Falling back to langchain CSV chat...")
@@ -726,14 +740,20 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
726
  # return {"image_url": image_public_url}
727
  # return FileResponse(groq_result, media_type="image/png")
728
 
729
- logger.info("Trying cerebras ai llama...")
730
- result = await query_csv_agent_cerebras(csv_url, query, chat_id)
731
- logger.info("cerebras ai result ==>", result)
 
 
 
 
 
 
732
  if result is not None and result != "":
733
  return {"orchestrator_response": jsonable_encoder(result)}
734
 
735
  # Fallback: try langchain-based again
736
- logger.error("Cerebras ai llama response failed, trying langchain groq....")
737
  langchain_paths = await loop.run_in_executor(
738
  process_executor, langchain_csv_chart, csv_url, query, True
739
  )
@@ -745,7 +765,6 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
745
  logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
746
  os.remove(langchain_paths[0])
747
  return {"image_url": image_public_url}
748
- return FileResponse(langchain_paths[0], media_type="image/png")
749
  else:
750
  logger.error("All chart generation methods failed")
751
  return {"answer": "error"}
 
34
  from python_code_executor_service import CsvChatResult, PythonExecutor
35
  from supabase_service import upload_file_to_supabase
36
  from cerebras_csv_agent import query_csv_agent_cerebras
37
+ from groq_csv_agent import query_csv_agent_groq
38
  from util_service import _prompt_generator, process_answer
39
  from fastapi.middleware.cors import CORSMiddleware
40
 
 
442
  logger.info("Processing detailed answer with orchestrator...")
443
  return await handle_detailed_answer(decoded_url, query, conversation_history, chat_id)
444
 
445
+ # # Process with standard CSV agent (Cerebras)
446
+ # logger.info("Processing with standard CSV agent (Cerebras)...")
447
+ # try:
448
+ # result = await query_csv_agent_cerebras(decoded_url, query, chat_id)
449
+ # logger.info(f"Standard CSV agent (Cerebras) result: {str(result)[:200]}...")
450
+ # if result is not None and result != "":
451
+ # return {"answer": result}
452
+ # else:
453
+ # logger.warning("Standard CSV agent (Cerebras) returned empty or None result")
454
+ # except Exception as e:
455
+ # logger.error(f"Standard CSV agent (Cerebras) failed: {str(e)}")
456
+
457
+
458
+ # Process with standard CSV agent (Groq)
459
+ logger.info("Processing with standard CSV agent (Groq)...")
460
  try:
461
+ result = await query_csv_agent_groq(decoded_url, query, chat_id)
462
+ logger.info(f"Standard CSV agent (Groq) result: {str(result)[:200]}...")
463
  if result is not None and result != "":
464
  return {"answer": result}
465
  else:
466
+ logger.warning("Standard CSV agent (Groq) returned empty or None result")
467
  except Exception as e:
468
+ logger.error(f"Standard CSV agent (Groq) failed: {str(e)}")
469
 
470
  # Fallback to langchain
471
  logger.info("Falling back to langchain CSV chat...")
 
740
  # return {"image_url": image_public_url}
741
  # return FileResponse(groq_result, media_type="image/png")
742
 
743
+ # logger.info("Trying cerebras ai...")
744
+ # result = await query_csv_agent_cerebras(csv_url, query, chat_id)
745
+ # logger.info("cerebras ai result ==>", result)
746
+ # if result is not None and result != "":
747
+ # return {"orchestrator_response": jsonable_encoder(result)}
748
+
749
+ logger.info("Trying groq ai...")
750
+ result = await query_csv_agent_groq(csv_url, query, chat_id)
751
+ logger.info("groq ai result ==>", result)
752
  if result is not None and result != "":
753
  return {"orchestrator_response": jsonable_encoder(result)}
754
 
755
  # Fallback: try langchain-based again
756
+ logger.error("Groq ai response failed, trying langchain groq....")
757
  langchain_paths = await loop.run_in_executor(
758
  process_executor, langchain_csv_chart, csv_url, query, True
759
  )
 
765
  logger.info("Image uploaded to Supabase and Image URL is... ", {image_public_url})
766
  os.remove(langchain_paths[0])
767
  return {"image_url": image_public_url}
 
768
  else:
769
  logger.error("All chart generation methods failed")
770
  return {"answer": "error"}