Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ vision = [
"selenium",
]
vllm = [
"vllm",
"vllm>=0.10.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add some version control logic like the following

json_schema = response_format["json_schema"]["schema"]
if parse(vllm.__version__) >= parse("0.10.2"):
    from vllm.outputs import StructuredOutputsParams
    if response_format:
        structured_outputs = StructuredOutputsParams(json=json_schema)
else:
    if response_format:       
        guided_options_request = {"guided_json": json_schema}

But I think that adds unnecessary complexity. Might be simpler to just force the version to be >= 0.10.2

Copy link
Contributor Author

@suryabdev suryabdev Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with vLLM 0.10.0, With the new code it will break
image

"torch"
]
all = [
Expand Down
7 changes: 5 additions & 2 deletions src/smolagents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ def generate(
**kwargs,
) -> ChatMessage:
from vllm import SamplingParams # type: ignore
from vllm.sampling_params import StructuredOutputsParams # type: ignore

completion_kwargs = self._prepare_completion_kwargs(
messages=messages,
Expand All @@ -639,7 +640,9 @@ def generate(
**kwargs,
)
# Override the OpenAI schema for VLLM compatibility
guided_options_request = {"guided_json": response_format["json_schema"]["schema"]} if response_format else None
structured_outputs = (
StructuredOutputsParams(json=response_format["json_schema"]["schema"]) if response_format else None
)

messages = completion_kwargs.pop("messages")
prepared_stop_sequences = completion_kwargs.pop("stop", [])
Expand All @@ -658,12 +661,12 @@ def generate(
temperature=kwargs.get("temperature", 0.0),
max_tokens=kwargs.get("max_tokens", 2048),
stop=prepared_stop_sequences,
structured_outputs=structured_outputs,
)

out = self.model.generate(
prompt,
sampling_params=sampling_params,
guided_options_request=guided_options_request,
**completion_kwargs,
)

Expand Down