Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

add streaming test for ai21

Ishaan Jaffae25c5695f93
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()
[email protected](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}")
[email protected](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