From 3e7a300eefdcc2bc84cbd4511c7dfebbaa1b71aa Mon Sep 17 00:00:00 2001 From: OwusuBlessing Date: Mon, 18 Aug 2025 14:43:03 +0100 Subject: [PATCH] fixed issues --- api/routes/chat.py | 47 +++++++------------------ src/config/llm_config.py | 1 + src/llm/orchestrator.py | 12 +++---- src/prompts/templates/chat_templates.py | 3 ++ test.py | 5 +-- 5 files changed, 25 insertions(+), 43 deletions(-) diff --git a/api/routes/chat.py b/api/routes/chat.py index 4465711..ba65e5b 100644 --- a/api/routes/chat.py +++ b/api/routes/chat.py @@ -36,6 +36,7 @@ async def chat_ai( # Initialize DroneBot with history and customer metadata logger.info("Initializing DroneBot...") + logger.info(f"History: {history}") bot = DroneBot(history=history, use_openai_as_fallback=True, customer_metadata=customer_metadata) logger.info("DroneBot initialized successfully") @@ -44,45 +45,21 @@ async def chat_ai( result = bot.chat(request.query) logger.info(f"DroneBot response received: {result}") - # Validate result and final_message - if not result or "final_message" not in result: - logger.error(f"Invalid result from DroneBot: {result}") - raise HTTPException( - status_code=500, - detail="Invalid response from DroneBot: missing final_message" - ) - - final_message = result["final_message"] - logger.info(f"Final message extracted: {final_message}") - - if not final_message or not isinstance(final_message, str): - logger.error(f"Final message is not a valid string: {type(final_message)} - {final_message}") - raise HTTPException( - status_code=500, - detail="Invalid response from DroneBot: final_message is not a valid string" - ) - - try: - logger.info("Attempting to parse final_message as JSON...") - message = json.loads(final_message) - logger.info("JSON parsing successful") - except json.JSONDecodeError as json_error: - logger.warning(f"JSON decode error: {json_error}") - logger.warning(f"Raw final_message: {final_message}") + final_message_json = json.loads(result["final_message"]) # If JSON parsing fails, create a fallback structure - message = { - "message": final_message, - "options": None, - "requires_selection": False, - "end": "in_progress", - "form": {} - } - logger.info("Created fallback message structure") + # message = { + # "message": final_message_json, + # "options": None, + # "requires_selection": False, + # "end": "in_progress", + # "form": {} + # } + logger.info("Created fallback message structure") - logger.info(f"Final message to return: {message}") + logger.info(f"Final message to return: {final_message_json}") return ChatResponse( status="success", - message=message + message=final_message_json ) except HTTPException: logger.error("Re-raising HTTPException") diff --git a/src/config/llm_config.py b/src/config/llm_config.py index f57c7dc..7ef6459 100644 --- a/src/config/llm_config.py +++ b/src/config/llm_config.py @@ -3,6 +3,7 @@ class LlmConfig: class models: gpt_4o = "gpt-4o" gpt_4_1 = "gpt-4.1" + gpt_5_mini = "gpt-5-mini" temperatures = { "default": 0.7, diff --git a/src/llm/orchestrator.py b/src/llm/orchestrator.py index bccd46c..2b27b86 100644 --- a/src/llm/orchestrator.py +++ b/src/llm/orchestrator.py @@ -43,12 +43,12 @@ class ModelRotationManager: # Add OpenAI models if enabled if use_openai_as_fallback: openai_models = [ - { - "name": LlmConfig.openai.models.gpt_4o, - "provider": "openai", - "api_key": Config.OPENAI_API_KEY, - "temperature": LlmConfig.openai.temperatures.get("drone_bot") - }, + # { + # "name": LlmConfig.openai.models.gpt_5_mini, + # "provider": "openai", + # "api_key": Config.OPENAI_API_KEY, + # "temperature": LlmConfig.openai.temperatures.get("drone_bot") + # }, { "name": LlmConfig.openai.models.gpt_4_1, "provider": "openai", diff --git a/src/prompts/templates/chat_templates.py b/src/prompts/templates/chat_templates.py index 003f842..bb63d26 100644 --- a/src/prompts/templates/chat_templates.py +++ b/src/prompts/templates/chat_templates.py @@ -709,4 +709,7 @@ NOTE: THIS IS SOLELY YOUR TASK PLEASE, NO OTHER THING : DO NOT ADD ```json or ``` or anything else before or after the json format : DO NOT ADD ANYTHING ELSE TO THE JSON FORMAT, ONLY THE JSON FORMAT, do not add ```json or ``` or anything else before or after the json format CRITICAL !!! ONLY JSON !!! + +FINAL CRITICAL INSTRUCTIONS: + RETURN ONLY JSON FORMAT NO EXPLANATION OR EXTRA INFORMATION BEFORE OR AFTER, DO NOT ADD ```json before or after """ \ No newline at end of file diff --git a/test.py b/test.py index 7c005fd..5fd9a49 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,6 @@ # terminal_chat.py from src.llm.orchestrator import DroneBot, Message # Adjust import path as needed - +import json def terminal_chat(): print("🚁 DroneBot Terminal Chat") print("Type 'exit' to quit.\n") @@ -37,7 +37,8 @@ def terminal_chat(): history.append(Message(role="ai", content=response["final_message"])) # Print bot response - print(f"🤖 DroneBot: {response['final_message']}\n") + response_json = json.loads(response["final_message"]) + print(f"🤖 DroneBot: {response_json}\n") if __name__ == "__main__":