Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -165,6 +165,27 @@ def chat_completions():
|
|
| 165 |
mimetype='application/json'
|
| 166 |
)
|
| 167 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
match = re.search(r"jobId='([^']+)'", akash_response.text)
|
| 169 |
if match:
|
| 170 |
job_id = match.group(1)
|
|
|
|
| 165 |
mimetype='application/json'
|
| 166 |
)
|
| 167 |
else:
|
| 168 |
+
user_query = data.get('messages', [])[0]["content"]
|
| 169 |
+
#解决用dify或者new_api添加模型时报错
|
| 170 |
+
if user_query == "ping":
|
| 171 |
+
text_matches = re.findall(r'0:"(.*?)"', akash_response.text)
|
| 172 |
+
parsed_text = "".join(text_matches)
|
| 173 |
+
response_payload = {
|
| 174 |
+
"object": "chat.completion",
|
| 175 |
+
"created": int(time.time() * 1000),
|
| 176 |
+
"model": model,
|
| 177 |
+
"choices": [{
|
| 178 |
+
"index": 0,
|
| 179 |
+
"message": {"role": "assistant", "content": parsed_text},
|
| 180 |
+
"finish_reason": "stop"
|
| 181 |
+
}]
|
| 182 |
+
}
|
| 183 |
+
logging.info("非流式响应 payload: %s", json.dumps(response_payload, ensure_ascii=False))
|
| 184 |
+
return Response(
|
| 185 |
+
json.dumps(response_payload, ensure_ascii=False),
|
| 186 |
+
status=akash_response.status_code,
|
| 187 |
+
mimetype='application/json'
|
| 188 |
+
)
|
| 189 |
match = re.search(r"jobId='([^']+)'", akash_response.text)
|
| 190 |
if match:
|
| 191 |
job_id = match.group(1)
|