chore: log cost object (#829)

This commit is contained in:
Tim
2025-04-25 19:26:08 +08:00
committed by GitHub
parent 686437d671
commit 6be059dd5d
+12
View File
@@ -139,4 +139,16 @@ class LiteLLMAPIBackend(APIBackend):
logger.info(
f"Current Cost: ${float(cost):.10f}; Accumulated Cost: ${float(ACC_COST):.10f}; {finish_reason=}",
)
prompt_tokens = token_counter(model=model, messages=messages)
completion_tokens = token_counter(model=model, text=content)
logger.log_object(
{
"model": model,
"prompt_tokens": prompt_tokens,
"completion_tokens": completion_tokens,
"cost": cost,
"accumulated_cost": ACC_COST,
},
tag="token_cost",
)
return content, finish_reason