smgc commited on
Commit
38637c0
1 Parent(s): 352e325

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
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')