Spaces:
Running
Running
update
Browse files
app.py
CHANGED
@@ -13,10 +13,10 @@ API_TOKEN = os.getenv("API_TOKEN")
|
|
13 |
|
14 |
# 验证必要的环境变量
|
15 |
if not API_URL or not API_TOKEN:
|
16 |
-
raise ValueError("
|
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": False,
|
52 |
"messages": messages,
|
53 |
"temperature": temperature,
|
54 |
"top_p": top_p,
|
@@ -64,16 +64,14 @@ def respond(
|
|
64 |
|
65 |
try:
|
66 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
67 |
-
if r.status_code
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
return "hello"
|
76 |
-
return "No response from model"
|
77 |
except Exception as e:
|
78 |
print(f"[ERROR] Request error: {e}")
|
79 |
return "Service error occurred"
|
|
|
13 |
|
14 |
# 验证必要的环境变量
|
15 |
if not API_URL or not API_TOKEN:
|
16 |
+
raise ValueError("make sure 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 |
|
49 |
data = {
|
50 |
"model": "/data/DMind-1-mini",
|
51 |
+
"stream": False, # 改为非流式模式
|
52 |
"messages": messages,
|
53 |
"temperature": temperature,
|
54 |
"top_p": top_p,
|
|
|
64 |
|
65 |
try:
|
66 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
67 |
+
if r.status_code == 200:
|
68 |
+
json_response = r.json()
|
69 |
+
if 'choices' in json_response and len(json_response['choices']) > 0:
|
70 |
+
content = json_response['choices'][0].get('message', {}).get('content', '')
|
71 |
+
print(f"[INFO] response: {content}")
|
72 |
+
if content:
|
73 |
+
return content
|
74 |
+
return "Service temporarily unavailable"
|
|
|
|
|
75 |
except Exception as e:
|
76 |
print(f"[ERROR] Request error: {e}")
|
77 |
return "Service error occurred"
|