From 00e5f571f4ddcd8cc55de5c982466520f1b9a5bf Mon Sep 17 00:00:00 2001 From: olgavrou Date: Fri, 26 Jan 2024 11:23:17 -0500 Subject: [PATCH 1/3] fix: unit test should not call private function --- test/oai/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/oai/test_client.py b/test/oai/test_client.py index b8c93e13d707..c9ed42965cae 100644 --- a/test/oai/test_client.py +++ b/test/oai/test_client.py @@ -139,7 +139,7 @@ def test_usage_summary(): client.print_usage_summary() # check update - client._update_usage_summary(response, use_cache=True) + response = client.create(prompt="1+3=", model=model, cache_seed=None) assert ( client.total_usage_summary["total_cost"] == response.cost * 2 ), "total_cost should be equal to response.cost * 2" From 999980c017b2cbc252a89c33d2eb0519b0c26858 Mon Sep 17 00:00:00 2001 From: olgavrou Date: Fri, 26 Jan 2024 11:53:28 -0500 Subject: [PATCH 2/3] fix test --- test/oai/test_client.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/oai/test_client.py b/test/oai/test_client.py index c9ed42965cae..e5a742e832ba 100644 --- a/test/oai/test_client.py +++ b/test/oai/test_client.py @@ -126,7 +126,11 @@ def test_cost(cache_seed): @pytest.mark.skipif(skip, reason="openai>=1 not installed") def test_usage_summary(): - config_list = config_list_openai_aoai(KEY_LOC) + config_list = config_list_from_json( + env_or_file=OAI_CONFIG_LIST, + file_location=KEY_LOC, + filter_dict={"api_type": ["azure"], "model": ["gpt-3.5-turbo-instruct"]}, + ) client = OpenAIWrapper(config_list=config_list) model = "gpt-3.5-turbo-instruct" response = client.create(prompt="1+3=", model=model, cache_seed=None) @@ -138,12 +142,6 @@ def test_usage_summary(): # check print client.print_usage_summary() - # check update - response = client.create(prompt="1+3=", model=model, cache_seed=None) - assert ( - client.total_usage_summary["total_cost"] == response.cost * 2 - ), "total_cost should be equal to response.cost * 2" - # check clear client.clear_usage_summary() assert client.actual_usage_summary is None, "actual_usage_summary should be None" @@ -152,8 +150,16 @@ def test_usage_summary(): # actual usage and all usage should be different response = client.create(prompt="1+3=", model=model, cache_seed=42) assert client.total_usage_summary["total_cost"] > 0, "total_cost should be greater than 0" + client.clear_usage_summary() + response = client.create(prompt="1+3=", model=model, cache_seed=42) assert client.actual_usage_summary is None, "No actual cost should be recorded" + # check update + response = client.create(prompt="1+3=", model=model, cache_seed=42) + assert ( + client.total_usage_summary["total_cost"] == response.cost * 2 + ), "total_cost should be equal to response.cost * 2" + @pytest.mark.skipif(skip, reason="openai>=1 not installed") def test_legacy_cache(): From c15a8699f76a5e6197ac8d161fa12119304a3ab0 Mon Sep 17 00:00:00 2001 From: olgavrou Date: Fri, 26 Jan 2024 11:55:38 -0500 Subject: [PATCH 3/3] restore config --- test/oai/test_client.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/oai/test_client.py b/test/oai/test_client.py index e5a742e832ba..77b69cb71cad 100644 --- a/test/oai/test_client.py +++ b/test/oai/test_client.py @@ -126,11 +126,7 @@ def test_cost(cache_seed): @pytest.mark.skipif(skip, reason="openai>=1 not installed") def test_usage_summary(): - config_list = config_list_from_json( - env_or_file=OAI_CONFIG_LIST, - file_location=KEY_LOC, - filter_dict={"api_type": ["azure"], "model": ["gpt-3.5-turbo-instruct"]}, - ) + config_list = config_list_openai_aoai(KEY_LOC) client = OpenAIWrapper(config_list=config_list) model = "gpt-3.5-turbo-instruct" response = client.create(prompt="1+3=", model=model, cache_seed=None)