mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 08:58:48 +00:00
check keys before using (#475)
This commit is contained in:
parent
12aa43469f
commit
3e41ab7bff
@ -142,11 +142,12 @@ class BaseOpenAI(BaseLLM, BaseModel):
|
|||||||
token_usage = {}
|
token_usage = {}
|
||||||
# Get the token usage from the response.
|
# Get the token usage from the response.
|
||||||
# Includes prompt, completion, and total tokens used.
|
# Includes prompt, completion, and total tokens used.
|
||||||
_keys = ["completion_tokens", "prompt_tokens", "total_tokens"]
|
_keys = {"completion_tokens", "prompt_tokens", "total_tokens"}
|
||||||
for _prompts in sub_prompts:
|
for _prompts in sub_prompts:
|
||||||
response = self.client.create(prompt=_prompts, **params)
|
response = self.client.create(prompt=_prompts, **params)
|
||||||
choices.extend(response["choices"])
|
choices.extend(response["choices"])
|
||||||
for _key in _keys:
|
_keys_to_use = _keys.intersection(response["usage"])
|
||||||
|
for _key in _keys_to_use:
|
||||||
if _key not in token_usage:
|
if _key not in token_usage:
|
||||||
token_usage[_key] = response["usage"][_key]
|
token_usage[_key] = response["usage"][_key]
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user