fix: 修复Xinference 模型回答问题最后几个字会重复一次

--bug=1045125 --user=王孝刚 【模型管理】本地 Xinference 模型回答问题最后几个字会重复一次 https://www.tapd.cn/57709429/s/1565685
This commit is contained in:
wxg0103 2024-08-20 11:48:12 +08:00 committed by wxg0103
parent df33fc80d8
commit d50c008979

View File

@ -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