vlff李飞飞 commited on
Commit
fe2448f
1 Parent(s): 87ba825

update oai

Browse files
Files changed (1) hide show
  1. qwen_agent/llm/qwen_oai.py +7 -5
qwen_agent/llm/qwen_oai.py CHANGED
@@ -374,7 +374,8 @@ def predict(
374
  chunk = ChatCompletionResponse(
375
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
376
  )
377
- yield "{}".format(_dump_json(chunk, exclude_unset=True))
 
378
 
379
  current_length = 0
380
  stop_words_ids = [tokenizer.encode(s) for s in stop_words] if stop_words else None
@@ -400,7 +401,8 @@ def predict(
400
  chunk = ChatCompletionResponse(
401
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
402
  )
403
- yield "{}".format(_dump_json(chunk, exclude_unset=True))
 
404
 
405
  choice_data = ChatCompletionResponseStreamChoice(
406
  index=0, delta=DeltaMessage(), finish_reason="stop"
@@ -408,8 +410,9 @@ def predict(
408
  chunk = ChatCompletionResponse(
409
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
410
  )
411
- yield "{}".format(_dump_json(chunk, exclude_unset=True))
412
- yield "[DONE]"
 
413
 
414
  _gc()
415
 
@@ -452,7 +455,6 @@ class QwenChatAsOAI(BaseChatModel):
452
  response = create_chat_completion(_request)
453
  # TODO: error handling
454
  for chunk in response:
455
- chunk = json.loads(chunk)
456
  if hasattr(chunk.choices[0].delta, 'content'):
457
  yield chunk.choices[0].delta.content
458
 
 
374
  chunk = ChatCompletionResponse(
375
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
376
  )
377
+ # yield "{}".format(_dump_json(chunk, exclude_unset=True))
378
+ yield chunk
379
 
380
  current_length = 0
381
  stop_words_ids = [tokenizer.encode(s) for s in stop_words] if stop_words else None
 
401
  chunk = ChatCompletionResponse(
402
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
403
  )
404
+ # yield "{}".format(_dump_json(chunk, exclude_unset=True))
405
+ yield chunk
406
 
407
  choice_data = ChatCompletionResponseStreamChoice(
408
  index=0, delta=DeltaMessage(), finish_reason="stop"
 
410
  chunk = ChatCompletionResponse(
411
  model=model_id, choices=[choice_data], object="chat.completion.chunk"
412
  )
413
+ # yield "{}".format(_dump_json(chunk, exclude_unset=True))
414
+ yield chunk
415
+ # yield "[DONE]"
416
 
417
  _gc()
418
 
 
455
  response = create_chat_completion(_request)
456
  # TODO: error handling
457
  for chunk in response:
 
458
  if hasattr(chunk.choices[0].delta, 'content'):
459
  yield chunk.choices[0].delta.content
460