Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,9 +33,12 @@ def chat_with_groq(user_message):
|
|
| 33 |
stream=False
|
| 34 |
)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
return f"發生錯誤:{e}"
|
|
|
|
| 33 |
stream=False
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# 確保返回結果格式正確
|
| 37 |
+
if "choices" in completion and len(completion["choices"]) > 0:
|
| 38 |
+
response = completion["choices"][0].get("message", {}).get("content", "")
|
| 39 |
+
return response or "抱歉,我無法生成有效的回應。"
|
| 40 |
+
else:
|
| 41 |
+
return "抱歉,我無法解析 API 的回應結果。"
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
return f"發生錯誤:{e}"
|