ChingCL commited on
Commit
ffda859
·
verified ·
1 Parent(s): 3bb1b5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -33,9 +33,12 @@ def chat_with_groq(user_message):
33
  stream=False
34
  )
35
 
36
- # 處理非流式輸出
37
- response = completion["choices"][0]["message"]["content"]
38
- return response
 
 
 
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}"