deepseek_r1_parser.rs 1.05 KB
Newer Older
1
2
3
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

4
5
6
use super::base_parser::BasicReasoningParser;
use crate::ParserResult;
use crate::ReasoningParser;
7

8
#[derive(Default, Debug, Clone)]
9
pub struct DeepseekR1ReasoningParser {
10
    base: BasicReasoningParser,
11
12
13
14
15
}

impl DeepseekR1ReasoningParser {
    pub fn new() -> Self {
        Self {
16
            base: BasicReasoningParser::new(
17
18
19
20
21
22
23
24
25
26
                "<think>".to_string(),
                "</think>".to_string(),
                true,
                true,
            ),
        }
    }
}

impl ReasoningParser for DeepseekR1ReasoningParser {
27
28
29
30
31
32
33
    fn parse_reasoning_streaming_incremental(
        &mut self,
        text: &str,
        token_ids: &[u32],
    ) -> ParserResult {
        self.base
            .parse_reasoning_streaming_incremental(text, token_ids)
34
35
    }

36
37
    fn detect_and_parse_reasoning(&mut self, text: &str, token_ids: &[u32]) -> ParserResult {
        self.base.detect_and_parse_reasoning(text, token_ids)
38
39
    }
}