smgc commited on
Commit
352e325
1 Parent(s): 5d0e80d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -148,7 +148,6 @@ def messages():
148
  text = json.loads(data['text'])
149
  chunk = text['chunks'][-1] if text['chunks'] else None
150
  if chunk:
151
- chunk = json.loads(f'"{chunk}"') # 解码 Unicode 转义序列
152
  response_text.append(chunk)
153
 
154
  def on_query_complete(data):
@@ -199,7 +198,7 @@ def messages():
199
  "delta": {"stop_reason": "end_turn", "stop_sequence": None},
200
  "usage": {"output_tokens": len(''.join(response_text))},
201
  })
202
- yield create_event("message_stop", {"type": "message_stop"}) # 添加 message_stop 事件
203
  log_request(request.remote_addr, request.path, 200)
204
 
205
  return Response(generate(), content_type='text/event-stream')
@@ -222,7 +221,7 @@ def server_error(error):
222
 
223
  def create_event(event, data):
224
  if isinstance(data, dict):
225
- data = json.dumps(data)
226
  return f"event: {event}\ndata: {data}\n\n"
227
 
228
  if __name__ == '__main__':
 
148
  text = json.loads(data['text'])
149
  chunk = text['chunks'][-1] if text['chunks'] else None
150
  if chunk:
 
151
  response_text.append(chunk)
152
 
153
  def on_query_complete(data):
 
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')
 
221
 
222
  def create_event(event, data):
223
  if isinstance(data, dict):
224
+ data = json.dumps(data, ensure_ascii=False) # 确保中文不会被转义
225
  return f"event: {event}\ndata: {data}\n\n"
226
 
227
  if __name__ == '__main__':