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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(together_ai): move request-shape checks to the mapped file, drop the live ones
Yuneng Jiang8c046e13bdcb
diff --git a/tests/local_testing/test_completion.py b/tests/local_testing/test_completion.pyindex a6ac112a3b7..25c6c50251d 100644--- a/tests/local_testing/test_completion.py+++ b/tests/local_testing/test_completion.py@@ -11,7 +11,6 @@ import iofrom unittest.mock import AsyncMock, MagicMock, patch-import httpximport pytestimport litellm@@ -58,51 +57,6 @@ def test_response_model_none():assert isinstance(x, litellm.ModelResponse)-TOGETHER_AI_CHAT_URL = "https://api.together.ai/v1/chat/completions"---def _together_ai_chat_response(content="Hello!"):- return httpx.Response(- 200,- json={- "id": "chatcmpl-together",- "object": "chat.completion",- "created": 1,- "model": "openai/gpt-oss-20b",- "choices": [- {- "index": 0,- "message": {"role": "assistant", "content": content},- "finish_reason": "stop",- }- ],- "usage": {- "prompt_tokens": 1,- "completion_tokens": 1,- "total_tokens": 2,- },- },- request=httpx.Request("POST", TOGETHER_AI_CHAT_URL),- )---def test_completion_custom_provider_model_name():- litellm.cache = None- with patch.object(- HTTPHandler, "post", return_value=_together_ai_chat_response()- ) as mock_post:- response = completion(- model="together_ai/openai/gpt-oss-20b",- messages=messages,- logger_fn=logger_fn,- api_key="fake-key",- )-- assert mock_post.call_args.kwargs["url"] == TOGETHER_AI_CHAT_URL- assert json.loads(mock_post.call_args.kwargs["data"])["model"] == "openai/gpt-oss-20b"- assert response.choices[0].finish_reason == "stop"--def _openai_mock_response(*args, **kwargs) -> litellm.ModelResponse:new_response = MagicMock()new_response.headers = {"hello": "world"}@@ -2832,40 +2786,6 @@ def test_completion_together_ai_llama():# test_completion_together_ai()-def test_customprompt_together_ai():- litellm.set_verbose = False- litellm.num_retries = 0- with patch.object(- HTTPHandler, "post", return_value=_together_ai_chat_response()- ) as mock_post:- response = completion(- model="together_ai/openai/gpt-oss-20b",- messages=messages,- roles={- "system": {- "pre_message": "<|im_start|>system\n",- "post_message": "<|im_end|>",- },- "assistant": {- "pre_message": "<|im_start|>assistant\n",- "post_message": "<|im_end|>",- },- "user": {- "pre_message": "<|im_start|>user\n",- "post_message": "<|im_end|>",- },- },- api_key="fake-key",- )-- body = json.loads(mock_post.call_args.kwargs["data"])- assert body["messages"] == messages- assert "prompt" not in body- assert "roles" not in body- assert response.choices[0].finish_reason == "stop"---# test_customprompt_together_ai()def response_format_tests(response: litellm.ModelResponse):@@ -3672,51 +3592,6 @@ async def test_acompletion_stream_watsonx():# test_maritalk()-def test_completion_together_ai_stream():- litellm.set_verbose = True- user_message = "Write 1pg about YC & litellm"- messages = [{"content": user_message, "role": "user"}]- sse_body = (- 'data: {"id":"chatcmpl-together","object":"chat.completion.chunk","created":1,'- '"model":"openai/gpt-oss-20b","choices":[{"index":0,"delta":{"role":"assistant",'- '"content":"YC"},"finish_reason":null}]}\n\n'- 'data: {"id":"chatcmpl-together","object":"chat.completion.chunk","created":1,'- '"model":"openai/gpt-oss-20b","choices":[{"index":0,"delta":{"content":" and '- 'litellm"},"finish_reason":null}]}\n\n'- 'data: {"id":"chatcmpl-together","object":"chat.completion.chunk","created":1,'- '"model":"openai/gpt-oss-20b","choices":[{"index":0,"delta":{},'- '"finish_reason":"stop"}]}\n\n'- "data: [DONE]\n\n"- )- stream_response = httpx.Response(- 200,- content=sse_body.encode(),- headers={"content-type": "text/event-stream"},- request=httpx.Request("POST", TOGETHER_AI_CHAT_URL),- )-- with patch.object(- HTTPHandler, "post", return_value=stream_response- ) as mock_post:- response = completion(- model="together_ai/openai/gpt-oss-20b",- messages=messages,- stream=True,- max_tokens=5,- api_key="fake-key",- )- chunks = list(response)-- assert json.loads(mock_post.call_args.kwargs["data"])["stream"] is True- assert "".join(- chunk.choices[0].delta.content or "" for chunk in chunks- ) == "YC and litellm"- assert chunks[-1].choices[0].finish_reason == "stop"---# test_completion_together_ai_stream()--def test_moderation():response = litellm.moderation(input="i'm ishaan cto of litellm")print(response)diff --git a/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py b/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.pyindex 7eb7dc41d4f..a7347edb2c7 100644--- a/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py+++ b/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py@@ -1108,3 +1108,67 @@ def test_get_optional_params_preserves_max_for_declared_levels_model():)assert optional_params["reasoning_effort"] == "max"+++def _together_chat_transport() -> tuple[HTTPHandler, list[httpx.Request]]:+ captured_requests: list[httpx.Request] = []++ def respond(request: httpx.Request) -> httpx.Response:+ captured_requests.append(request)+ return httpx.Response(+ 200,+ json={+ "id": "chatcmpl-together",+ "object": "chat.completion",+ "created": 1234567890,+ "model": TOOL_CALLING_MODEL,+ "choices": [+ {+ "index": 0,+ "message": {"role": "assistant", "content": "Hello!"},+ "finish_reason": "stop",+ }+ ],+ "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15},+ },+ )++ client = HTTPHandler(client=httpx.Client(transport=httpx.MockTransport(respond)))+ return client, captured_requests+++def test_only_the_provider_prefix_is_stripped_from_a_slashed_model_name():+ client, captured_requests = _together_chat_transport()++ litellm.completion(+ model=f"together_ai/{TOOL_CALLING_MODEL}",+ messages=[{"role": "user", "content": "Hello!"}],+ api_key="fake-key",+ client=client,+ )++ assert "/" in TOOL_CALLING_MODEL+ assert str(captured_requests[0].url) == "https://api.together.ai/v1/chat/completions"+ assert json.loads(captured_requests[0].content)["model"] == TOOL_CALLING_MODEL+++def test_custom_role_wrappers_never_reach_the_request():+ client, captured_requests = _together_chat_transport()+ messages = [{"role": "user", "content": "Hello!"}]++ litellm.completion(+ model=f"together_ai/{TOOL_CALLING_MODEL}",+ messages=messages,+ roles={+ "system": {"pre_message": "<|im_start|>system\n", "post_message": "<|im_end|>"},+ "assistant": {"pre_message": "<|im_start|>assistant\n", "post_message": "<|im_end|>"},+ "user": {"pre_message": "<|im_start|>user\n", "post_message": "<|im_end|>"},+ },+ api_key="fake-key",+ client=client,+ )++ request_body = json.loads(captured_requests[0].content)+ assert request_body["messages"] == messages+ assert "prompt" not in request_body+ assert "roles" not in request_body