Unverified Commit 9d696492 authored by Nan Qin's avatar Nan Qin Committed by GitHub
Browse files

fix: response_format for completion (#23212)


Signed-off-by: default avatarNan2018 <qinnanjoshua@gmail.com>
parent 0e658189
...@@ -1197,6 +1197,10 @@ class CompletionRequest(OpenAIBaseModel): ...@@ -1197,6 +1197,10 @@ class CompletionRequest(OpenAIBaseModel):
"Please pass `grammar` to `structured_outputs` instead." "Please pass `grammar` to `structured_outputs` instead."
), ),
) )
structural_tag: str | None = Field(
default=None,
description=("If specified, the output will follow the structural tag schema."),
)
guided_decoding_backend: str | None = Field( guided_decoding_backend: str | None = Field(
default=None, default=None,
description=( description=(
...@@ -1357,10 +1361,27 @@ class CompletionRequest(OpenAIBaseModel): ...@@ -1357,10 +1361,27 @@ class CompletionRequest(OpenAIBaseModel):
echo_without_generation = self.echo and self.max_tokens == 0 echo_without_generation = self.echo and self.max_tokens == 0
guided_json_object = None
if self.response_format is not None:
if self.response_format.type == "json_object":
guided_json_object = True
elif self.response_format.type == "json_schema":
json_schema = self.response_format.json_schema
assert json_schema is not None
self.guided_json = json_schema.json_schema
elif self.response_format.type == "structural_tag":
structural_tag = self.response_format
assert structural_tag is not None and isinstance(
structural_tag, StructuralTagResponseFormat
)
s_tag_obj = structural_tag.model_dump(by_alias=True)
self.structural_tag = json.dumps(s_tag_obj)
# Forward deprecated guided_* parameters to structured_outputs # Forward deprecated guided_* parameters to structured_outputs
if self.structured_outputs is None: if self.structured_outputs is None:
kwargs = dict[str, Any]( kwargs = dict[str, Any](
json=self.guided_json, json=self.guided_json,
json_object=guided_json_object,
regex=self.guided_regex, regex=self.guided_regex,
choice=self.guided_choice, choice=self.guided_choice,
grammar=self.guided_grammar, grammar=self.guided_grammar,
...@@ -1370,13 +1391,6 @@ class CompletionRequest(OpenAIBaseModel): ...@@ -1370,13 +1391,6 @@ class CompletionRequest(OpenAIBaseModel):
if len(kwargs) > 0: if len(kwargs) > 0:
self.structured_outputs = StructuredOutputsParams(**kwargs) self.structured_outputs = StructuredOutputsParams(**kwargs)
if (
self.structured_outputs is not None
and self.response_format is not None
and self.response_format.type == "json_object"
):
self.structured_outputs.json_object = True
extra_args: dict[str, Any] = self.vllm_xargs if self.vllm_xargs else {} extra_args: dict[str, Any] = self.vllm_xargs if self.vllm_xargs else {}
if self.kv_transfer_params: if self.kv_transfer_params:
# Pass in kv_transfer_params via extra_args # Pass in kv_transfer_params via extra_args
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment