ChingCL commited on
Commit
ac01850
Β·
verified Β·
1 Parent(s): 6b9fc8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -1,5 +1,3 @@
1
- print(f\"API Key: {api_key}\")
2
-
3
  import os
4
  import gradio as gr
5
 
@@ -20,11 +18,10 @@ if not api_key:
20
 
21
  client.api_key = api_key
22
 
23
-
24
-
25
  def chat_with_groq(user_message):
26
  """θˆ‡ Groq ζ¨‘εž‹ι€²θ‘ŒδΊ’ε‹•"""
27
  try:
 
28
  completion = client.chat.completions.create(
29
  model="llama-3.1-70b-versatile",
30
  messages=[
@@ -40,12 +37,15 @@ def chat_with_groq(user_message):
40
  stream=False
41
  )
42
 
43
- # η’ΊδΏθΏ”ε›žη΅ζžœζ ΌεΌζ­£η’Ί
44
- if completion.get("choices") and len(completion["choices"]) > 0:
45
- response = completion["choices"][0].get("message", {}).get("content", "ζŠ±ζ­‰οΌŒζˆ‘η„‘ζ³•η”Ÿζˆζœ‰ζ•ˆηš„ε›žζ‡‰γ€‚")
46
- return response
 
 
 
47
  else:
48
- return "ζŠ±ζ­‰οΌŒζˆ‘η„‘ζ³•θ§£ζž API ηš„ε›žζ‡‰η΅ζžœγ€‚"
49
 
50
  except Exception as e:
51
  return f"η™Όη”ŸιŒ―θͺ€οΌš{str(e)}"
 
 
 
1
  import os
2
  import gradio as gr
3
 
 
18
 
19
  client.api_key = api_key
20
 
 
 
21
  def chat_with_groq(user_message):
22
  """θˆ‡ Groq ζ¨‘εž‹ι€²θ‘ŒδΊ’ε‹•"""
23
  try:
24
+ # θͺΏη”¨ API
25
  completion = client.chat.completions.create(
26
  model="llama-3.1-70b-versatile",
27
  messages=[
 
37
  stream=False
38
  )
39
 
40
+ # ι©—θ­‰δΈ¦θ§£ζžε›žζ‡‰
41
+ if "choices" in completion and len(completion["choices"]) > 0:
42
+ response = completion["choices"][0].get("message", {}).get("content", None)
43
+ if response:
44
+ return response
45
+ else:
46
+ return "ζŠ±ζ­‰οΌŒζˆ‘η„‘ζ³•η”Ÿζˆζœ‰ζ•ˆηš„ε›žζ‡‰γ€‚"
47
  else:
48
+ return "ζŠ±ζ­‰οΌŒAPI ε›žζ‡‰ηš„η΅ζ§‹δΈη¬¦εˆι ζœŸγ€‚"
49
 
50
  except Exception as e:
51
  return f"η™Όη”ŸιŒ―θͺ€οΌš{str(e)}"