From 8695629fce6be6b72c53ec6c6f48d051bdcac6a0 Mon Sep 17 00:00:00 2001 From: huangpeilin Date: Wed, 8 May 2024 19:22:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dusage=20=E5=80=BC?= =?UTF-8?q?=E4=B8=BAnone=20=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 7957f775c..cc1a4fc8b 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -100,7 +100,7 @@ async def _achat_completion_stream(self, messages: list[dict], timeout=USE_CONFI 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"): From a473c74c902b4e9e1aa9ac21baaf61e2a92ba6d5 Mon Sep 17 00:00:00 2001 From: huangpeilin Date: Thu, 9 May 2024 11:36:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/provider/openai_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index cc1a4fc8b..68dc156c2 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -100,7 +100,7 @@ async def _achat_completion_stream(self, messages: list[dict], timeout=USE_CONFI log_llm_stream(chunk_message) collected_messages.append(chunk_message) if finish_reason: - if hasattr(chunk, "usage") and chunk.usage: + 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) elif hasattr(chunk.choices[0], "usage"):