From db26e36d37625391de6dd6c2630f80fe37ede7c0 Mon Sep 17 00:00:00 2001 From: xun Date: Thu, 23 May 2024 21:08:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86usage=E4=B8=BA=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/provider/openai_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 067dc3923..31907d9e8 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -102,7 +102,10 @@ class OpenAILLM(BaseLLM): if finish_reason: if hasattr(chunk, "usage") and chunk.usage is not None: # Some services have usage as an attribute of the chunk, such as Fireworks - usage = CompletionUsage(**chunk.usage) + if isinstance(chunk.usage, CompletionUsage): + usage = chunk.usage + else: + usage = CompletionUsage(**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)