Update app.py
Browse files
app.py
CHANGED
@@ -150,6 +150,10 @@ def messages():
|
|
150 |
if chunk:
|
151 |
response_text.append(chunk)
|
152 |
|
|
|
|
|
|
|
|
|
153 |
def on_query_complete(data):
|
154 |
response_event.set()
|
155 |
|
@@ -198,7 +202,7 @@ def messages():
|
|
198 |
"delta": {"stop_reason": "end_turn", "stop_sequence": None},
|
199 |
"usage": {"output_tokens": len(''.join(response_text))},
|
200 |
})
|
201 |
-
yield create_event("message_stop", {"type": "message_stop"})
|
202 |
log_request(request.remote_addr, request.path, 200)
|
203 |
|
204 |
return Response(generate(), content_type='text/event-stream')
|
|
|
150 |
if chunk:
|
151 |
response_text.append(chunk)
|
152 |
|
153 |
+
# 检查是否是最终响应
|
154 |
+
if data.get('final', False):
|
155 |
+
response_event.set()
|
156 |
+
|
157 |
def on_query_complete(data):
|
158 |
response_event.set()
|
159 |
|
|
|
202 |
"delta": {"stop_reason": "end_turn", "stop_sequence": None},
|
203 |
"usage": {"output_tokens": len(''.join(response_text))},
|
204 |
})
|
205 |
+
yield create_event("message_stop", {"type": "message_stop"}) # 确保发送 message_stop 事件
|
206 |
log_request(request.remote_addr, request.path, 200)
|
207 |
|
208 |
return Response(generate(), content_type='text/event-stream')
|