From ae25c5695f934e9c40fa5c5a80ae7bd6d18895d5 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 2 Sep 2024 11:58:15 -0700 Subject: [PATCH] add streaming test for ai21 --- litellm/tests/test_completion.py | 1 + litellm/tests/test_streaming.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index 7aff45ff6be..b010bd6025d 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -4477,6 +4477,7 @@ async def test_dynamic_azure_params(stream, sync_mode): @pytest.mark.asyncio() +@pytest.mark.flaky(retries=3, delay=1) async def test_completion_ai21(): litellm.set_verbose = True response = await litellm.acompletion( diff --git a/litellm/tests/test_streaming.py b/litellm/tests/test_streaming.py index 1b8b4e08527..1b155bea850 100644 --- a/litellm/tests/test_streaming.py +++ b/litellm/tests/test_streaming.py @@ -586,6 +586,37 @@ async def test_completion_predibase_streaming(sync_mode): pytest.fail(f"Error occurred: {e}") +@pytest.mark.asyncio() +@pytest.mark.flaky(retries=3, delay=1) +async def test_completion_ai21_stream(): + litellm.set_verbose = True + response = await litellm.acompletion( + model="ai21_chat/jamba-1.5-large", + user="ishaan", + stream=True, + seed=123, + messages=[{"role": "user", "content": "hi my name is ishaan"}], + ) + complete_response = "" + idx = 0 + async for init_chunk in response: + chunk, finished = streaming_format_tests(idx, init_chunk) + complete_response += chunk + custom_llm_provider = init_chunk._hidden_params["custom_llm_provider"] + print(f"custom_llm_provider: {custom_llm_provider}") + assert custom_llm_provider == "ai21_chat" + idx += 1 + if finished: + assert isinstance(init_chunk.choices[0], litellm.utils.StreamingChoices) + break + if complete_response.strip() == "": + raise Exception("Empty response received") + + print(f"complete_response: {complete_response}") + + pass + + def test_completion_azure_function_calling_stream(): try: litellm.set_verbose = False