Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Update openai_api.py

王金淋25679346dc4c
diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py
index 11b1d38cb..8cb503572 100644
--- a/metagpt/provider/openai_api.py
+++ b/metagpt/provider/openai_api.py
@@ -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)