@@ -247,7 +247,7 @@ def test_stop_behavior_in_reasoning(self):
247247 },
248248 "parameters" : {
249249 "stop" : [target_stop_word ],
250- # R1 自动开启思考,但也可能需要显式参数,视具体后端实现而定,这里保持默认或按需添加
250+ "incremental_output" : True # 开启增量输出,避免内容重复
251251 }
252252 }
253253
@@ -273,22 +273,24 @@ def test_stop_behavior_in_reasoning(self):
273273
274274 try :
275275 chunk = json .loads (json_str )
276- choices = chunk .get ("choices" , [])
276+
277+ # --- [修复 1] 适配 DashScope 结构:先取 output ---
278+ output = chunk .get ("output" , {})
279+ choices = output .get ("choices" , [])
280+
277281 if not choices :
278282 continue
279283
280- delta = choices [0 ].get ("delta" , {})
284+ # --- [修复 2] 适配 DashScope 结构:取 message 而非 delta ---
285+ # DashScope 在流式传输中也使用 message 字段
286+ message = choices [0 ].get ("message" , {})
281287
282- # 1. 收集 reasoning_content
283- # 注意:有些实现可能叫 reasoning_text,视具体 API 定义,这里假设是 reasoning_content
284- if "reasoning_content" in delta :
285- collected_reasoning += delta ["reasoning_content" ]
288+ if "reasoning_content" in message :
289+ collected_reasoning += message ["reasoning_content" ]
286290
287- # 2. 收集正文 content
288- if "content" in delta :
289- collected_content += delta ["content" ]
291+ if "content" in message :
292+ collected_content += message ["content" ]
290293
291- # 3. 捕捉 finish_reason
292294 if choices [0 ].get ("finish_reason" ):
293295 final_finish_reason = choices [0 ].get ("finish_reason" )
294296
0 commit comments