fix: 修复usage 值为none 的情况

This commit is contained in:
huangpeilin 2024-05-08 19:22:10 +08:00
parent f201b2f5f3
commit 8695629fce

View file

@ -100,7 +100,7 @@ class OpenAILLM(BaseLLM):
log_llm_stream(chunk_message)
collected_messages.append(chunk_message)
if finish_reason:
if hasattr(chunk, "usage"):
if hasattr(chunk, "usage") and chunk.usage:
# Some services have usage as an attribute of the chunk, such as Fireworks
usage = CompletionUsage(**chunk.usage)
elif hasattr(chunk.choices[0], "usage"):