From cbdfac309f1cc3df52b8189f2acb03c53bd7e01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Thu, 1 Feb 2024 22:37:57 +0800 Subject: [PATCH] fixbug: num_tokens_from_messages() is not implemented --- metagpt/provider/azure_openai_api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/metagpt/provider/azure_openai_api.py b/metagpt/provider/azure_openai_api.py index 6dc32d380..99063f7cf 100644 --- a/metagpt/provider/azure_openai_api.py +++ b/metagpt/provider/azure_openai_api.py @@ -6,14 +6,14 @@ @Modified By: mashenquan, 2023/11/21. Fix bug: ReadTimeout. @Modified By: mashenquan, 2023/12/1. Fix bug: Unclosed connection caused by openai 0.x. """ - - from openai import AsyncAzureOpenAI from openai._base_client import AsyncHttpxClientWrapper +from openai.types import CompletionUsage from metagpt.configs.llm_config import LLMType from metagpt.provider.llm_provider_registry import register_provider from metagpt.provider.openai_api import OpenAILLM +from metagpt.utils.exceptions import handle_exception @register_provider(LLMType.AZURE) @@ -41,3 +41,10 @@ class AzureOpenAILLM(OpenAILLM): kwargs["http_client"] = AsyncHttpxClientWrapper(**proxy_params) return kwargs + + def _calc_usage(self, messages: list[dict], rsp: str) -> CompletionUsage: + return CompletionUsage(prompt_tokens=0, completion_tokens=0, total_tokens=0) + + @handle_exception + def _update_costs(self, usage: CompletionUsage): + pass