nanova commited on
Commit
fd11aed
·
1 Parent(s): 9cb8eea
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -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,25 +64,16 @@ def respond(
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
- response_content = json_response['choices'][0].get('message', {}).get('content', '')
71
- # 去掉<think>标签及其内容
72
- import re
73
- clean_response = re.sub(r'<think>.*?</think>', '', response_content).strip()
74
- if clean_response:
75
- print(f"[INFO] Cleaned API response content: {clean_response}")
76
- return clean_response
77
- else:
78
- print("[ERROR] No cleaned content found in API response")
79
- return "No content in the response after cleaning"
80
- else:
81
- print("[ERROR] No choices found in API response")
82
- return "No choices in the response"
83
- else:
84
- print(f"[ERROR] Unexpected status code: {r.status_code}")
85
- return "Unexpected status code from API"
86
  except Exception as e:
87
  print(f"[ERROR] Request error: {e}")
88
  return "Service error occurred"
 
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
+ print(f"[ERROR] API Error: {r.status_code} - {r.text}")
69
+ return "Service error"
70
+ json_response = r.json()
71
+ print(f"[DEBUG] API Response: {json.dumps(json_response, indent=2)}")
72
+ if 'choices' in json_response and len(json_response['choices']) > 0:
73
+ response = json_response['choices'][0].get('message', {}).get('content', '')
74
+ if response:
75
+ return response
76
+ return "No response from model"
 
 
 
 
 
 
 
 
 
77
  except Exception as e:
78
  print(f"[ERROR] Request error: {e}")
79
  return "Service error occurred"