Co-authored-by: HRUSHIKESH DOKALA <96101829+Hk669@users.noreply.github.com>
This commit is contained in:
Yiran Wu 2024-07-21 14:07:13 -07:00 committed by GitHub
parent adf438abfa
commit c19f44f626
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -795,7 +795,7 @@ class OpenAIWrapper:
n_output_tokens = response.usage.completion_tokens if response.usage is not None else 0 # type: ignore [union-attr]
if n_output_tokens is None:
n_output_tokens = 0
return n_input_tokens * price_1k[0] + n_output_tokens * price_1k[1]
return (n_input_tokens * price_1k[0] + n_output_tokens * price_1k[1]) / 1000
@staticmethod
def _update_dict_from_chunk(chunk: BaseModel, d: Dict[str, Any], field: str) -> int:

View File

@ -140,10 +140,10 @@ def test_customized_cost():
env_or_file=OAI_CONFIG_LIST, file_location=KEY_LOC, filter_dict={"tags": ["gpt-3.5-turbo-instruct"]}
)
for config in config_list:
config.update({"price": [1, 1]})
config.update({"price": [1000, 1000]})
client = OpenAIWrapper(config_list=config_list, cache_seed=None)
response = client.create(prompt="1+3=")
assert response.cost >= 4, "Due to customized pricing, cost should be greater than 4"
assert response.cost >= 4 and response.cost < 10, "Due to customized pricing, cost should be > 4 and < 10"
@pytest.mark.skipif(skip, reason="openai>=1 not installed")