Merge branch 'betterwang-mgx_ops-patch-18744' into 'mgx_ops'

update openai_api.py

See merge request pub/MetaGPT!401
This commit is contained in:
王金淋 2024-10-18 10:02:16 +00:00
commit 6879c93080

View file

@ -103,7 +103,7 @@ class OpenAILLM(BaseLLM):
if finish_reason:
if hasattr(chunk, "usage"):
# Some services have usage as an attribute of the chunk, such as Fireworks
usage = CompletionUsage(**chunk.usage)
usage = CompletionUsage(**chunk.usage) if isinstance(chunk.usage, dict) else chunk.usage
elif hasattr(chunk.choices[0], "usage"):
# The usage of some services is an attribute of chunk.choices[0], such as Moonshot
usage = CompletionUsage(**chunk.choices[0].usage)