Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -122,9 +122,6 @@ def chat(request: ChatRequest):
|
|
122 |
user_message = request.message
|
123 |
chat_history.append(user_message)
|
124 |
|
125 |
-
# Retrieve relevant diagnostic question
|
126 |
-
relevant_question = retrieve_relevant_question(user_message)
|
127 |
-
|
128 |
# Constructing the DeepSeek prompt
|
129 |
prompt = f"""
|
130 |
You are an AI psychiatrist conducting a mental health consultation.
|
@@ -132,7 +129,6 @@ def chat(request: ChatRequest):
|
|
132 |
|
133 |
- Always provide a thoughtful and compassionate response.
|
134 |
- If a user shares distressing emotions, acknowledge their feelings and ask relevant follow-up questions.
|
135 |
-
- Ask a symptom-related question to explore their concerns in depth.
|
136 |
|
137 |
Previous conversation:
|
138 |
{chat_history}
|
@@ -143,17 +139,21 @@ def chat(request: ChatRequest):
|
|
143 |
Generate:
|
144 |
- An empathetic response.
|
145 |
- A related follow-up question.
|
146 |
-
|
147 |
-
|
148 |
-
Ensure your response is always meaningful and non-empty.
|
149 |
"""
|
150 |
|
|
|
151 |
ai_response = deepseek_request(prompt, max_tokens=250)
|
152 |
|
153 |
-
|
|
|
|
|
154 |
|
|
|
155 |
return {"response": ai_response}
|
156 |
|
|
|
157 |
# ✅ API Endpoint: Detect Disorders from Chat History
|
158 |
@app.post("/detect_disorders")
|
159 |
def detect_disorders():
|
|
|
122 |
user_message = request.message
|
123 |
chat_history.append(user_message)
|
124 |
|
|
|
|
|
|
|
125 |
# Constructing the DeepSeek prompt
|
126 |
prompt = f"""
|
127 |
You are an AI psychiatrist conducting a mental health consultation.
|
|
|
129 |
|
130 |
- Always provide a thoughtful and compassionate response.
|
131 |
- If a user shares distressing emotions, acknowledge their feelings and ask relevant follow-up questions.
|
|
|
132 |
|
133 |
Previous conversation:
|
134 |
{chat_history}
|
|
|
139 |
Generate:
|
140 |
- An empathetic response.
|
141 |
- A related follow-up question.
|
142 |
+
|
143 |
+
Ensure your response is meaningful and NEVER empty.
|
|
|
144 |
"""
|
145 |
|
146 |
+
# Call DeepSeek API
|
147 |
ai_response = deepseek_request(prompt, max_tokens=250)
|
148 |
|
149 |
+
# ✅ Ensure response is NEVER empty
|
150 |
+
if not ai_response or ai_response.strip() == "":
|
151 |
+
ai_response = "I'm here to listen. Can you tell me more about how you're feeling? Maybe I can help."
|
152 |
|
153 |
+
chat_history.append(ai_response)
|
154 |
return {"response": ai_response}
|
155 |
|
156 |
+
|
157 |
# ✅ API Endpoint: Detect Disorders from Chat History
|
158 |
@app.post("/detect_disorders")
|
159 |
def detect_disorders():
|