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 1/3] 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" ) From 2252578da03234607101bba8d373e284523ae49d Mon Sep 17 00:00:00 2001 From: Yang An Date: Wed, 16 Aug 2023 15:10:10 +0800 Subject: [PATCH 2/3] Update openai_api.py --- openai_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openai_api.py b/openai_api.py index 6f90458..568984f 100644 --- a/openai_api.py +++ b/openai_api.py @@ -123,11 +123,10 @@ async def create_chat_completion(request: ChatCompletionRequest): generate = predict(query, history, request.model) return EventSourceResponse(generate, media_type="text/event-stream") - responses = [resp for resp in model.chat_stream(tokenizer, query, history=history)] - combined_response = ''.join(responses) + response, _ = model.chat_stream(tokenizer, query, history=history) choice_data = ChatCompletionResponseChoice( index=0, - message=ChatMessage(role="assistant", content=combined_response), + message=ChatMessage(role="assistant", content=response), finish_reason="stop" ) From 555d815ec0aff0fbc9a3f7970e594955df18749c Mon Sep 17 00:00:00 2001 From: Yang An Date: Wed, 16 Aug 2023 15:11:24 +0800 Subject: [PATCH 3/3] Update openai_api.py --- openai_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai_api.py b/openai_api.py index 568984f..da105f3 100644 --- a/openai_api.py +++ b/openai_api.py @@ -123,7 +123,7 @@ 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) + response, _ = model.chat(tokenizer, query, history=history) choice_data = ChatCompletionResponseChoice( index=0, message=ChatMessage(role="assistant", content=response),