Spaces:
Running
Running
update
Browse files
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[-
|
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":
|
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
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
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 |
"""
|