[Frontend] Add the Beam reasoning and tool parsers (#62052)
Signed-off-by: Woosuk Kwon <woosuk@inferact.ai> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com> Co-authored-by: neilkg <33635204+neilkg@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Bugen Zhao
Yoni Gozlan
neilkg
Cursor
Claude Opus 5.5
parent
9731f30a03
commit
153a17166e
@@ -53,6 +53,7 @@ from openai_harmony import Message as OpenAIHarmonyMessage
|
||||
from pydantic import (
|
||||
BeforeValidator,
|
||||
Field,
|
||||
PrivateAttr,
|
||||
ValidationError,
|
||||
field_serializer,
|
||||
model_validator,
|
||||
@@ -469,6 +470,14 @@ class ResponsesRequest(OpenAIBaseModel):
|
||||
max_output_tokens_param="max_output_tokens",
|
||||
)
|
||||
|
||||
_grammar_from_parser: bool = PrivateAttr(default=False)
|
||||
"""CAUTION: Should only be set by the parser's adjust_request."""
|
||||
|
||||
_parser_structured_outputs: StructuredOutputsParams | None = PrivateAttr(
|
||||
default=None
|
||||
)
|
||||
"""Parser-derived constraints that preserve the public request's text metadata."""
|
||||
|
||||
_DEFAULT_SAMPLING_PARAMS = {
|
||||
"temperature": 1.0,
|
||||
"top_p": 1.0,
|
||||
@@ -478,6 +487,8 @@ class ResponsesRequest(OpenAIBaseModel):
|
||||
|
||||
def extract_structured_outputs(self) -> StructuredOutputsParams | None:
|
||||
"""Normalize request constraints into ``StructuredOutputsParams``."""
|
||||
if self._parser_structured_outputs is not None:
|
||||
return self._parser_structured_outputs
|
||||
if self.text is None or self.text.format is None:
|
||||
return self.structured_outputs
|
||||
|
||||
|
||||
@@ -526,6 +526,7 @@ class OpenAIServingResponses(GenerateBaseServing):
|
||||
trace_headers=trace_headers,
|
||||
session_id=session_id,
|
||||
reasoning_parser_kwargs=reasoning_parser_kwargs,
|
||||
reasoning_ended=True if request._grammar_from_parser else None,
|
||||
)
|
||||
generators.append(generator)
|
||||
|
||||
@@ -647,6 +648,7 @@ class OpenAIServingResponses(GenerateBaseServing):
|
||||
trace_headers: Mapping[str, str] | None = None,
|
||||
session_id: str | None = None,
|
||||
reasoning_parser_kwargs: dict[str, Any] | None = None,
|
||||
reasoning_ended: bool | None = None,
|
||||
):
|
||||
max_model_len = self.model_config.max_model_len
|
||||
cache_salt = cast(str | None, engine_input.get("cache_salt"))
|
||||
@@ -673,6 +675,7 @@ class OpenAIServingResponses(GenerateBaseServing):
|
||||
priority=priority,
|
||||
session_id=session_id,
|
||||
reasoning_parser_kwargs=reasoning_parser_kwargs,
|
||||
reasoning_ended=reasoning_ended,
|
||||
)
|
||||
|
||||
async for res in generator:
|
||||
|
||||
Reference in New Issue
Block a user