abdullahalioo commited on
Commit
cbb83bf
·
verified ·
1 Parent(s): e0c20b6

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -3
main.py CHANGED
@@ -66,9 +66,21 @@ async def generate_response(request: QuestionRequest):
66
  raise HTTPException(status_code=500, detail="Chatbot not initialized. Please try again later.")
67
 
68
  try:
69
- # Generate response (non-streaming for simplicity in API context)
70
- response = chatbot.chat(request.question, stream=False)
71
- return {"response": response}
 
 
 
 
 
 
 
 
 
 
 
 
72
  except Exception as e:
73
  raise HTTPException(status_code=500, detail=f"Failed to generate response: {str(e)}")
74
 
 
66
  raise HTTPException(status_code=500, detail="Chatbot not initialized. Please try again later.")
67
 
68
  try:
69
+ # Generate response (non-streaming for simplicity)
70
+ response_data = chatbot.chat(request.question, stream=False)
71
+
72
+ # Extract the actual response text
73
+ # The response may be a dictionary; check for 'gen' or other keys
74
+ if isinstance(response_data, dict):
75
+ # Assuming 'gen' contains the response text (list of strings)
76
+ response_text = "".join(response_data.get("gen", [])) if response_data.get("gen") else "Here's what we can do: Let's discuss your vision!"
77
+ if not response_text:
78
+ # Fallback to a default premium response if 'gen' is empty
79
+ response_text = f"Welcome, valued client! How can Abdullah Ali and our premium team bring your vision to life with a custom website or AI chatbot?"
80
+ else:
81
+ response_text = response_data # Direct string response (if hugchat returns string)
82
+
83
+ return {"response": response_text}
84
  except Exception as e:
85
  raise HTTPException(status_code=500, detail=f"Failed to generate response: {str(e)}")
86