smgc commited on
Commit
ddf5e2a
·
verified ·
1 Parent(s): 0086ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -367,14 +367,12 @@ def count_message_tokens(messages, model="gpt-3.5-turbo-0301"):
367
 
368
  def stream_notdiamond_response(response, model):
369
  """流式处理 notdiamond API 响应。"""
370
- last_sent = ""
371
  for chunk in response.iter_content(1024):
372
  if chunk:
373
  new_content = chunk.decode('utf-8')
374
- to_send = new_content[len(last_sent):]
375
- if to_send:
376
- yield create_openai_chunk(to_send, model)
377
- last_sent = new_content
378
 
379
  yield create_openai_chunk('', model, 'stop')
380
 
 
367
 
368
  def stream_notdiamond_response(response, model):
369
  """流式处理 notdiamond API 响应。"""
370
+ buffer = ""
371
  for chunk in response.iter_content(1024):
372
  if chunk:
373
  new_content = chunk.decode('utf-8')
374
+ buffer += new_content
375
+ yield create_openai_chunk(new_content, model)
 
 
376
 
377
  yield create_openai_chunk('', model, 'stop')
378