ChingCL commited on
Commit
c1ee240
·
verified ·
1 Parent(s): d8ea470

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -37,14 +37,14 @@ def chat_with_groq(user_message):
37
  )
38
 
39
  # 確保返回結果格式正確
40
- if "choices" in completion and len(completion["choices"]) > 0:
41
- response = completion["choices"][0]["message"]["content"]
42
- return response or "抱歉,我無法生成有效的回應。"
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():