Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,24 +27,23 @@ def respond(
|
|
| 27 |
|
| 28 |
# ارسال درخواست به API DeepSeek
|
| 29 |
headers = {
|
| 30 |
-
"Authorization": f"Bearer {
|
| 31 |
"Content-Type": "application/json",
|
| 32 |
}
|
| 33 |
payload = {
|
| 34 |
-
"model": "
|
| 35 |
"messages": messages,
|
| 36 |
"max_tokens": max_tokens,
|
| 37 |
"temperature": temperature,
|
| 38 |
"top_p": top_p,
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if response.status_code == 200:
|
| 44 |
response_data = response.json()
|
| 45 |
yield response_data["choices"][0]["message"]["content"]
|
| 46 |
-
|
| 47 |
-
yield "خطا در ارتباط با سرور DeepSeek
|
| 48 |
|
| 49 |
# ایجاد رابط کاربری با Gradio
|
| 50 |
demo = gr.ChatInterface(
|
|
|
|
| 27 |
|
| 28 |
# ارسال درخواست به API DeepSeek
|
| 29 |
headers = {
|
| 30 |
+
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
|
| 31 |
"Content-Type": "application/json",
|
| 32 |
}
|
| 33 |
payload = {
|
| 34 |
+
"model": "gpt-3.5-turbo", # استفاده از مدل gpt-3.5-turbo
|
| 35 |
"messages": messages,
|
| 36 |
"max_tokens": max_tokens,
|
| 37 |
"temperature": temperature,
|
| 38 |
"top_p": top_p,
|
| 39 |
}
|
| 40 |
+
try:
|
| 41 |
+
response = requests.post(DEEPSEEK_API_URL, headers=headers, json=payload)
|
| 42 |
+
response.raise_for_status() # بررسی خطاهای HTTP
|
|
|
|
| 43 |
response_data = response.json()
|
| 44 |
yield response_data["choices"][0]["message"]["content"]
|
| 45 |
+
except requests.exceptions.RequestException as e:
|
| 46 |
+
yield f"خطا در ارتباط با سرور DeepSeek: {str(e)}"
|
| 47 |
|
| 48 |
# ایجاد رابط کاربری با Gradio
|
| 49 |
demo = gr.ChatInterface(
|