Update app.py
Browse files
app.py
CHANGED
@@ -355,6 +355,20 @@ def handsome_chat_completions():
|
|
355 |
def generate():
|
356 |
first_chunk_time = None
|
357 |
full_response_content = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
for chunk in response.iter_content(chunk_size=2048):
|
359 |
if chunk:
|
360 |
if first_chunk_time is None:
|
@@ -397,8 +411,7 @@ def handsome_chat_completions():
|
|
397 |
|
398 |
if "finish_reason" in choice:
|
399 |
finish_reason = choice["finish_reason"]
|
400 |
-
|
401 |
-
logging.debug(f"Finish reason: {finish_reason}")
|
402 |
except json.JSONDecodeError as e:
|
403 |
logging.error(f"JSON 解析失败: {e}, 行内容: {line}")
|
404 |
except KeyError as e:
|
@@ -409,6 +422,7 @@ def handsome_chat_completions():
|
|
409 |
print(f'{response_content=}')
|
410 |
print(f'{prompt_tokens=}')
|
411 |
print(f'{completion_tokens=}')
|
|
|
412 |
user_content = extract_user_content(data.get("messages", []))
|
413 |
|
414 |
user_content_replaced = user_content.replace(
|
|
|
355 |
def generate():
|
356 |
first_chunk_time = None
|
357 |
full_response_content = ""
|
358 |
+
|
359 |
+
message_data = {
|
360 |
+
"choices": [
|
361 |
+
{
|
362 |
+
"delta": {
|
363 |
+
"content": "这是公益api,尽情享用"
|
364 |
+
},
|
365 |
+
"index": 0,
|
366 |
+
"finish_reason": None
|
367 |
+
}
|
368 |
+
]
|
369 |
+
}
|
370 |
+
yield f"data: {json.dumps(message_data)}\n\n".encode("utf-8")
|
371 |
+
|
372 |
for chunk in response.iter_content(chunk_size=2048):
|
373 |
if chunk:
|
374 |
if first_chunk_time is None:
|
|
|
411 |
|
412 |
if "finish_reason" in choice:
|
413 |
finish_reason = choice["finish_reason"]
|
414 |
+
logging.info(f"Finish reason: {finish_reason}")
|
|
|
415 |
except json.JSONDecodeError as e:
|
416 |
logging.error(f"JSON 解析失败: {e}, 行内容: {line}")
|
417 |
except KeyError as e:
|
|
|
422 |
print(f'{response_content=}')
|
423 |
print(f'{prompt_tokens=}')
|
424 |
print(f'{completion_tokens=}')
|
425 |
+
|
426 |
user_content = extract_user_content(data.get("messages", []))
|
427 |
|
428 |
user_content_replaced = user_content.replace(
|