nanova commited on
Commit
63850fe
·
1 Parent(s): ebfa154
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -16,7 +16,7 @@ if not API_URL or not API_TOKEN:
16
  raise ValueError("请确保设置了环境变量 API_URL 和 API_TOKEN")
17
 
18
  print(f"[INFO] starting:")
19
- print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-12:]}")
20
  print(f"[INFO] API_TOKEN: {API_TOKEN[:10]}...{API_TOKEN[-10:]}") # 只显示token的前10位和后10位
21
 
22
  """
@@ -48,7 +48,7 @@ def respond(
48
 
49
  data = {
50
  "model": "/data/DMind-1-mini",
51
- "stream": True,
52
  "messages": messages,
53
  "temperature": temperature,
54
  "top_p": top_p,
@@ -64,18 +64,13 @@ def respond(
64
 
65
  response = ""
66
 
67
- with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
68
- for line in r.iter_lines():
69
- if line:
70
- try:
71
- json_response = json.loads(line.decode('utf-8').replace('data: ', ''))
72
- if 'choices' in json_response and len(json_response['choices']) > 0:
73
- token = json_response['choices'][0].get('delta', {}).get('content', '')
74
- if token:
75
- response += token
76
- yield response
77
- except json.JSONDecodeError:
78
- continue
79
 
80
 
81
  """
 
16
  raise ValueError("请确保设置了环境变量 API_URL 和 API_TOKEN")
17
 
18
  print(f"[INFO] starting:")
19
+ print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-13:]}")
20
  print(f"[INFO] API_TOKEN: {API_TOKEN[:10]}...{API_TOKEN[-10:]}") # 只显示token的前10位和后10位
21
 
22
  """
 
48
 
49
  data = {
50
  "model": "/data/DMind-1-mini",
51
+ "stream": False, # 改为非流式模式
52
  "messages": messages,
53
  "temperature": temperature,
54
  "top_p": top_p,
 
64
 
65
  response = ""
66
 
67
+ with requests.post(API_URL, headers=headers, json=data) as r:
68
+ if r.status_code == 200:
69
+ json_response = r.json()
70
+ if 'choices' in json_response and len(json_response['choices']) > 0:
71
+ response = json_response['choices'][0].get('message', {}).get('content', '')
72
+ if response:
73
+ yield response
 
 
 
 
 
74
 
75
 
76
  """