Successful Truncation
Browse files- controller.py +24 -24
controller.py
CHANGED
|
@@ -399,33 +399,33 @@ async def csv_chat(request: Dict, authorization: str = Header(None)):
|
|
| 399 |
logger.info("Starting report generation process...")
|
| 400 |
|
| 401 |
# Try Cerebras first for report generation
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
|
| 413 |
-
#
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
|
| 425 |
-
|
| 426 |
|
| 427 |
-
# Gemini failed, last
|
| 428 |
-
logger.info("Attempting report generation with Groq as last
|
| 429 |
try:
|
| 430 |
report_files = await generate_csv_report_groq(csv_url, query, chat_id, conversation_history)
|
| 431 |
if report_files is not None and (report_files.files.csv_files or report_files.files.image_files):
|
|
|
|
| 399 |
logger.info("Starting report generation process...")
|
| 400 |
|
| 401 |
# Try Cerebras first for report generation
|
| 402 |
+
logger.info("Attempting report generation with Cerebras...")
|
| 403 |
+
try:
|
| 404 |
+
report_files = await generate_csv_report_cerebras(csv_url, query, chat_id, conversation_history)
|
| 405 |
+
if report_files is not None and (report_files.files.csv_files or report_files.files.image_files):
|
| 406 |
+
logger.info(f"Cerebras report generation successful: {len(report_files.files.csv_files)} CSV files, {len(report_files.files.image_files)} image files")
|
| 407 |
+
return {"answer": jsonable_encoder(report_files)}
|
| 408 |
+
else:
|
| 409 |
+
logger.warning("Cerebras report generation returned empty or None result")
|
| 410 |
+
except Exception as cerebras_error:
|
| 411 |
+
logger.error(f"Cerebras report generation failed: {str(cerebras_error)}")
|
| 412 |
|
| 413 |
+
# Fallback to Gemini for report generation
|
| 414 |
+
logger.info("Falling back to Gemini for report generation...")
|
| 415 |
+
try:
|
| 416 |
+
report_files = await generate_csv_report_gemini(csv_url, query, chat_id, conversation_history)
|
| 417 |
+
if report_files is not None and (report_files.files.csv_files or report_files.files.image_files):
|
| 418 |
+
logger.info(f"Gemini report generation successful: {len(report_files.files.csv_files)} CSV files, {len(report_files.files.image_files)} image files")
|
| 419 |
+
return {"answer": jsonable_encoder(report_files)}
|
| 420 |
+
else:
|
| 421 |
+
logger.warning("Gemini report generation returned empty or None result")
|
| 422 |
+
except Exception as gemini_error:
|
| 423 |
+
logger.error(f"Gemini report generation failed: {str(gemini_error)}")
|
| 424 |
|
| 425 |
+
logger.error("Both Cerebras and Gemini report generation failed")
|
| 426 |
|
| 427 |
+
# Gemini failed, last resort Groq Report Generation
|
| 428 |
+
logger.info("Attempting report generation with Groq as last resort...")
|
| 429 |
try:
|
| 430 |
report_files = await generate_csv_report_groq(csv_url, query, chat_id, conversation_history)
|
| 431 |
if report_files is not None and (report_files.files.csv_files or report_files.files.image_files):
|