main
py 62 lines 2.11 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 from collections.abc import Iterable, Sequence
4 from typing import TYPE_CHECKING
5
6 from transformers import PreTrainedTokenizerBase
7
8 from vllm.entrypoints.generate.base.protocol import DeltaMessage
9 from vllm.reasoning import ReasoningParser
10
11 if TYPE_CHECKING:
12 from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
13 from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
14
15
16 class GptOssReasoningParser(ReasoningParser):
17 """Reasoning parser for GptOss model.
18
19 The GptOss model uses harmony to extract reasoning content and this parser
20 is only used for detecting the end of the reasoning content.
21 """
22
23 def __init__(self, tokenizer: PreTrainedTokenizerBase, *args, **kwargs):
24 super().__init__(tokenizer, *args, **kwargs)
25
26 def is_reasoning_end(self, input_ids: Sequence[int]) -> bool:
27 return True
28
29 def is_reasoning_end_streaming(
30 self, input_ids: Sequence[int], delta_ids: Iterable[int]
31 ) -> bool:
32 return True
33
34 def extract_content_ids(self, input_ids: list[int]) -> list[int]:
35 raise NotImplementedError(
36 "GptOssReasoningParser only provides boundary detection. "
37 "Use HarmonyParser for output parsing."
38 )
39
40 def extract_reasoning_streaming(
41 self,
42 previous_text: str,
43 current_text: str,
44 delta_text: str,
45 previous_token_ids: Sequence[int],
46 current_token_ids: Sequence[int],
47 delta_token_ids: Sequence[int],
48 ) -> DeltaMessage | None:
49 raise NotImplementedError(
50 "GptOssReasoningParser only provides boundary detection. "
51 "Use HarmonyParser for output parsing."
52 )
53
54 def extract_reasoning(
55 self,
56 model_output: str,
57 request: "ChatCompletionRequest | ResponsesRequest",
58 ) -> tuple[str | None, str | None]:
59 raise NotImplementedError(
60 "GptOssReasoningParser only provides boundary detection. "
61 "Use HarmonyParser for output parsing."
62 )