From 4c9341a53d0da74e3f226be50c478daabda9971b Mon Sep 17 00:00:00 2001 From: Yiran Wu <32823396+yiranwu0@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:07:13 -0700 Subject: [PATCH] update (#3175) Co-authored-by: HRUSHIKESH DOKALA <96101829+Hk669@users.noreply.github.com> --- autogen/oai/client.py | 2 +- test/oai/test_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autogen/oai/client.py b/autogen/oai/client.py index ef3a3fd2b1b3..4e9d794a1f75 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -795,7 +795,7 @@ def _cost_with_customized_price( 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: diff --git a/test/oai/test_client.py b/test/oai/test_client.py index debad5fae3b0..ea6f7ba7c5f7 100755 --- a/test/oai/test_client.py +++ b/test/oai/test_client.py @@ -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")