openai[patch]: add check for none values when summing token usage (#27585)

**Description:** Fixes None addition issues when an empty value is
passed on

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
This commit is contained in:
yahya-mouman 2024-10-28 20:49:43 +01:00 committed by GitHub
parent ede953d617
commit 6803cb4f34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -605,6 +605,8 @@ class BaseChatOpenAI(BaseChatModel):
token_usage = output["token_usage"]
if token_usage is not None:
for k, v in token_usage.items():
if v is None:
continue
if k in overall_token_usage:
overall_token_usage[k] = _update_token_usage(
overall_token_usage[k], v