Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
45 |
-
response = completion["choices"][0].get("message", {}).get("content",
|
46 |
-
|
|
|
|
|
|
|
47 |
else:
|
48 |
-
return "
|
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)}"
|