community[patch]: fix cost calculations for o3 in OpenAI callback (#30807)

Resolves https://github.com/langchain-ai/langchain/issues/30795
This commit is contained in:
ccurme 2025-04-13 11:20:46 -04:00 committed by GitHub
parent 446361a0d3
commit f005988e31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -218,12 +218,17 @@ def standardize_model_name(
or model_name.startswith("gpt-3.5")
or model_name.startswith("gpt-35")
or model_name.startswith("o1-")
or model_name.startswith("o3-")
or ("finetuned" in model_name and "legacy" not in model_name)
):
return model_name + "-completion"
if (
token_type == TokenType.PROMPT_CACHED
and (model_name.startswith("gpt-4o") or model_name.startswith("o1"))
and (
model_name.startswith("gpt-4o")
or model_name.startswith("o1")
or model_name.startswith("o3")
)
and not (model_name.startswith("gpt-4o-2024-05-13"))
):
return model_name + "-cached"