Skip to content

Commit f7ffb8e

Browse files
Nan2018xuebwang-amd
authored andcommitted
fix: response_format for completion (vllm-project#23212)
Signed-off-by: Nan2018 <qinnanjoshua@gmail.com> Signed-off-by: xuebwang-amd <xuebwang@amd.com>
1 parent 321d80f commit f7ffb8e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

vllm/entrypoints/openai/protocol.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,10 @@ class CompletionRequest(OpenAIBaseModel):
11971197
"Please pass `grammar` to `structured_outputs` instead."
11981198
),
11991199
)
1200+
structural_tag: str | None = Field(
1201+
default=None,
1202+
description=("If specified, the output will follow the structural tag schema."),
1203+
)
12001204
guided_decoding_backend: str | None = Field(
12011205
default=None,
12021206
description=(
@@ -1357,10 +1361,27 @@ def to_sampling_params(
13571361

13581362
echo_without_generation = self.echo and self.max_tokens == 0
13591363

1364+
guided_json_object = None
1365+
if self.response_format is not None:
1366+
if self.response_format.type == "json_object":
1367+
guided_json_object = True
1368+
elif self.response_format.type == "json_schema":
1369+
json_schema = self.response_format.json_schema
1370+
assert json_schema is not None
1371+
self.guided_json = json_schema.json_schema
1372+
elif self.response_format.type == "structural_tag":
1373+
structural_tag = self.response_format
1374+
assert structural_tag is not None and isinstance(
1375+
structural_tag, StructuralTagResponseFormat
1376+
)
1377+
s_tag_obj = structural_tag.model_dump(by_alias=True)
1378+
self.structural_tag = json.dumps(s_tag_obj)
1379+
13601380
# Forward deprecated guided_* parameters to structured_outputs
13611381
if self.structured_outputs is None:
13621382
kwargs = dict[str, Any](
13631383
json=self.guided_json,
1384+
json_object=guided_json_object,
13641385
regex=self.guided_regex,
13651386
choice=self.guided_choice,
13661387
grammar=self.guided_grammar,
@@ -1370,13 +1391,6 @@ def to_sampling_params(
13701391
if len(kwargs) > 0:
13711392
self.structured_outputs = StructuredOutputsParams(**kwargs)
13721393

1373-
if (
1374-
self.structured_outputs is not None
1375-
and self.response_format is not None
1376-
and self.response_format.type == "json_object"
1377-
):
1378-
self.structured_outputs.json_object = True
1379-
13801394
extra_args: dict[str, Any] = self.vllm_xargs if self.vllm_xargs else {}
13811395
if self.kv_transfer_params:
13821396
# Pass in kv_transfer_params via extra_args

0 commit comments

Comments
 (0)