From d2fc7c95db2f0646a7e875e7c543de62c7a5fa4d Mon Sep 17 00:00:00 2001 From: Artificial <2119516028@qq.com> Date: Wed, 16 Aug 2023 13:55:42 +0800 Subject: [PATCH] Update openai_api.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决调用api的bug:response, _ = model.chat_stream(tokenizer, query, history=history) ValueError: too many values to unpack (expected 2) 用api的时候建议把stream改成false --- openai_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openai_api.py b/openai_api.py index 568984f..6f90458 100644 --- a/openai_api.py +++ b/openai_api.py @@ -123,10 +123,11 @@ async def create_chat_completion(request: ChatCompletionRequest): generate = predict(query, history, request.model) return EventSourceResponse(generate, media_type="text/event-stream") - response, _ = model.chat_stream(tokenizer, query, history=history) + responses = [resp for resp in model.chat_stream(tokenizer, query, history=history)] + combined_response = ''.join(responses) choice_data = ChatCompletionResponseChoice( index=0, - message=ChatMessage(role="assistant", content=response), + message=ChatMessage(role="assistant", content=combined_response), finish_reason="stop" )