From d50c008979f504159b08ed494fa7e11d95de63b8 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 20 Aug 2024 11:48:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DXinference=20=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=9B=9E=E7=AD=94=E9=97=AE=E9=A2=98=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E5=AD=97=E4=BC=9A=E9=87=8D=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1045125 --user=王孝刚 【模型管理】本地 Xinference 模型回答问题最后几个字会重复一次 https://www.tapd.cn/57709429/s/1565685 --- apps/setting/models_provider/impl/base_chat_open_ai.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/setting/models_provider/impl/base_chat_open_ai.py b/apps/setting/models_provider/impl/base_chat_open_ai.py index 74afcf0f2..c70197eae 100644 --- a/apps/setting/models_provider/impl/base_chat_open_ai.py +++ b/apps/setting/models_provider/impl/base_chat_open_ai.py @@ -42,7 +42,8 @@ class BaseChatOpenAI(ChatOpenAI): for chunk in response: if not isinstance(chunk, dict): chunk = chunk.model_dump() - if len(chunk["choices"]) == 0 or chunk["choices"][0]["finish_reason"] == "length" or chunk["choices"][0]["finish_reason"] == "stop": + if (len(chunk["choices"]) == 0 or chunk["choices"][0]["finish_reason"] == "length" or + chunk["choices"][0]["finish_reason"] == "stop") and chunk.get("usage") is not None: if token_usage := chunk.get("usage"): self.__dict__.setdefault('_last_generation_info', {}).update(token_usage) logprobs = None