🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
openai_api: refine logic
geekane8cb7991c447
diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.pyindex a73bb0aa0..86054881e 100644--- a/metagpt/provider/openai_api.py+++ b/metagpt/provider/openai_api.py@@ -329,7 +329,8 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):usage["completion_tokens"] = completion_tokensreturn usageexcept Exception as e:- logger.error("usage calculation failed!", e)+ logger.error(f"{self.model} usage calculation failed!", e)+ return {}else:return usage@@ -360,7 +361,7 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):return resultsdef _update_costs(self, usage: dict):- if CONFIG.calc_usage:+ if CONFIG.calc_usage and usage:try:prompt_tokens = int(usage["prompt_tokens"])completion_tokens = int(usage["completion_tokens"])