mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
test(bedrock): use monkeypatch for modify_params and remove redundant docstring
This commit is contained in:
parent
8d514bbc3e
commit
c12b3087f5
1 changed files with 30 additions and 43 deletions
|
|
@ -6955,51 +6955,38 @@ def test_transform_response_honors_json_mode_kwarg_when_optional_params_lack_it(
|
|||
assert json.loads(result.choices[0].message.content) == {"city": "Paris", "population": 2100000}
|
||||
|
||||
|
||||
def test_transform_request_injects_dummy_tool_without_tools_param():
|
||||
"""
|
||||
Bedrock Converse rejects requests with tool turns when toolConfig is omitted.
|
||||
LiteLLM must inject a dummy tool without requiring litellm.modify_params.
|
||||
"""
|
||||
def test_transform_request_injects_dummy_tool_without_tools_param(monkeypatch):
|
||||
from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig
|
||||
|
||||
monkeypatch.setattr(litellm, "modify_params", False)
|
||||
config = AmazonConverseConfig()
|
||||
prev_modify_params = litellm.modify_params
|
||||
litellm.modify_params = False
|
||||
try:
|
||||
messages = [
|
||||
{"role": "user", "content": "Hello"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Calling tool",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "tooluse_test_dummy",
|
||||
"type": "function",
|
||||
"function": {"name": "get_x", "arguments": "{}"},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"tool_call_id": "tooluse_test_dummy",
|
||||
"content": "{}",
|
||||
},
|
||||
]
|
||||
result = config.transform_request(
|
||||
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||
messages=messages,
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
headers={},
|
||||
)
|
||||
finally:
|
||||
litellm.modify_params = prev_modify_params
|
||||
|
||||
assert "toolConfig" in result
|
||||
tools = result["toolConfig"].get("tools", [])
|
||||
tool_names = [
|
||||
t.get("toolSpec", {}).get("name")
|
||||
for t in tools
|
||||
if isinstance(t, dict) and "toolSpec" in t
|
||||
messages = [
|
||||
{"role": "user", "content": "Hello"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Calling tool",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "tooluse_test_dummy",
|
||||
"type": "function",
|
||||
"function": {"name": "get_x", "arguments": "{}"},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"tool_call_id": "tooluse_test_dummy",
|
||||
"content": "{}",
|
||||
},
|
||||
]
|
||||
assert "dummy_tool" in tool_names
|
||||
result = config.transform_request(
|
||||
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||
messages=messages,
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
headers={},
|
||||
)
|
||||
assert "toolConfig" in result
|
||||
assert "tools" in result["toolConfig"]
|
||||
assert result["toolConfig"]["tools"][0]["toolSpec"]["name"] == "dummy_tool"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue