Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions responses_api_models/vllm_model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ def _resolve_audio_path_to_url(self, audio_path: str) -> str:
encoded = base64.b64encode(f.read()).decode("ascii")
return f"data:audio/{mime};base64,{encoded}"

@staticmethod
def _strip_hosted_only_tool_fields(body_dict: Dict[str, Any]) -> None:
"""Remove OpenAI-hosted-only fields from function tool definitions.

``strict`` is an OpenAI-hosted schema-enforcement flag that vLLM does
not implement: its FunctionDefinition keeps the unknown key, and chat
templates that render unknown function-definition keys (e.g.
Nemotron's ``render_extra_keys``) inject it into the prompt,
perturbing every tool-bearing request. Strip it at the vLLM boundary
so hosted providers keep their ``strict`` semantics.
"""
for tool_dict in body_dict.get("tools") or []:
if tool_dict.get("type") == "function":
(tool_dict.get("function") or {}).pop("strict", None)

def _preprocess_chat_completion_create_params(self, request: Request, body_dict: Dict[str, Any]) -> Dict[str, Any]:
"""Preprocess the body dict before issuing a chat completion request.

Expand All @@ -483,6 +498,8 @@ def _preprocess_chat_completion_create_params(self, request: Request, body_dict:
The (possibly mutated) ``body_dict`` that will be forwarded to
``client.create_chat_completion``.
"""
self._strip_hosted_only_tool_fields(body_dict)

if self.config.replace_developer_role_with_system:
for message_dict in body_dict["messages"]:
if message_dict.get("role") == "developer":
Expand Down Expand Up @@ -1087,6 +1104,10 @@ async def _chat_completions_via_completions_api(
modes — /v1/completions is text-only.
"""
body_dict = body.model_dump(exclude_unset=True)
# This path never runs _preprocess_chat_completion_create_params, and
# _render_messages_via_chat_template hands tools to apply_chat_template,
# so hosted-only fields must be stripped here too.
self._strip_hosted_only_tool_fields(body_dict)
messages = body_dict.get("messages", []) or []
metadata = body_dict.get("metadata", {}) or {}

Expand Down
19 changes: 16 additions & 3 deletions responses_api_models/vllm_model/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ def lineage_index():
return _TEST_LINEAGE.index


def test_strip_hosted_only_tool_fields_pops_strict() -> None:
body_dict = {
"tools": [
{"type": "function", "function": {"name": "get_weather", "strict": True}},
{"type": "custom", "custom": {"name": "not_a_function"}},
]
}
VLLMModel._strip_hosted_only_tool_fields(body_dict)
assert "strict" not in body_dict["tools"][0]["function"]
assert body_dict["tools"][0]["function"]["name"] == "get_weather"
assert body_dict["tools"][1] == {"type": "custom", "custom": {"name": "not_a_function"}}

# Tolerates absent tools.
VLLMModel._strip_hosted_only_tool_fields({})


def test_transport_io_writer_keeps_full_payload(monkeypatch: MonkeyPatch, tmp_path) -> None:
log_path = tmp_path / "model-io-transport.jsonl"
monkeypatch.setenv("NEMO_GYM_VLLM_TRANSPORT_LOG", str(log_path))
Expand Down Expand Up @@ -965,7 +981,6 @@ def _standardize(messages: list) -> list:
"required": ["order_id"],
},
"description": "Get the current status for a given order",
Comment thread
pthombre marked this conversation as resolved.
Resolved
"strict": True,
},
{
"name": "get_delivery_date",
Expand All @@ -980,7 +995,6 @@ def _standardize(messages: list) -> list:
"required": ["order_id"],
},
"description": "Get the estimated delivery date for a given order",
"strict": True,
},
]
assert expected_sent_tools == actual_sent_tools
Expand Down Expand Up @@ -1437,7 +1451,6 @@ def test_responses_multistep_multiturn(self, monkeypatch: MonkeyPatch):
},
"required": ["order_id", "date"],
},
"strict": True,
}
]
assert expected_sent_tools == actual_sent_tools
Expand Down
Loading