@@ -71,3 +71,81 @@ def test_qwen3_reasoning_parser_stream(delta_texts: list, content: list,
7171 result = reasoning_parser .parse_delta (delta_text )
7272 assert result .content == content [i ]
7373 assert result .reasoning_content == reasoning_context [i ]
74+
75+
76+ @pytest .mark .parametrize (
77+ ("text" , "content" , "reasoning_context" , "chat_template_kwargs" ),
78+ [
79+ ("a b" , "" , "a b" , None ),
80+ (f"{ R1_END } a b" , " a b" , "" , None ),
81+ (f"a { R1_END } b" , " b" , "a " , None ),
82+ (f"a b { R1_END } " , "" , "a b " , None ),
83+ (f"{ R1_START } a { R1_END } b" , " b" , f"{ R1_START } a " , None ),
84+ # All without reasoning_context.
85+ ("a b" , "a b" , "" , {
86+ "enable_thinking" : False
87+ }),
88+ (f"{ R1_END } a b" , f"{ R1_END } a b" , "" , {
89+ "enable_thinking" : False
90+ }),
91+ (f"a { R1_END } b" , f"a { R1_END } b" , "" , {
92+ "enable_thinking" : False
93+ }),
94+ (f"a b { R1_END } " , f"a b { R1_END } " , "" , {
95+ "enable_thinking" : False
96+ }),
97+ ])
98+ def test_nano_v3_reasoning_parser (text : str , content : str ,
99+ reasoning_context : str ,
100+ chat_template_kwargs : dict ):
101+ reasoning_parser = ReasoningParserFactory .create_reasoning_parser (
102+ "nano-v3" , chat_template_kwargs )
103+ result = reasoning_parser .parse (text )
104+ print (f"text: { text } , result: { result } " )
105+ assert result .content == content
106+ assert result .reasoning_content == reasoning_context
107+
108+
109+ @pytest .mark .parametrize (
110+ ("delta_texts" , "content" , "reasoning_context" , "chat_template_kwargs" ),
111+ [
112+ (["a" , "b" ], ["" , "" ], ["a" , "b" ], None ),
113+ ([R1_END , "a" , "b" ], ["" , "a" , "b" ], ["" , "" , "" ], None ),
114+ (["a" , R1_END , "b" ], ["" , "" , "b" ], ["a" , "" , "" ], None ),
115+ (["a" , "b" , R1_END ], ["" , "" , "" ], ["a" , "b" , "" ], None ),
116+ (["a" , f"l{ R1_END } " , "b" ], ["" , "" , "b" ], ["a" , "l" , "" ], None ),
117+ (["a" , f"l{ R1_END } r" , "b" ], ["" , "r" , "b" ], ["a" , "l" , "" ], None ),
118+ (["a" , f"{ R1_END } r" , "b" ], ["" , "r" , "b" ], ["a" , "" , "" ], None ),
119+ # All without reasoning_context.
120+ (["a" , "b" ], ["a" , "b" ], ["" , "" ], {
121+ "enable_thinking" : False
122+ }),
123+ ([R1_END , "a" , "b" ], ["" , f"{ R1_END } a" , "b" ], ["" , "" , "" ], {
124+ "enable_thinking" : False
125+ }),
126+ (["a" , R1_END , "b" ], ["a" , "" , f"{ R1_END } b" ], ["" , "" , "" ], {
127+ "enable_thinking" : False
128+ }),
129+ (["a" , "b" , R1_END ], ["a" , "b" , "" ], ["" , "" , "" ], {
130+ "enable_thinking" : False
131+ }),
132+ (["a" , f"l{ R1_END } " , "b" ], ["a" , f"l{ R1_END } " , "b" ], ["" , "" , "" ], {
133+ "enable_thinking" : False
134+ }),
135+ (["a" , f"l{ R1_END } r" , "b" ], ["a" , f"l{ R1_END } r" , "b" ], ["" , "" , "" ], {
136+ "enable_thinking" : False
137+ }),
138+ (["a" , f"{ R1_END } r" , "b" ], ["a" , f"{ R1_END } r" , "b" ], ["" , "" , "" ], {
139+ "enable_thinking" : False
140+ }),
141+ ])
142+ def test_nano_v3_reasoning_parser_stream (delta_texts : list , content : list ,
143+ reasoning_context : list ,
144+ chat_template_kwargs : dict ):
145+ reasoning_parser = ReasoningParserFactory .create_reasoning_parser (
146+ "nano-v3" , chat_template_kwargs )
147+ for i , delta_text in enumerate (delta_texts ):
148+ result = reasoning_parser .parse_delta (delta_text )
149+ print (f"delta_text: { delta_text } , result: { result } " )
150+ assert result .content == content [i ]
151+ assert result .reasoning_content == reasoning_context [i ]
0 commit comments