mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
always update_costs when set calc_usage=True
This commit is contained in:
parent
bab605ac44
commit
9373634e86
1 changed files with 3 additions and 3 deletions
|
|
@ -224,8 +224,8 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
return self.get_choice_text(rsp)
|
||||
|
||||
def _calc_usage(self, messages: list[dict], rsp: str) -> dict:
|
||||
usage = {}
|
||||
if CONFIG.calc_usage:
|
||||
usage = {}
|
||||
try:
|
||||
prompt_tokens = count_message_tokens(messages, self.model)
|
||||
completion_tokens = count_string_tokens(rsp, self.model)
|
||||
|
|
@ -234,7 +234,8 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
return usage
|
||||
except Exception as e:
|
||||
logger.error("usage calculation failed!", e)
|
||||
CONFIG.calc_usage = False
|
||||
else:
|
||||
return usage
|
||||
|
||||
async def acompletion_batch(self, batch: list[list[dict]]) -> list[dict]:
|
||||
"""返回完整JSON"""
|
||||
|
|
@ -270,7 +271,6 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
self._cost_manager.update_cost(prompt_tokens, completion_tokens, self.model)
|
||||
except Exception as e:
|
||||
logger.error("updating costs failed!", e)
|
||||
CONFIG.calc_usage = False
|
||||
|
||||
def get_costs(self) -> Costs:
|
||||
return self._cost_manager.get_costs()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue