mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
test(together_ai): move request-shape checks to the mapped file, drop the live ones
Together moved openai/gpt-oss-20b off serverless and three tests in test_completion.py died on a live 400. None of them needed Together to be up: streaming is already covered live by tests/e2e/llm_translation/test_together_ai_e2e.py, which picks its model from the cost map instead of pinning one, and the other two are request-shape questions. Delete all three and assert the two shapes in the mapped transformation file: the provider prefix is stripped without eating the rest of a slashed model name, and custom role wrappers never reach the request.
This commit is contained in:
parent
1aa2e19ee4
commit
8c046e13bd
2 changed files with 64 additions and 125 deletions
|
|
@ -11,7 +11,6 @@ import io
|
|||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
import 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue