mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
partners: (langchain-openai) total_tokens should not add 'Nonetype' t… (#31146)
partners: (langchain-openai) total_tokens should not add 'Nonetype' t… # PR Description ## Description Fixed an issue in `langchain-openai` where `total_tokens` was incorrectly adding `None` to an integer, causing a TypeError. The fix ensures proper type checking before adding token counts. ## Issue Fixes the TypeError traceback shown in the image where `'NoneType'` cannot be added to an integer. ## Dependencies None ## Twitter handle None  Co-authored-by: qiulijie <qiulijie@yuaiweiwu.com>
This commit is contained in:
parent
19041dcc95
commit
1df3ee91e7
@ -2924,9 +2924,9 @@ class OpenAIRefusalError(Exception):
|
||||
|
||||
|
||||
def _create_usage_metadata(oai_token_usage: dict) -> UsageMetadata:
|
||||
input_tokens = oai_token_usage.get("prompt_tokens", 0)
|
||||
output_tokens = oai_token_usage.get("completion_tokens", 0)
|
||||
total_tokens = oai_token_usage.get("total_tokens", input_tokens + output_tokens)
|
||||
input_tokens = oai_token_usage.get("prompt_tokens") or 0
|
||||
output_tokens = oai_token_usage.get("completion_tokens") or 0
|
||||
total_tokens = oai_token_usage.get("total_tokens") or input_tokens + output_tokens
|
||||
input_token_details: dict = {
|
||||
"audio": (oai_token_usage.get("prompt_tokens_details") or {}).get(
|
||||
"audio_tokens"
|
||||
|
Loading…
Reference in New Issue
Block a user