Self ping
Browse files- orchestrator_functions.py +32 -33
orchestrator_functions.py
CHANGED
@@ -494,7 +494,7 @@ def langchain_csv_chart(csv_url: str, question: str, chart_required: bool):
|
|
494 |
async def csv_chat(csv_url: str, query: str):
|
495 |
"""
|
496 |
Generate a response based on the provided CSV URL and query.
|
497 |
-
Prioritizes LangChain-
|
498 |
|
499 |
Parameters:
|
500 |
- csv_url (str): The URL of the CSV file.
|
@@ -512,52 +512,52 @@ async def csv_chat(csv_url: str, query: str):
|
|
512 |
try:
|
513 |
updated_query = f"{query} and Do not show any charts or graphs."
|
514 |
|
515 |
-
# --- 1. First Attempt: LangChain
|
516 |
try:
|
517 |
-
|
518 |
-
|
519 |
)
|
520 |
-
logger.info("LangChain-
|
521 |
|
522 |
-
if
|
523 |
-
return {"answer": jsonable_encoder(
|
524 |
|
525 |
-
raise Exception("LangChain-
|
526 |
|
527 |
-
except Exception as
|
528 |
-
logger.info(f"LangChain-
|
529 |
|
530 |
-
# --- 2. Second Attempt:
|
531 |
try:
|
532 |
-
|
533 |
-
|
534 |
-
)
|
535 |
-
logger.info("LangChain-Groq answer:", lang_groq_answer)
|
536 |
|
537 |
-
if
|
538 |
-
|
539 |
|
540 |
-
|
|
|
541 |
|
542 |
-
|
543 |
-
logger.info(f"LangChain-Groq error: {str(lang_groq_error)}")
|
544 |
|
545 |
-
|
|
|
|
|
|
|
546 |
try:
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
return {"answer": "Sorry, I couldn't find relevant data..."}
|
552 |
|
553 |
-
if
|
554 |
-
|
555 |
|
556 |
-
|
557 |
|
558 |
-
except Exception as
|
559 |
-
logger.info(f"
|
560 |
-
return {"answer": "
|
561 |
|
562 |
except Exception as e:
|
563 |
logger.info(f"Unexpected error: {str(e)}")
|
@@ -569,7 +569,6 @@ async def csv_chat(csv_url: str, query: str):
|
|
569 |
|
570 |
|
571 |
|
572 |
-
|
573 |
async def csv_chart(csv_url: str, query: str):
|
574 |
"""
|
575 |
Generate a chart based on the provided CSV URL and query.
|
|
|
494 |
async def csv_chat(csv_url: str, query: str):
|
495 |
"""
|
496 |
Generate a response based on the provided CSV URL and query.
|
497 |
+
Prioritizes LangChain-Groq, then raw Groq, and finally LangChain-Gemini as fallback.
|
498 |
|
499 |
Parameters:
|
500 |
- csv_url (str): The URL of the CSV file.
|
|
|
512 |
try:
|
513 |
updated_query = f"{query} and Do not show any charts or graphs."
|
514 |
|
515 |
+
# --- 1. First Attempt: LangChain Groq ---
|
516 |
try:
|
517 |
+
lang_groq_answer = await asyncio.to_thread(
|
518 |
+
langchain_csv_chat, csv_url, updated_query, False
|
519 |
)
|
520 |
+
logger.info("LangChain-Groq answer:", lang_groq_answer)
|
521 |
|
522 |
+
if lang_groq_answer is not None:
|
523 |
+
return {"answer": jsonable_encoder(lang_groq_answer)}
|
524 |
|
525 |
+
raise Exception("LangChain-Groq response not usable, falling back to raw Groq")
|
526 |
|
527 |
+
except Exception as lang_groq_error:
|
528 |
+
logger.info(f"LangChain-Groq error: {str(lang_groq_error)}")
|
529 |
|
530 |
+
# --- 2. Second Attempt: Raw Groq Chat ---
|
531 |
try:
|
532 |
+
raw_groq_answer = await asyncio.to_thread(groq_chat, csv_url, updated_query)
|
533 |
+
logger.info("Raw Groq answer:", raw_groq_answer)
|
|
|
|
|
534 |
|
535 |
+
if process_answer(raw_groq_answer) == "Empty response received." or raw_groq_answer is None:
|
536 |
+
raise Exception("Raw Groq response not usable, falling back to LangChain-Gemini")
|
537 |
|
538 |
+
if process_answer(raw_groq_answer):
|
539 |
+
raise Exception("Raw Groq response not usable, falling back to LangChain-Gemini")
|
540 |
|
541 |
+
return {"answer": jsonable_encoder(raw_groq_answer)}
|
|
|
542 |
|
543 |
+
except Exception as raw_groq_error:
|
544 |
+
logger.info(f"Raw Groq error: {str(raw_groq_error)}")
|
545 |
+
|
546 |
+
# --- 3. Final Attempt: LangChain Gemini ---
|
547 |
try:
|
548 |
+
gemini_answer = await asyncio.to_thread(
|
549 |
+
langchain_gemini_csv_handler, csv_url, updated_query, False
|
550 |
+
)
|
551 |
+
logger.info("LangChain-Gemini answer:", gemini_answer)
|
|
|
552 |
|
553 |
+
if gemini_answer is not None:
|
554 |
+
return {"answer": jsonable_encoder(gemini_answer)}
|
555 |
|
556 |
+
raise Exception("All fallbacks exhausted")
|
557 |
|
558 |
+
except Exception as gemini_error:
|
559 |
+
logger.info(f"LangChain-Gemini error: {str(gemini_error)}")
|
560 |
+
return {"answer": "Sorry, I couldn't find relevant data..."}
|
561 |
|
562 |
except Exception as e:
|
563 |
logger.info(f"Unexpected error: {str(e)}")
|
|
|
569 |
|
570 |
|
571 |
|
|
|
572 |
async def csv_chart(csv_url: str, query: str):
|
573 |
"""
|
574 |
Generate a chart based on the provided CSV URL and query.
|