[Refactor] Responses API parser state into conversation context (#46030)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
04c2a8deac
commit
3ce5823762
@@ -386,8 +386,15 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
|
|||||||
reasoning_parser="qwen3",
|
reasoning_parser="qwen3",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
request = ResponsesRequest(input="hi", tools=[], stream=False)
|
||||||
|
response_parser = serving._make_response_parser(
|
||||||
|
request,
|
||||||
|
tokenizer,
|
||||||
|
serving._effective_chat_template_kwargs(request),
|
||||||
|
)
|
||||||
|
|
||||||
# Build a SimpleContext with thinking tokens in the output.
|
# Build a SimpleContext with thinking tokens in the output.
|
||||||
context = SimpleContext()
|
context = SimpleContext(response_parser=response_parser)
|
||||||
token_ids = [1, 10, 2, 20] # <think> 10 </think> 20 -> reasoning token count = 1
|
token_ids = [1, 10, 2, 20] # <think> 10 </think> 20 -> reasoning token count = 1
|
||||||
completion = CompletionOutput(
|
completion = CompletionOutput(
|
||||||
index=0,
|
index=0,
|
||||||
@@ -412,7 +419,6 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
|
|||||||
async def dummy_result_generator():
|
async def dummy_result_generator():
|
||||||
yield None
|
yield None
|
||||||
|
|
||||||
request = ResponsesRequest(input="hi", tools=[], stream=False)
|
|
||||||
sampling_params = SamplingParams(max_tokens=16)
|
sampling_params = SamplingParams(max_tokens=16)
|
||||||
metadata = RequestResponseMetadata(request_id="req")
|
metadata = RequestResponseMetadata(request_id="req")
|
||||||
|
|
||||||
@@ -636,9 +642,9 @@ class TestHarmonyPreambleStreaming:
|
|||||||
assert "response.output_text.done" not in type_names
|
assert "response.output_text.done" not in type_names
|
||||||
|
|
||||||
|
|
||||||
def _make_simple_context_with_output(text, token_ids):
|
def _make_simple_context_with_output(text, token_ids, response_parser=None):
|
||||||
"""Create a SimpleContext with a RequestOutput containing the given text."""
|
"""Create a SimpleContext with a RequestOutput containing the given text."""
|
||||||
ctx = SimpleContext()
|
ctx = SimpleContext(response_parser=response_parser)
|
||||||
completion = CompletionOutput(
|
completion = CompletionOutput(
|
||||||
index=0,
|
index=0,
|
||||||
text=text,
|
text=text,
|
||||||
@@ -719,6 +725,7 @@ def _mock_parser_with_reasoning(serving, delta_sequence: list[DeltaMessage]):
|
|||||||
mock_parser_instance.parse_delta = mock_parse_delta
|
mock_parser_instance.parse_delta = mock_parse_delta
|
||||||
mock_parser_instance.is_reasoning_end = MagicMock(return_value=False)
|
mock_parser_instance.is_reasoning_end = MagicMock(return_value=False)
|
||||||
serving.parser = MagicMock(return_value=mock_parser_instance)
|
serving.parser = MagicMock(return_value=mock_parser_instance)
|
||||||
|
return mock_parser_instance
|
||||||
|
|
||||||
|
|
||||||
class TestStreamingReasoningToContentTransition:
|
class TestStreamingReasoningToContentTransition:
|
||||||
@@ -745,12 +752,12 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
DeltaMessage(reasoning=" end", content="hello"), # mixed delta
|
DeltaMessage(reasoning=" end", content="hello"), # mixed delta
|
||||||
DeltaMessage(content=" world"),
|
DeltaMessage(content=" world"),
|
||||||
]
|
]
|
||||||
_mock_parser_with_reasoning(serving, delta_sequence)
|
response_parser = _mock_parser_with_reasoning(serving, delta_sequence)
|
||||||
# Create contexts for each streaming chunk
|
# Create contexts for each streaming chunk
|
||||||
contexts = [
|
contexts = [
|
||||||
_make_simple_context_with_output("chunk1", [10]),
|
_make_simple_context_with_output("chunk1", [10], response_parser),
|
||||||
_make_simple_context_with_output("chunk2", [20]),
|
_make_simple_context_with_output("chunk2", [20], response_parser),
|
||||||
_make_simple_context_with_output("chunk3", [30]),
|
_make_simple_context_with_output("chunk3", [30], response_parser),
|
||||||
]
|
]
|
||||||
|
|
||||||
async def result_generator():
|
async def result_generator():
|
||||||
@@ -767,7 +774,7 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
request=request,
|
request=request,
|
||||||
sampling_params=sampling_params,
|
sampling_params=sampling_params,
|
||||||
result_generator=result_generator(),
|
result_generator=result_generator(),
|
||||||
context=SimpleContext(),
|
context=SimpleContext(response_parser=response_parser),
|
||||||
model_name="test-model",
|
model_name="test-model",
|
||||||
tokenizer=MagicMock(),
|
tokenizer=MagicMock(),
|
||||||
request_metadata=metadata,
|
request_metadata=metadata,
|
||||||
@@ -813,11 +820,11 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
DeltaMessage(reasoning="thinking"),
|
DeltaMessage(reasoning="thinking"),
|
||||||
DeltaMessage(content="answer"),
|
DeltaMessage(content="answer"),
|
||||||
]
|
]
|
||||||
_mock_parser_with_reasoning(serving, delta_sequence)
|
response_parser = _mock_parser_with_reasoning(serving, delta_sequence)
|
||||||
|
|
||||||
contexts = [
|
contexts = [
|
||||||
_make_simple_context_with_output("chunk1", [10]),
|
_make_simple_context_with_output("chunk1", [10], response_parser),
|
||||||
_make_simple_context_with_output("chunk2", [20]),
|
_make_simple_context_with_output("chunk2", [20], response_parser),
|
||||||
]
|
]
|
||||||
|
|
||||||
async def result_generator():
|
async def result_generator():
|
||||||
@@ -834,7 +841,7 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
request=request,
|
request=request,
|
||||||
sampling_params=sampling_params,
|
sampling_params=sampling_params,
|
||||||
result_generator=result_generator(),
|
result_generator=result_generator(),
|
||||||
context=SimpleContext(),
|
context=SimpleContext(response_parser=response_parser),
|
||||||
model_name="test-model",
|
model_name="test-model",
|
||||||
tokenizer=MagicMock(),
|
tokenizer=MagicMock(),
|
||||||
request_metadata=metadata,
|
request_metadata=metadata,
|
||||||
@@ -875,11 +882,11 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
DeltaMessage(reasoning="step 1"),
|
DeltaMessage(reasoning="step 1"),
|
||||||
DeltaMessage(reasoning=" step 2"),
|
DeltaMessage(reasoning=" step 2"),
|
||||||
]
|
]
|
||||||
_mock_parser_with_reasoning(serving, delta_sequence)
|
response_parser = _mock_parser_with_reasoning(serving, delta_sequence)
|
||||||
|
|
||||||
contexts = [
|
contexts = [
|
||||||
_make_simple_context_with_output("chunk1", [10]),
|
_make_simple_context_with_output("chunk1", [10], response_parser),
|
||||||
_make_simple_context_with_output("chunk2", [20]),
|
_make_simple_context_with_output("chunk2", [20], response_parser),
|
||||||
]
|
]
|
||||||
|
|
||||||
async def result_generator():
|
async def result_generator():
|
||||||
@@ -896,7 +903,7 @@ class TestStreamingReasoningToContentTransition:
|
|||||||
request=request,
|
request=request,
|
||||||
sampling_params=sampling_params,
|
sampling_params=sampling_params,
|
||||||
result_generator=result_generator(),
|
result_generator=result_generator(),
|
||||||
context=SimpleContext(),
|
context=SimpleContext(response_parser=response_parser),
|
||||||
model_name="test-model",
|
model_name="test-model",
|
||||||
tokenizer=MagicMock(),
|
tokenizer=MagicMock(),
|
||||||
request_metadata=metadata,
|
request_metadata=metadata,
|
||||||
@@ -936,10 +943,10 @@ class TestAutoToolStreaming:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
async def _collect_events(delta_sequence: list[DeltaMessage]):
|
async def _collect_events(delta_sequence: list[DeltaMessage]):
|
||||||
serving = _make_serving_instance_with_reasoning()
|
serving = _make_serving_instance_with_reasoning()
|
||||||
_mock_parser_with_reasoning(serving, delta_sequence)
|
response_parser = _mock_parser_with_reasoning(serving, delta_sequence)
|
||||||
|
|
||||||
contexts = [
|
contexts = [
|
||||||
_make_simple_context_with_output("chunk", [i])
|
_make_simple_context_with_output("chunk", [i], response_parser)
|
||||||
for i in range(len(delta_sequence))
|
for i in range(len(delta_sequence))
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -974,7 +981,7 @@ class TestAutoToolStreaming:
|
|||||||
request=request,
|
request=request,
|
||||||
sampling_params=sampling_params,
|
sampling_params=sampling_params,
|
||||||
result_generator=result_generator(),
|
result_generator=result_generator(),
|
||||||
context=SimpleContext(),
|
context=SimpleContext(response_parser=response_parser),
|
||||||
model_name="test-model",
|
model_name="test-model",
|
||||||
tokenizer=MagicMock(),
|
tokenizer=MagicMock(),
|
||||||
request_metadata=metadata,
|
request_metadata=metadata,
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ class TurnMetrics:
|
|||||||
|
|
||||||
|
|
||||||
class ConversationContext(ABC):
|
class ConversationContext(ABC):
|
||||||
|
response_parser: Parser | None = None
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def append_output(self, output: RequestOutput) -> None:
|
def append_output(self, output: RequestOutput) -> None:
|
||||||
pass
|
pass
|
||||||
@@ -167,8 +169,25 @@ def _create_json_parse_error_messages(
|
|||||||
class SimpleContext(ConversationContext):
|
class SimpleContext(ConversationContext):
|
||||||
"""This is a context that cannot handle MCP tool calls"""
|
"""This is a context that cannot handle MCP tool calls"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
response_parser: Parser | None = None,
|
||||||
|
parser_cls: type[Parser] | None = None,
|
||||||
|
tokenizer: TokenizerLike | None = None,
|
||||||
|
request: ResponsesRequest | None = None,
|
||||||
|
chat_template_kwargs: dict[str, Any] | None = None,
|
||||||
|
):
|
||||||
self.last_output = None
|
self.last_output = None
|
||||||
|
self.response_parser = response_parser or (
|
||||||
|
parser_cls(
|
||||||
|
tokenizer,
|
||||||
|
request.tools,
|
||||||
|
chat_template_kwargs=chat_template_kwargs,
|
||||||
|
)
|
||||||
|
if parser_cls is not None and tokenizer is not None and request is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
# Accumulated final output for streaming mode
|
# Accumulated final output for streaming mode
|
||||||
self._accumulated_text: str = ""
|
self._accumulated_text: str = ""
|
||||||
@@ -181,7 +200,7 @@ class SimpleContext(ConversationContext):
|
|||||||
# todo num_reasoning_tokens is not implemented yet.
|
# todo num_reasoning_tokens is not implemented yet.
|
||||||
self.num_reasoning_tokens = 0
|
self.num_reasoning_tokens = 0
|
||||||
# not implemented yet for SimpleContext
|
# not implemented yet for SimpleContext
|
||||||
self.all_turn_metrics = []
|
self.all_turn_metrics: list[TurnMetrics] = []
|
||||||
|
|
||||||
self.input_messages: list[ResponseRawMessageAndToken] = []
|
self.input_messages: list[ResponseRawMessageAndToken] = []
|
||||||
self.kv_transfer_params: dict[str, Any] | None = None
|
self.kv_transfer_params: dict[str, Any] | None = None
|
||||||
@@ -280,6 +299,7 @@ class ParsableContext(ConversationContext):
|
|||||||
available_tools: list[str] | None,
|
available_tools: list[str] | None,
|
||||||
chat_template: str | None,
|
chat_template: str | None,
|
||||||
chat_template_content_format: ChatTemplateContentFormatOption,
|
chat_template_content_format: ChatTemplateContentFormatOption,
|
||||||
|
response_parser: Parser | None = None,
|
||||||
enable_auto_tools: bool = False,
|
enable_auto_tools: bool = False,
|
||||||
tool_call_id_type: str = "random",
|
tool_call_id_type: str = "random",
|
||||||
):
|
):
|
||||||
@@ -296,13 +316,13 @@ class ParsableContext(ConversationContext):
|
|||||||
self.enable_auto_tools = enable_auto_tools
|
self.enable_auto_tools = enable_auto_tools
|
||||||
self.tool_call_id_type = tool_call_id_type
|
self.tool_call_id_type = tool_call_id_type
|
||||||
|
|
||||||
self.parser_instance: Parser | None = None
|
self.response_parser = response_parser
|
||||||
if parser_cls is not None:
|
if self.response_parser is None and parser_cls is not None:
|
||||||
chat_template_kwargs = request.build_chat_params(
|
chat_template_kwargs = request.build_chat_params(
|
||||||
default_template=chat_template,
|
default_template=chat_template,
|
||||||
default_template_content_format=chat_template_content_format,
|
default_template_content_format=chat_template_content_format,
|
||||||
).chat_template_kwargs
|
).chat_template_kwargs
|
||||||
self.parser_instance = parser_cls(
|
self.response_parser = parser_cls(
|
||||||
tokenizer,
|
tokenizer,
|
||||||
tools=request.tools,
|
tools=request.tools,
|
||||||
chat_template_kwargs=chat_template_kwargs,
|
chat_template_kwargs=chat_template_kwargs,
|
||||||
@@ -334,8 +354,8 @@ class ParsableContext(ConversationContext):
|
|||||||
completion = output.outputs[0]
|
completion = output.outputs[0]
|
||||||
self.finish_reason = completion.finish_reason
|
self.finish_reason = completion.finish_reason
|
||||||
|
|
||||||
if self.parser_instance is not None:
|
if self.response_parser is not None:
|
||||||
reasoning, content, tool_calls = self.parser_instance.parse(
|
reasoning, content, tool_calls = self.response_parser.parse(
|
||||||
completion.text,
|
completion.text,
|
||||||
self.request,
|
self.request,
|
||||||
enable_auto_tools=self.enable_auto_tools,
|
enable_auto_tools=self.enable_auto_tools,
|
||||||
@@ -591,8 +611,10 @@ class HarmonyContext(ConversationContext):
|
|||||||
messages: list,
|
messages: list,
|
||||||
available_tools: list[str],
|
available_tools: list[str],
|
||||||
function_tool_names: frozenset[str] | None = None,
|
function_tool_names: frozenset[str] | None = None,
|
||||||
|
response_parser: Parser | None = None,
|
||||||
):
|
):
|
||||||
self._messages = messages
|
self._messages = messages
|
||||||
|
self.response_parser = response_parser
|
||||||
self.finish_reason: str | None = None
|
self.finish_reason: str | None = None
|
||||||
self.available_tools = available_tools
|
self.available_tools = available_tools
|
||||||
self.function_tool_names = function_tool_names
|
self.function_tool_names = function_tool_names
|
||||||
|
|||||||
@@ -260,6 +260,20 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
.chat_template_kwargs
|
.chat_template_kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _make_response_parser(
|
||||||
|
self,
|
||||||
|
request: ResponsesRequest,
|
||||||
|
tokenizer: TokenizerLike,
|
||||||
|
chat_template_kwargs: dict[str, Any],
|
||||||
|
) -> Parser | None:
|
||||||
|
if self.parser is None:
|
||||||
|
return None
|
||||||
|
return self.parser(
|
||||||
|
tokenizer,
|
||||||
|
request.tools,
|
||||||
|
chat_template_kwargs=chat_template_kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
def _validate_generator_input(
|
def _validate_generator_input(
|
||||||
self,
|
self,
|
||||||
engine_input: EngineInput,
|
engine_input: EngineInput,
|
||||||
@@ -443,16 +457,27 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
else await self._get_trace_headers(raw_request.headers)
|
else await self._get_trace_headers(raw_request.headers)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
chat_template_kwargs = self._effective_chat_template_kwargs(request)
|
||||||
|
response_parser = self._make_response_parser(
|
||||||
|
request, tokenizer, chat_template_kwargs
|
||||||
|
)
|
||||||
|
|
||||||
context: ConversationContext
|
context: ConversationContext
|
||||||
function_tool_names = extract_function_tool_names(request.tools)
|
function_tool_names = extract_function_tool_names(request.tools)
|
||||||
if self.use_harmony:
|
if self.use_harmony:
|
||||||
if request.stream:
|
if request.stream:
|
||||||
context = StreamingHarmonyContext(
|
context = StreamingHarmonyContext(
|
||||||
messages, available_tools, function_tool_names
|
messages,
|
||||||
|
available_tools,
|
||||||
|
function_tool_names,
|
||||||
|
response_parser=response_parser,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
context = HarmonyContext(
|
context = HarmonyContext(
|
||||||
messages, available_tools, function_tool_names
|
messages,
|
||||||
|
available_tools,
|
||||||
|
function_tool_names,
|
||||||
|
response_parser=response_parser,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if envs.VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT:
|
if envs.VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT:
|
||||||
@@ -463,6 +488,7 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
tokenizer=tokenizer,
|
tokenizer=tokenizer,
|
||||||
parser_cls=self.parser,
|
parser_cls=self.parser,
|
||||||
request=request,
|
request=request,
|
||||||
|
response_parser=response_parser,
|
||||||
available_tools=available_tools,
|
available_tools=available_tools,
|
||||||
chat_template=self.chat_template,
|
chat_template=self.chat_template,
|
||||||
chat_template_content_format=self.chat_template_content_format,
|
chat_template_content_format=self.chat_template_content_format,
|
||||||
@@ -470,17 +496,17 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
tool_call_id_type=self.tool_call_id_type,
|
tool_call_id_type=self.tool_call_id_type,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
context = SimpleContext()
|
context = SimpleContext(
|
||||||
|
response_parser=response_parser,
|
||||||
|
)
|
||||||
|
|
||||||
if self.parser and self.parser.reasoning_parser_cls is not None:
|
if (
|
||||||
chat_template_kwargs = self._effective_chat_template_kwargs(request)
|
context.response_parser is not None
|
||||||
|
and context.response_parser.reasoning_parser is not None
|
||||||
|
):
|
||||||
reasoning_parser_kwargs = {
|
reasoning_parser_kwargs = {
|
||||||
"chat_template_kwargs": chat_template_kwargs,
|
"chat_template_kwargs": chat_template_kwargs,
|
||||||
}
|
}
|
||||||
reasoning_parser = self.parser.reasoning_parser_cls(
|
|
||||||
tokenizer,
|
|
||||||
chat_template_kwargs=chat_template_kwargs,
|
|
||||||
)
|
|
||||||
if (
|
if (
|
||||||
isinstance(
|
isinstance(
|
||||||
struct_out := sampling_params.structured_outputs,
|
struct_out := sampling_params.structured_outputs,
|
||||||
@@ -490,8 +516,10 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
):
|
):
|
||||||
sampling_params.structured_outputs = replace(
|
sampling_params.structured_outputs = replace(
|
||||||
struct_out,
|
struct_out,
|
||||||
structural_tag=reasoning_parser.prepare_structured_tag(
|
structural_tag=(
|
||||||
struct_out.structural_tag, self.tool_server
|
context.response_parser.reasoning_parser.prepare_structured_tag(
|
||||||
|
struct_out.structural_tag, self.tool_server
|
||||||
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
generator = self._generate_with_builtin_tools(
|
generator = self._generate_with_builtin_tools(
|
||||||
@@ -833,7 +861,12 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
if final_output.finish_reason == "length":
|
if final_output.finish_reason == "length":
|
||||||
status = "incomplete"
|
status = "incomplete"
|
||||||
|
|
||||||
output = self._make_response_output_items(request, final_output, tokenizer)
|
output = self._make_response_output_items(
|
||||||
|
request,
|
||||||
|
final_output,
|
||||||
|
tokenizer,
|
||||||
|
parser=context.response_parser,
|
||||||
|
)
|
||||||
|
|
||||||
if request.enable_response_messages:
|
if request.enable_response_messages:
|
||||||
input_messages = context.input_messages
|
input_messages = context.input_messages
|
||||||
@@ -854,16 +887,16 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
# accumulated output token IDs using the parser if not already set.
|
# accumulated output token IDs using the parser if not already set.
|
||||||
if (
|
if (
|
||||||
num_reasoning_tokens == 0
|
num_reasoning_tokens == 0
|
||||||
and self.parser is not None
|
|
||||||
and self.parser.reasoning_parser_cls is not None
|
|
||||||
and isinstance(context, (SimpleContext, ParsableContext))
|
and isinstance(context, (SimpleContext, ParsableContext))
|
||||||
|
and context.response_parser is not None
|
||||||
|
and context.response_parser.reasoning_parser is not None
|
||||||
):
|
):
|
||||||
reasoning_parser = self.parser.reasoning_parser_cls(
|
|
||||||
tokenizer,
|
|
||||||
chat_template_kwargs=self._effective_chat_template_kwargs(request),
|
|
||||||
)
|
|
||||||
accumulated = getattr(context, "_accumulated_token_ids", []) or []
|
accumulated = getattr(context, "_accumulated_token_ids", []) or []
|
||||||
num_reasoning_tokens = reasoning_parser.count_reasoning_tokens(accumulated)
|
num_reasoning_tokens = (
|
||||||
|
context.response_parser.reasoning_parser.count_reasoning_tokens(
|
||||||
|
accumulated
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
usage = ResponseUsage(
|
usage = ResponseUsage(
|
||||||
input_tokens=num_prompt_tokens,
|
input_tokens=num_prompt_tokens,
|
||||||
@@ -1005,6 +1038,7 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
request: ResponsesRequest,
|
request: ResponsesRequest,
|
||||||
final_output: CompletionOutput,
|
final_output: CompletionOutput,
|
||||||
tokenizer: TokenizerLike,
|
tokenizer: TokenizerLike,
|
||||||
|
parser: Parser | None = None,
|
||||||
) -> list[ResponseOutputItem]:
|
) -> list[ResponseOutputItem]:
|
||||||
# Log complete response if output logging is enabled
|
# Log complete response if output logging is enabled
|
||||||
if self.enable_log_outputs and self.request_logger:
|
if self.enable_log_outputs and self.request_logger:
|
||||||
@@ -1028,11 +1062,7 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Use parser to extract reasoning, content, and tool calls
|
# Use parser to extract reasoning, content, and tool calls
|
||||||
if self.parser:
|
if parser:
|
||||||
chat_template_kwargs = self._effective_chat_template_kwargs(request)
|
|
||||||
parser = self.parser(
|
|
||||||
tokenizer, request.tools, chat_template_kwargs=chat_template_kwargs
|
|
||||||
)
|
|
||||||
reasoning, content, tool_calls = parser.parse(
|
reasoning, content, tool_calls = parser.parse(
|
||||||
final_output.text,
|
final_output.text,
|
||||||
request,
|
request,
|
||||||
@@ -1350,15 +1380,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
],
|
],
|
||||||
) -> AsyncGenerator[StreamingResponsesResponse, None]:
|
) -> AsyncGenerator[StreamingResponsesResponse, None]:
|
||||||
processor = SimpleStreamingEventProcessor()
|
processor = SimpleStreamingEventProcessor()
|
||||||
parser = (
|
|
||||||
self.parser(
|
|
||||||
tokenizer,
|
|
||||||
request.tools,
|
|
||||||
chat_template_kwargs=self._effective_chat_template_kwargs(request),
|
|
||||||
)
|
|
||||||
if self.parser
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_logprobs(
|
def _get_logprobs(
|
||||||
output: CompletionOutput,
|
output: CompletionOutput,
|
||||||
@@ -1382,8 +1403,8 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
delta_text = output.text
|
delta_text = output.text
|
||||||
delta_token_ids = as_list(output.token_ids)
|
delta_token_ids = as_list(output.token_ids)
|
||||||
|
|
||||||
if parser:
|
if ctx.response_parser:
|
||||||
delta_message = parser.parse_delta(
|
delta_message = ctx.response_parser.parse_delta(
|
||||||
delta_text=delta_text,
|
delta_text=delta_text,
|
||||||
delta_token_ids=delta_token_ids,
|
delta_token_ids=delta_token_ids,
|
||||||
request=request,
|
request=request,
|
||||||
|
|||||||
Reference in New Issue
Block a user