From f5cbce8f098c442e5bf0e962330559412549037a Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 16:11:02 +0530 Subject: [PATCH 01/14] chore: add loadbalance and fallback test cases for images --- .../segmind_n_openai.json | 36 +++++++++++++++++++ .../loadbalance_with_two_apikeys.json | 19 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json create mode 100644 tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json diff --git a/tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json b/tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json new file mode 100644 index 00000000..644ec482 --- /dev/null +++ b/tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json @@ -0,0 +1,36 @@ +{ + "strategy": { + "mode": "loadbalance" + }, + "targets": [ + { + "virtual_key": "openai-virtual-key", + "override_params": { + "model": "dall-e-2" + } + }, + { + "strategy": { + "mode": "fallback", + "on_status_codes": [ + 429, + 241 + ] + }, + "targets": [ + { + "virtual_key": "openai-virtual-key", + "override_params": { + "model": "dall-e-2" + } + }, + { + "virtual_key": "segmind-virtual-key", + "override_params": { + "model": "sdxl1.0-newreality-lightning" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json new file mode 100644 index 00000000..441e5291 --- /dev/null +++ b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json @@ -0,0 +1,19 @@ +{ + "strategy": { + "mode": "loadbalance" + }, + "targets": [ + { + "virtual_key": "openai-virtual-key", + "override_params": { + "model": "dall-e-2" + } + }, + { + "virtual_key": "segmind-virtual-key", + "override_params": { + "model": "sdxl1.0-newreality-lightning" + } + } + ] +} \ No newline at end of file From 4e7ff8132ad1d7e107e9491394c566bd57d27edf Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 16:11:52 +0530 Subject: [PATCH 02/14] chore: fix loadbalance and fallback test cases for images --- tests/test_images.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_images.py b/tests/test_images.py index 4f6dc400..8702510a 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -158,10 +158,10 @@ def test_method_loadbalance_with_two_apikeys( ) image = portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" + prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" ) - assert type(image.data[0].url) is str + assert type(image.data[0].b64_json) is str # -------------------------- # Test-5 @@ -179,10 +179,10 @@ def test_method_loadbalance_and_fallback(self, client: Any, config: Dict) -> Non ) image = portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" + prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" ) - assert type(image.data[0].url) is str + assert type(image.data[0].b64_json) is str # -------------------------- # Test-6 From 1856236ad4183fb8fa9606ad5957d55b20b9074e Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 16:16:51 +0530 Subject: [PATCH 03/14] chore: update assistants test cases --- tests/test_assistants.py | 79 +++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/tests/test_assistants.py b/tests/test_assistants.py index 10e589ca..ffe3d83e 100644 --- a/tests/test_assistants.py +++ b/tests/test_assistants.py @@ -39,35 +39,56 @@ def get_metadata(self): "random_id": str(uuid4()), } - # # -------------------------- - # # Test-1 - - # t1_params = [] - # t = [] - # for k, v in models.items(): - # if k == "openai": - # for i in v["chat"]: - # if "vision" not in i: - # t.append((client, k, os.environ.get(v["env_variable"]), i)) - - # t1_params.extend(t) - - # @pytest.mark.parametrize("client, provider, auth, model", t1_params) - # def test_method_single_with_vk_and_provider( - # self, client: Any, provider: str, auth: str, model - # ) -> None: - # portkey = client( - # base_url=base_url, - # api_key=api_key, - # provider=f"{provider}", - # Authorization=f"{auth}", - # trace_id=str(uuid4()), - # metadata=self.get_metadata(), - # ) - # assistant = portkey.beta.assistants.create( - # model=model, - # ) - # print(assistant) + # -------------------------- + # Test-1 + + t1_params = [] + t = [] + for k, v in models.items(): + if k == "openai": + for i in v["chat"]: + if "vision" not in i: + t.append((client, k, os.environ.get(v["env_variable"]), i)) + + t1_params.extend(t) + + @pytest.mark.parametrize("client, provider, auth, model", t1_params) + def test_method_single_with_vk_and_provider( + self, client: Any, provider: str, auth: str, model + ) -> None: + portkey = client( + base_url=base_url, + api_key=api_key, + provider=f"{provider}", + Authorization=f"{auth}", + trace_id=str(uuid4()), + metadata=self.get_metadata(), + ) + assistant = portkey.beta.assistants.create( + model=model, + ) + + assert type(assistant.id) is str + assert assistant.object == "assistant" + assert assistant.model == model + + update_assistant = portkey.beta.assistants.update( + assistant.id, description="updated string" + ) + + assert update_assistant.description == "updated string" + + retrieve_assistant = portkey.beta.assistants.retrieve(assistant.id) + + assert retrieve_assistant.id == assistant.id + assert retrieve_assistant.object == "assistant" + assert retrieve_assistant.model == model + + delete_assistant = portkey.beta.assistants.delete(assistant.id) + + assert delete_assistant.id == assistant.id + assert delete_assistant.object == "assistant.deleted" + assert delete_assistant.deleted is True # -------------------------- # Test-3 From ed44eaf95dfae89ce40a69b2bb68d428506285cc Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 16:17:27 +0530 Subject: [PATCH 04/14] chore: remove unused comments --- tests/test_async_chat_complete.py | 2 -- tests/test_async_complete.py | 2 -- tests/test_async_images.py | 1 - tests/test_chat_complete.py | 2 -- tests/test_complete.py | 2 -- tests/test_images.py | 1 - 6 files changed, 10 deletions(-) diff --git a/tests/test_async_chat_complete.py b/tests/test_async_chat_complete.py index a0def363..c0aaaaac 100644 --- a/tests/test_async_chat_complete.py +++ b/tests/test_async_chat_complete.py @@ -182,7 +182,6 @@ async def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, @@ -409,7 +408,6 @@ async def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, diff --git a/tests/test_async_complete.py b/tests/test_async_complete.py index cd063727..c3a9060f 100644 --- a/tests/test_async_complete.py +++ b/tests/test_async_complete.py @@ -179,7 +179,6 @@ async def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, @@ -388,7 +387,6 @@ async def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, diff --git a/tests/test_async_images.py b/tests/test_async_images.py index a8413865..6ebf9e18 100644 --- a/tests/test_async_images.py +++ b/tests/test_async_images.py @@ -157,7 +157,6 @@ async def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, diff --git a/tests/test_chat_complete.py b/tests/test_chat_complete.py index 48727950..e7d309cf 100644 --- a/tests/test_chat_complete.py +++ b/tests/test_chat_complete.py @@ -177,7 +177,6 @@ def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, @@ -394,7 +393,6 @@ def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, diff --git a/tests/test_complete.py b/tests/test_complete.py index 218971a4..a4c13726 100644 --- a/tests/test_complete.py +++ b/tests/test_complete.py @@ -170,7 +170,6 @@ def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, @@ -368,7 +367,6 @@ def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, diff --git a/tests/test_images.py b/tests/test_images.py index 8702510a..1f4ea2d3 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -151,7 +151,6 @@ def test_method_loadbalance_with_two_apikeys( portkey = client( base_url=base_url, api_key=api_key, - # virtual_key=virtual_api_key, trace_id=str(uuid4()), metadata=self.get_metadata(), config=config, From 8cf27d6d8cafc42edf8c0f1fbae631ae8933b10d Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 17:39:22 +0530 Subject: [PATCH 05/14] fix: add missing await in async chat complete test --- tests/test_async_chat_complete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_async_chat_complete.py b/tests/test_async_chat_complete.py index c0aaaaac..967e6d90 100644 --- a/tests/test_async_chat_complete.py +++ b/tests/test_async_chat_complete.py @@ -162,7 +162,7 @@ async def test_method_single_provider_with_vk_retry_cache( config=config, ) - cached_completion = portkey_2.chat.completions.create( + cached_completion = await portkey_2.chat.completions.create( messages=[{"role": "user", "content": "Say this is a test"}], model="gpt-3.5-turbo", ) From a2d2ed995b7f8939edaf66dd6ef37c12dae49562 Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 17:40:04 +0530 Subject: [PATCH 06/14] chore: add loadbalance fallback test for async images --- tests/test_async_images.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_async_images.py b/tests/test_async_images.py index 6ebf9e18..11a2cbec 100644 --- a/tests/test_async_images.py +++ b/tests/test_async_images.py @@ -163,10 +163,10 @@ async def test_method_loadbalance_with_two_apikeys( ) image = await portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" + model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" ) - assert type(image.data[0].url) is str + assert type(image.data[0].b64_json) is str # -------------------------- # Test-5 @@ -187,10 +187,10 @@ async def test_method_loadbalance_and_fallback( ) image = await portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" + model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" ) - assert type(image.data[0].url) is str + assert type(image.data[0].b64_json) is str # -------------------------- # Test-6 From c4de831f1ae02d7f4f99088a77e59849d5c983a5 Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 17:41:09 +0530 Subject: [PATCH 07/14] chore: replace segmind with stability ai in test cases --- .../{segmind_n_openai.json => stability_n_openai.json} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename tests/configs/images/loadbalance_and_fallback/{segmind_n_openai.json => stability_n_openai.json} (75%) diff --git a/tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json b/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json similarity index 75% rename from tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json rename to tests/configs/images/loadbalance_and_fallback/stability_n_openai.json index 644ec482..e0553dc5 100644 --- a/tests/configs/images/loadbalance_and_fallback/segmind_n_openai.json +++ b/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json @@ -4,9 +4,9 @@ }, "targets": [ { - "virtual_key": "openai-virtual-key", + "virtual_key": "stability-virtual-key", "override_params": { - "model": "dall-e-2" + "model": "stable-diffusion-v1-6" } }, { @@ -25,9 +25,9 @@ } }, { - "virtual_key": "segmind-virtual-key", + "virtual_key": "stability-virtual-key", "override_params": { - "model": "sdxl1.0-newreality-lightning" + "model": "stable-diffusion-v1-6" } } ] From d3acb633f6ab8e0046c6066bdedc4a3a9353658c Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 17:41:43 +0530 Subject: [PATCH 08/14] chore: replace segmind with stability ai in test cases --- .../loadbalance_with_two_apikeys.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json index 441e5291..193057b4 100644 --- a/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json +++ b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json @@ -10,9 +10,9 @@ } }, { - "virtual_key": "segmind-virtual-key", + "virtual_key": "stability-virtual-key", "override_params": { - "model": "sdxl1.0-newreality-lightning" + "model": "stable-diffusion-v1-6" } } ] From 99c530da91d941b7bb84cb5b445b87f31c20b0bb Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 18:31:00 +0530 Subject: [PATCH 09/14] feat: release 1.2.0 --- portkey_ai/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portkey_ai/version.py b/portkey_ai/version.py index c4748725..848258f9 100644 --- a/portkey_ai/version.py +++ b/portkey_ai/version.py @@ -1 +1 @@ -VERSION = "1.1.7" +VERSION = "1.2.0" From 6c67b2fae3f2142e1a6a1fa4a7d0e4975ceb65fa Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 18:40:04 +0530 Subject: [PATCH 10/14] chore: test case formatting --- tests/test_async_images.py | 12 ++++++++++-- tests/test_images.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test_async_images.py b/tests/test_async_images.py index 11a2cbec..3f89da42 100644 --- a/tests/test_async_images.py +++ b/tests/test_async_images.py @@ -163,7 +163,11 @@ async def test_method_loadbalance_with_two_apikeys( ) image = await portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" + model="dall-e-3", + prompt="A cute baby sea otter", + n=1, + size="1024x1024", + response_format="b64_json", ) assert type(image.data[0].b64_json) is str @@ -187,7 +191,11 @@ async def test_method_loadbalance_and_fallback( ) image = await portkey.images.generate( - model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" + model="dall-e-3", + prompt="A cute baby sea otter", + n=1, + size="1024x1024", + response_format="b64_json", ) assert type(image.data[0].b64_json) is str diff --git a/tests/test_images.py b/tests/test_images.py index 1f4ea2d3..4663966e 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -157,7 +157,10 @@ def test_method_loadbalance_with_two_apikeys( ) image = portkey.images.generate( - prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" + prompt="A cute baby sea otter", + n=1, + size="1024x1024", + response_format="b64_json", ) assert type(image.data[0].b64_json) is str @@ -178,7 +181,10 @@ def test_method_loadbalance_and_fallback(self, client: Any, config: Dict) -> Non ) image = portkey.images.generate( - prompt="A cute baby sea otter", n=1, size="1024x1024", response_format="b64_json" + prompt="A cute baby sea otter", + n=1, + size="1024x1024", + response_format="b64_json", ) assert type(image.data[0].b64_json) is str From a9922d7e665693d6cbe49adcbdc04da641237436 Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 19:20:46 +0530 Subject: [PATCH 11/14] fix: build errors in test cases --- tests/test_assistants.py | 4 ++-- tests/test_async_chat_complete.py | 12 ++++++------ tests/test_async_complete.py | 12 ++++++------ tests/test_async_images.py | 14 +++++++------- tests/test_chat_complete.py | 12 ++++++------ tests/test_complete.py | 12 ++++++------ tests/test_images.py | 14 +++++++------- tests/test_threads.py | 6 +++--- tests/utils.py | 6 +++--- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/test_assistants.py b/tests/test_assistants.py index ffe3d83e..10c47f46 100644 --- a/tests/test_assistants.py +++ b/tests/test_assistants.py @@ -68,7 +68,7 @@ def test_method_single_with_vk_and_provider( model=model, ) - assert type(assistant.id) is str + assert isinstance(assistant.id, str) is True assert assistant.object == "assistant" assert assistant.model == model @@ -120,7 +120,7 @@ def test_method_all_params(self, client: Any, virtual_key: str) -> None: tools=[{"type": "code_interpreter"}], ) - assert type(assistant.id) is str + assert isinstance(assistant.id, str) assert assistant.object == "assistant" assert assistant.model == model assert assistant.name == "Math Tutor" diff --git a/tests/test_async_chat_complete.py b/tests/test_async_chat_complete.py index 967e6d90..06487f65 100644 --- a/tests/test_async_chat_complete.py +++ b/tests/test_async_chat_complete.py @@ -70,7 +70,7 @@ async def test_method_single_with_vk_and_provider( max_tokens=245, ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test -2 @@ -120,7 +120,7 @@ async def test_method_single_with_basic_config( model="gpt-3.5-turbo", ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-3 @@ -166,7 +166,7 @@ async def test_method_single_provider_with_vk_retry_cache( messages=[{"role": "user", "content": "Say this is a test"}], model="gpt-3.5-turbo", ) - assert type(cached_completion.choices[0].message.content) is str + assert isinstance(cached_completion.choices[0].message.content, str) is True # -------------------------- # Test-4 @@ -191,7 +191,7 @@ async def test_method_loadbalance_with_two_apikeys( messages=[{"role": "user", "content": "Say this is a test"}], max_tokens=245 ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-5 @@ -220,7 +220,7 @@ async def test_method_loadbalance_and_fallback( ], ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-6 @@ -243,7 +243,7 @@ async def test_method_single_provider(self, client: Any, config: Dict) -> None: model="gpt-3.5-turbo", ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True class TestChatCompletionsStreaming: diff --git a/tests/test_async_complete.py b/tests/test_async_complete.py index c3a9060f..1dabde9b 100644 --- a/tests/test_async_complete.py +++ b/tests/test_async_complete.py @@ -70,7 +70,7 @@ async def test_method_single_with_vk_and_provider( max_tokens=245, ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test -2 @@ -118,7 +118,7 @@ async def test_method_single_with_basic_config( prompt="Say this is a test", ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-3 @@ -163,7 +163,7 @@ async def test_method_single_provider_with_vk_retry_cache( prompt="Say this is a test" ) - assert type(cached_completion.choices[0].text) is str + assert isinstance(cached_completion.choices[0].text, str) is True # -------------------------- # Test-4 @@ -188,7 +188,7 @@ async def test_method_loadbalance_with_two_apikeys( prompt="Say this is a test", max_tokens=245 ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-5 @@ -212,7 +212,7 @@ async def test_method_loadbalance_and_fallback( prompt="Say this is just a loadbalance and fallback test test" ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-6 @@ -234,7 +234,7 @@ async def test_method_single_provider(self, client: Any, config: Dict) -> None: prompt="Say this is a test", ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True class TestChatCompletionsStreaming: diff --git a/tests/test_async_images.py b/tests/test_async_images.py index 3f89da42..a374ded1 100644 --- a/tests/test_async_images.py +++ b/tests/test_async_images.py @@ -70,7 +70,7 @@ async def test_method_single_with_vk_and_provider( model=model, prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(generation.data[0].url) is str + assert isinstance(generation.data[0].url, str) is True # -------------------------- # Test -2 @@ -95,7 +95,7 @@ async def test_method_single_with_basic_config( model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(generation.data[0].url) is str + assert isinstance(generation.data[0].url, str) is True # -------------------------- # Test-3 @@ -141,7 +141,7 @@ async def test_method_single_provider_with_vk_retry_cache( model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(cached_generation.data[0].url) is str + assert isinstance(cached_generation.data[0].url, str) is True # -------------------------- # Test-4 @@ -170,7 +170,7 @@ async def test_method_loadbalance_with_two_apikeys( response_format="b64_json", ) - assert type(image.data[0].b64_json) is str + assert isinstance(image.data[0].b64_json, str) is True # -------------------------- # Test-5 @@ -198,7 +198,7 @@ async def test_method_loadbalance_and_fallback( response_format="b64_json", ) - assert type(image.data[0].b64_json) is str + assert isinstance(image.data[0].b64_json, str) is True # -------------------------- # Test-6 @@ -220,7 +220,7 @@ async def test_method_single_provider(self, client: Any, config: Dict) -> None: model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(image.data[0].url) is str + assert isinstance(image.data[0].url, str) is True # -------------------------- # Test-7 @@ -249,4 +249,4 @@ async def test_method_all_params(self, client: Any, config: Dict) -> None: user="user-1234", ) - assert type(image.data[0].url) is str + assert isinstance(image.data[0].url, str) is True diff --git a/tests/test_chat_complete.py b/tests/test_chat_complete.py index e7d309cf..c65e4ba5 100644 --- a/tests/test_chat_complete.py +++ b/tests/test_chat_complete.py @@ -69,7 +69,7 @@ def test_method_single_with_vk_and_provider( max_tokens=245, ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test -2 @@ -116,7 +116,7 @@ def test_method_single_with_basic_config(self, client: Any, config: Dict) -> Non model="gpt-3.5-turbo", ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-3 @@ -162,7 +162,7 @@ def test_method_single_provider_with_vk_retry_cache( model="gpt-3.5-turbo", ) - assert type(cached_completion.choices[0].message.content) is str + assert isinstance(cached_completion.choices[0].message.content, str) is True # -------------------------- # Test-4 @@ -186,7 +186,7 @@ def test_method_loadbalance_with_two_apikeys( messages=[{"role": "user", "content": "Say this is a test"}], max_tokens=245 ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-5 @@ -212,7 +212,7 @@ def test_method_loadbalance_and_fallback(self, client: Any, config: Dict) -> Non ], ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True # -------------------------- # Test-6 @@ -234,7 +234,7 @@ def test_method_single_provider(self, client: Any, config: Dict) -> None: model="gpt-3.5-turbo", ) - assert type(completion.choices[0].message.content) is str + assert isinstance(completion.choices[0].message.content, str) is True class TestChatCompletionsStreaming: diff --git a/tests/test_complete.py b/tests/test_complete.py index a4c13726..2e996ada 100644 --- a/tests/test_complete.py +++ b/tests/test_complete.py @@ -69,7 +69,7 @@ def test_method_single_with_vk_and_provider( max_tokens=245, ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test -2 @@ -114,7 +114,7 @@ def test_method_single_with_basic_config(self, client: Any, config: Dict) -> Non prompt="Say this is a test", ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-3 @@ -155,7 +155,7 @@ def test_method_single_provider_with_vk_retry_cache( ) cached_completion = portkey_2.completions.create(prompt="Say this is a test") - assert type(cached_completion.choices[0].text) is str + assert isinstance(cached_completion.choices[0].text, str) is True # -------------------------- # Test-4 @@ -178,7 +178,7 @@ def test_method_loadbalance_with_two_apikeys( completion = portkey.completions.create( prompt="Say this is a test", max_tokens=245 ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-5 @@ -199,7 +199,7 @@ def test_method_loadbalance_and_fallback(self, client: Any, config: Dict) -> Non prompt="Say this is just a loadbalance and fallback test test" ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True # -------------------------- # Test-6 @@ -220,7 +220,7 @@ def test_method_single_provider(self, client: Any, config: Dict) -> None: prompt="Say this is a test", ) - assert type(completion.choices[0].text) is str + assert isinstance(completion.choices[0].text, str) is True class TestChatCompletionsStreaming: diff --git a/tests/test_images.py b/tests/test_images.py index 4663966e..da7ad42b 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -70,7 +70,7 @@ def test_method_single_with_vk_and_provider( model=model, prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(generation.data[0].url) is str + assert isinstance(generation.data[0].url, str) is True # -------------------------- # Test -2 @@ -92,7 +92,7 @@ def test_method_single_with_basic_config(self, client: Any, config: Dict) -> Non model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(generation.data[0].url) is str + assert isinstance(generation.data[0].url, str) is True # -------------------------- # Test-3 @@ -136,7 +136,7 @@ def test_method_single_provider_with_vk_retry_cache( model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(cached_generation.data[0].url) is str + assert isinstance(cached_generation.data[0].url, str) is True # -------------------------- # Test-4 @@ -163,7 +163,7 @@ def test_method_loadbalance_with_two_apikeys( response_format="b64_json", ) - assert type(image.data[0].b64_json) is str + assert isinstance(image.data[0].b64_json, str) is True # -------------------------- # Test-5 @@ -187,7 +187,7 @@ def test_method_loadbalance_and_fallback(self, client: Any, config: Dict) -> Non response_format="b64_json", ) - assert type(image.data[0].b64_json) is str + assert isinstance(image.data[0].b64_json, str) is True # -------------------------- # Test-6 @@ -208,7 +208,7 @@ def test_method_single_provider(self, client: Any, config: Dict) -> None: model="dall-e-3", prompt="A cute baby sea otter", n=1, size="1024x1024" ) - assert type(image.data[0].url) is str + assert isinstance(image.data[0].url, str) is True # -------------------------- # Test-7 @@ -236,4 +236,4 @@ def test_method_all_params(self, client: Any, config: Dict) -> None: user="user-1234", ) - assert type(image.data[0].url) is str + assert isinstance(image.data[0].url, str) is True diff --git a/tests/test_threads.py b/tests/test_threads.py index 9a7bb70f..9fcf6365 100644 --- a/tests/test_threads.py +++ b/tests/test_threads.py @@ -56,14 +56,14 @@ def test_method_single_with_vk_and_provider( ) thread = portkey.beta.threads.create() - assert type(thread.id) is str + assert isinstance(thread.id, str) is True assert thread.object == "thread" retrieve_thread = portkey.beta.threads.retrieve(thread.id) assert retrieve_thread.id == thread.id assert retrieve_thread.object == "thread" - assert type(retrieve_thread.metadata) is dict + assert isinstance(retrieve_thread.metadata, dict) is True update_thread = portkey.beta.threads.update( thread.id, @@ -74,7 +74,7 @@ def test_method_single_with_vk_and_provider( assert update_thread.id == thread.id assert update_thread.object == "thread" - assert type(update_thread.metadata) is dict + assert isinstance(update_thread.metadata, dict) is True assert update_thread.metadata["modified"] == "true" delete_thread = portkey.beta.threads.delete(thread.id) diff --git a/tests/utils.py b/tests/utils.py index 60175eba..7b20a081 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,11 +8,11 @@ def read_json_file(path: str) -> Dict[str, Any]: def check_chat_streaming_chunk(chunk) -> bool: stop_reason = chunk.choices[0].finish_reason - if type(stop_reason) is str: + if isinstance(stop_reason, str) is True: return chunk.choices[0].delta.content == "" else: - return type(chunk.choices[0].delta.content) is str + return isinstance(chunk.choices[0].delta.content, str) def check_text_streaming_chunk(chunk) -> bool: - return type(chunk.choices[0].text) is str + return isinstance(chunk.choices[0].text, str) From cbe91e6333cd943b248b397b674e610394dd5bf2 Mon Sep 17 00:00:00 2001 From: visargD Date: Thu, 21 Mar 2024 19:24:40 +0530 Subject: [PATCH 12/14] chore: minor cleaning --- tests/test_assistants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_assistants.py b/tests/test_assistants.py index 10c47f46..5622be49 100644 --- a/tests/test_assistants.py +++ b/tests/test_assistants.py @@ -120,7 +120,7 @@ def test_method_all_params(self, client: Any, virtual_key: str) -> None: tools=[{"type": "code_interpreter"}], ) - assert isinstance(assistant.id, str) + assert isinstance(assistant.id, str) is True assert assistant.object == "assistant" assert assistant.model == model assert assistant.name == "Math Tutor" From 1c57bc5155598651e71e3ba62268229cd54b8ea7 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Fri, 22 Mar 2024 11:38:28 +0530 Subject: [PATCH 13/14] hotfix: openAI as dependency --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 896df0b4..50bb811f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,6 +24,7 @@ install_requires = black==23.7.0 typing_extensions>=4.7.1,<5.0 pydantic>=1.10.12 + openai>=1.0,<2.0 [options.entry_points] console_scripts = From 802e5001e0ca665d68e94a15aa3ba8457c74d9fa Mon Sep 17 00:00:00 2001 From: visargD Date: Fri, 22 Mar 2024 11:46:54 +0530 Subject: [PATCH 14/14] feat: release 1.2.1 --- portkey_ai/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portkey_ai/version.py b/portkey_ai/version.py index 848258f9..3a0b6cbf 100644 --- a/portkey_ai/version.py +++ b/portkey_ai/version.py @@ -1 +1 @@ -VERSION = "1.2.0" +VERSION = "1.2.1"