mohammadshahabiy commited on
Commit
7d9a618
·
verified ·
1 Parent(s): 42fc2cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -27,24 +27,23 @@ def respond(
27
 
28
  # ارسال درخواست به API DeepSeek
29
  headers = {
30
- "Authorization": f"Bearer {sk-fb523fb5a222445fae65de601818f622}",
31
  "Content-Type": "application/json",
32
  }
33
  payload = {
34
- "model": "deepseek-v3",
35
  "messages": messages,
36
  "max_tokens": max_tokens,
37
  "temperature": temperature,
38
  "top_p": top_p,
39
  }
40
- response = requests.post(DEEPSEEK_API_URL, headers=headers, json=payload)
41
-
42
- # بررسی پاسخ و استخراج متن
43
- if response.status_code == 200:
44
  response_data = response.json()
45
  yield response_data["choices"][0]["message"]["content"]
46
- else:
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(