mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
151 lines
5.8 KiB
Python
151 lines
5.8 KiB
Python
from base_llm_unit_tests import BaseLLMChatTest
|
|
import json
|
|
import pytest
|
|
from unittest.mock import patch, Mock, MagicMock
|
|
|
|
import litellm
|
|
from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig
|
|
from litellm.llms.custom_httpx.http_handler import HTTPHandler
|
|
|
|
|
|
class TestBedrockGPTOSS(BaseLLMChatTest):
|
|
def get_base_completion_call_args(self) -> dict:
|
|
return {
|
|
"model": "bedrock/converse/openai.gpt-oss-20b-1:0",
|
|
}
|
|
|
|
def test_tool_call_no_arguments(self, tool_call_no_arguments):
|
|
"""Test that tool calls with no arguments is translated correctly. Relevant issue: https://github.com/BerriAI/litellm/issues/6833"""
|
|
pass
|
|
|
|
def test_function_calling_with_tool_response(self):
|
|
"""Bedrock GPT-OSS intermittently emits truncated toolUse.input deltas on
|
|
the live endpoint, which makes the inherited live integration test flaky.
|
|
The accumulation side is covered deterministically by
|
|
tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py::test_transform_tool_calls_index;
|
|
the GPT-OSS-specific request-body transformation is covered by
|
|
test_function_calling_request_body_gpt_oss below.
|
|
"""
|
|
pass
|
|
|
|
def test_function_calling_request_body_gpt_oss(self):
|
|
"""Verify the Bedrock Converse request body is well-formed for GPT-OSS when the
|
|
caller supplies a tool schema with OpenAI-style metadata ($id, $schema,
|
|
additionalProperties, strict). Bedrock only accepts a trimmed JSON Schema in
|
|
toolSpec.inputSchema.json, so the extra fields must be stripped and the
|
|
required shape preserved.
|
|
"""
|
|
client = HTTPHandler()
|
|
|
|
tools = [
|
|
{
|
|
"type": "function",
|
|
"function": {
|
|
"name": "get_weather",
|
|
"description": "Get the weather in a city",
|
|
"parameters": {
|
|
"$id": "https://some/internal/name",
|
|
"$schema": "https://json-schema.org/draft-07/schema",
|
|
"type": "object",
|
|
"properties": {
|
|
"city": {
|
|
"type": "string",
|
|
"description": "The city to get the weather for",
|
|
}
|
|
},
|
|
"required": ["city"],
|
|
"additionalProperties": False,
|
|
},
|
|
"strict": True,
|
|
},
|
|
}
|
|
]
|
|
|
|
with patch.object(client, "post", new=Mock()) as mock_post:
|
|
try:
|
|
litellm.completion(
|
|
model="bedrock/converse/openai.gpt-oss-20b-1:0",
|
|
messages=[
|
|
{"role": "user", "content": "How is the weather in Mumbai?"}
|
|
],
|
|
tools=tools,
|
|
aws_region_name="us-west-2",
|
|
client=client,
|
|
)
|
|
except Exception:
|
|
# We only care about the outgoing request; the mocked post returns
|
|
# a Mock that can't be parsed as a real Converse response.
|
|
pass
|
|
|
|
mock_post.assert_called_once()
|
|
call_kwargs = mock_post.call_args.kwargs
|
|
|
|
assert call_kwargs["url"].endswith(
|
|
"/model/openai.gpt-oss-20b-1%3A0/converse"
|
|
), call_kwargs["url"]
|
|
|
|
request_body = json.loads(call_kwargs["data"])
|
|
|
|
assert "toolConfig" in request_body
|
|
tool_specs = request_body["toolConfig"]["tools"]
|
|
assert len(tool_specs) == 1
|
|
tool_spec = tool_specs[0]["toolSpec"]
|
|
assert tool_spec["name"] == "get_weather"
|
|
assert tool_spec["description"] == "Get the weather in a city"
|
|
|
|
input_schema = tool_spec["inputSchema"]["json"]
|
|
assert input_schema["type"] == "object"
|
|
assert input_schema["required"] == ["city"]
|
|
assert input_schema["properties"]["city"]["type"] == "string"
|
|
|
|
# Bedrock's toolSpec.inputSchema.json only accepts type/properties/required;
|
|
# the OpenAI-style metadata must not leak through.
|
|
for stripped_field in ("$id", "$schema", "additionalProperties", "strict"):
|
|
assert (
|
|
stripped_field not in input_schema
|
|
), f"{stripped_field} should be stripped before hitting Bedrock"
|
|
|
|
assert request_body["messages"][0]["role"] == "user"
|
|
assert (
|
|
request_body["messages"][0]["content"][0]["text"]
|
|
== "How is the weather in Mumbai?"
|
|
)
|
|
|
|
def test_prompt_caching(self):
|
|
"""
|
|
Remove override once we have access to Bedrock prompt caching
|
|
"""
|
|
pass
|
|
|
|
async def test_completion_cost(self):
|
|
"""
|
|
Bedrock GPT-OSS models are flaky and occasionally report 0 token counts in api response
|
|
"""
|
|
pass
|
|
|
|
@pytest.mark.parametrize(
|
|
"model",
|
|
[
|
|
"bedrock/openai.gpt-oss-20b-1:0",
|
|
"bedrock/openai.gpt-oss-120b-1:0",
|
|
],
|
|
)
|
|
def test_reasoning_effort_transformation_gpt_oss(self, model):
|
|
"""Test that reasoning_effort is handled correctly for GPT-OSS models."""
|
|
config = AmazonConverseConfig()
|
|
|
|
# Test GPT-OSS model - should keep reasoning_effort as-is
|
|
non_default_params = {"reasoning_effort": "low"}
|
|
optional_params = {}
|
|
|
|
result = config.map_openai_params(
|
|
non_default_params=non_default_params,
|
|
optional_params=optional_params,
|
|
model=model,
|
|
drop_params=False,
|
|
)
|
|
|
|
# GPT-OSS should have reasoning_effort in result, not thinking
|
|
assert "reasoning_effort" in result
|
|
assert result["reasoning_effort"] == "low"
|
|
assert "thinking" not in result
|