fixed issues
This commit is contained in:
+11
-34
@@ -36,6 +36,7 @@ async def chat_ai(
|
|||||||
|
|
||||||
# Initialize DroneBot with history and customer metadata
|
# Initialize DroneBot with history and customer metadata
|
||||||
logger.info("Initializing DroneBot...")
|
logger.info("Initializing DroneBot...")
|
||||||
|
logger.info(f"History: {history}")
|
||||||
bot = DroneBot(history=history, use_openai_as_fallback=True, customer_metadata=customer_metadata)
|
bot = DroneBot(history=history, use_openai_as_fallback=True, customer_metadata=customer_metadata)
|
||||||
logger.info("DroneBot initialized successfully")
|
logger.info("DroneBot initialized successfully")
|
||||||
|
|
||||||
@@ -44,45 +45,21 @@ async def chat_ai(
|
|||||||
result = bot.chat(request.query)
|
result = bot.chat(request.query)
|
||||||
logger.info(f"DroneBot response received: {result}")
|
logger.info(f"DroneBot response received: {result}")
|
||||||
|
|
||||||
# Validate result and final_message
|
final_message_json = json.loads(result["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}")
|
|
||||||
# If JSON parsing fails, create a fallback structure
|
# If JSON parsing fails, create a fallback structure
|
||||||
message = {
|
# message = {
|
||||||
"message": final_message,
|
# "message": final_message_json,
|
||||||
"options": None,
|
# "options": None,
|
||||||
"requires_selection": False,
|
# "requires_selection": False,
|
||||||
"end": "in_progress",
|
# "end": "in_progress",
|
||||||
"form": {}
|
# "form": {}
|
||||||
}
|
# }
|
||||||
logger.info("Created fallback message structure")
|
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(
|
return ChatResponse(
|
||||||
status="success",
|
status="success",
|
||||||
message=message
|
message=final_message_json
|
||||||
)
|
)
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
logger.error("Re-raising HTTPException")
|
logger.error("Re-raising HTTPException")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class LlmConfig:
|
|||||||
class models:
|
class models:
|
||||||
gpt_4o = "gpt-4o"
|
gpt_4o = "gpt-4o"
|
||||||
gpt_4_1 = "gpt-4.1"
|
gpt_4_1 = "gpt-4.1"
|
||||||
|
gpt_5_mini = "gpt-5-mini"
|
||||||
|
|
||||||
temperatures = {
|
temperatures = {
|
||||||
"default": 0.7,
|
"default": 0.7,
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ class ModelRotationManager:
|
|||||||
# Add OpenAI models if enabled
|
# Add OpenAI models if enabled
|
||||||
if use_openai_as_fallback:
|
if use_openai_as_fallback:
|
||||||
openai_models = [
|
openai_models = [
|
||||||
{
|
# {
|
||||||
"name": LlmConfig.openai.models.gpt_4o,
|
# "name": LlmConfig.openai.models.gpt_5_mini,
|
||||||
"provider": "openai",
|
# "provider": "openai",
|
||||||
"api_key": Config.OPENAI_API_KEY,
|
# "api_key": Config.OPENAI_API_KEY,
|
||||||
"temperature": LlmConfig.openai.temperatures.get("drone_bot")
|
# "temperature": LlmConfig.openai.temperatures.get("drone_bot")
|
||||||
},
|
# },
|
||||||
{
|
{
|
||||||
"name": LlmConfig.openai.models.gpt_4_1,
|
"name": LlmConfig.openai.models.gpt_4_1,
|
||||||
"provider": "openai",
|
"provider": "openai",
|
||||||
|
|||||||
@@ -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 ```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
|
: 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 !!!
|
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
|
||||||
"""
|
"""
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# terminal_chat.py
|
# terminal_chat.py
|
||||||
from src.llm.orchestrator import DroneBot, Message # Adjust import path as needed
|
from src.llm.orchestrator import DroneBot, Message # Adjust import path as needed
|
||||||
|
import json
|
||||||
def terminal_chat():
|
def terminal_chat():
|
||||||
print("🚁 DroneBot Terminal Chat")
|
print("🚁 DroneBot Terminal Chat")
|
||||||
print("Type 'exit' to quit.\n")
|
print("Type 'exit' to quit.\n")
|
||||||
@@ -37,7 +37,8 @@ def terminal_chat():
|
|||||||
history.append(Message(role="ai", content=response["final_message"]))
|
history.append(Message(role="ai", content=response["final_message"]))
|
||||||
|
|
||||||
# Print bot response
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user