Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,14 +37,14 @@ def chat_with_groq(user_message):
|
|
| 37 |
)
|
| 38 |
|
| 39 |
# 確保返回結果格式正確
|
| 40 |
-
if "choices"
|
| 41 |
-
response = completion["choices"][0]
|
| 42 |
-
return response
|
| 43 |
else:
|
| 44 |
return "抱歉,我無法解析 API 的回應結果。"
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
-
return f"發生錯誤:{e}"
|
| 48 |
|
| 49 |
# 定義 Gradio 介面
|
| 50 |
def gradio_chatbot():
|
|
|
|
| 37 |
)
|
| 38 |
|
| 39 |
# 確保返回結果格式正確
|
| 40 |
+
if completion.get("choices") and len(completion["choices"]) > 0:
|
| 41 |
+
response = completion["choices"][0].get("message", {}).get("content", "抱歉,我無法生成有效的回應。")
|
| 42 |
+
return response
|
| 43 |
else:
|
| 44 |
return "抱歉,我無法解析 API 的回應結果。"
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
+
return f"發生錯誤:{str(e)}"
|
| 48 |
|
| 49 |
# 定義 Gradio 介面
|
| 50 |
def gradio_chatbot():
|