Skip to content

vllm.reasoning.cohere_command_reasoning_parser

Classes:

BaseCohereCommandReasoningParser

Bases: ReasoningParser

Expose is_reasoning_end for the structured-output engine. Everything else runs in :class:vllm.parser.cohere_command.CohereCommandParser.

Source code in vllm/reasoning/cohere_command_reasoning_parser.py
class BaseCohereCommandReasoningParser(ReasoningParser):
    """Expose is_reasoning_end for the structured-output engine.
    Everything else runs in
    :class:`vllm.parser.cohere_command.CohereCommandParser`.
    """

    melody_preset: ClassVar[str]

    def __init__(self, tokenizer: TokenizerLike, *args, **kwargs):
        super().__init__(tokenizer, *args, **kwargs)
        self.start_token_id = tokenizer.convert_tokens_to_ids("<|START_THINKING|>")
        self.end_token_id = tokenizer.convert_tokens_to_ids("<|END_THINKING|>")
        self.chatbot_token_id = tokenizer.convert_tokens_to_ids("<|CHATBOT_TOKEN|>")

    @property
    def reasoning_start_str(self) -> str | None:
        return "<|START_THINKING|>"

    @property
    def reasoning_end_str(self) -> str | None:
        return "<|END_THINKING|>"

    def is_reasoning_end(self, input_ids: Sequence[int]) -> bool:
        # Reasoning ended if an end token follows the newest start token,
        # unless a chatbot token comes after that start.
        i = rfind_tokens(input_ids, (self.start_token_id, self.chatbot_token_id))
        if i >= 0 and input_ids[i] == self.chatbot_token_id:
            return False
        return rfind_tokens(input_ids, (self.end_token_id,), start=i + 1) >= 0