@@ -174,5 +174,148 @@ def test_r1_enable_thinking_unsupported(self):
174174 )
175175
176176
177- if __name__ == "__main__" :
178- pytest .main (["-v" , __file__ ])
177+ class TestFunctionalFixes :
178+ """
179+ 测试表格中提到的功能修复验证 (Verify Fixes) 和特定的字段格式检查
180+ """
181+
182+ def test_r1_usage_structure_no_text_tokens (self ):
183+ """
184+ 表格行: .usage.output_tokens_details 该路径下不应该返回 text_tokens 字段
185+ Model: pre-siliconflow/deepseek-r1
186+ Check: usage.output_tokens_details 应该只包含 reasoning_tokens
187+ """
188+ payload = {
189+ "model" : "pre-siliconflow/deepseek-r1" ,
190+ "input" : {"messages" : [{"role" : "user" , "content" : "你好" }]},
191+ "parameters" : {"max_tokens" : 10 } # 限制输出以加快测试
192+ }
193+ response = make_request (payload )
194+
195+ assert response .status_code == 200 , f"Request failed with { response .status_code } "
196+
197+ # 解析 SSE 流或直接读取 JSON (假设是非流式或读取最后一块)
198+ # 这里简化处理:如果是流式,我们需要解析最后一个包含 usage 的块
199+ # 为了测试稳定性,建议在此处强制是非流式请求,或者手动解析SSE
200+ # 这里演示解析 JSON Body (如果接口支持非流式返回) 或者解析 SSE
201+
202+ # 简单起见,读取整个流并查找 usage
203+ content = response .text
204+ assert '"text_tokens"' not in content , "Response output_tokens_details should NOT contain 'text_tokens'"
205+ assert '"reasoning_tokens"' in content , "Response output_tokens_details MUST contain 'reasoning_tokens'"
206+
207+ def test_tool_choice_invalid_error_mapping (self ):
208+ """
209+ 表格行: Error code: 400,_sse_http_status": 500
210+ 描述: 传递了不符合协议的 tool_choice (传递了type但没有function定义,或格式错误)
211+ Expected: 返回明确的 InternalError 且包含 upstream 的 400 信息
212+ """
213+ payload = {
214+ "model" : "pre-siliconflow/deepseek-r1" ,
215+ "input" : {
216+ "messages" : [{"role" : "user" , "content" : "What is the weather like in Boston?" }]
217+ },
218+ "parameters" : {
219+ "result_format" : "message" ,
220+ # 错误的 tool_choice 格式,导致上游报错
221+ "tool_choice" : {"type" : "get_current_weather" },
222+ "tools" : [
223+ {
224+ "type" : "function" ,
225+ "function" : {
226+ "name" : "get_current_weather" ,
227+ "description" : "Get current weather" ,
228+ "parameters" : {
229+ "type" : "object" ,
230+ "properties" : {"location" : {"type" : "string" }},
231+ "required" : ["location" ]
232+ }
233+ }
234+ }
235+ ]
236+ }
237+ }
238+ response = make_request (payload )
239+ data = response .json ()
240+
241+ expected_msg_snippet = "Input should be 'none', 'auto' or 'required'"
242+
243+ assert data .get ("code" ) == "InternalError"
244+ # 验证错误信息是否透传了上游的详细校验失败信息
245+ assert expected_msg_snippet in data .get ("message" ), \
246+ f"Expected error message to contain '{ expected_msg_snippet } ', got: { data .get ('message' )} "
247+
248+ def test_history_tool_call_fix (self ):
249+ """
250+ 表格行: 3.1和3.2 message中包含历史tool_call调用信息会报5xx -> 修复验证
251+ Model: pre-siliconflow/deepseek-v3.2
252+ Input: 包含 system, user, assistant(tool_calls), tool(result) 的完整历史
253+ Expected: 200 OK (之前报 500)
254+ """
255+ payload = {
256+ "model" : "pre-siliconflow/deepseek-v3.2" ,
257+ "input" : {
258+ "messages" : [
259+ {
260+ "role" : "system" ,
261+ "content" : "你是一个智能助手。"
262+ },
263+ {
264+ "role" : "user" ,
265+ "content" : "外部轴设置"
266+ },
267+ {
268+ "role" : "assistant" ,
269+ "tool_calls" : [
270+ {
271+ "function" : {
272+ "arguments" : "{\" input_text\" : \" 外部轴设置\" }" ,
273+ "name" : "KB20250625001"
274+ },
275+ "id" : "call_6478091069c2448b83f38e" ,
276+ "type" : "function"
277+ }
278+ ]
279+ },
280+ {
281+ "role" : "tool" ,
282+ "content" : "界面用于用户进行快速配置。" ,
283+ "tool_call_id" : "call_6478091069c2448b83f38e"
284+ }
285+ ]
286+ },
287+ # 确保不开启思考,避免干扰测试 tool history 功能
288+ "parameters" : {"enable_thinking" : False }
289+ }
290+
291+ response = make_request (payload )
292+ assert response .status_code == 200 , f"Previously 500 error scenario failed. Got: { response .text } "
293+
294+ def test_prefix_completion_success (self ):
295+ """
296+ 表格行: 前缀续写,pre-siliconflow-deepseek-v3.2 报500 -> 修复验证
297+ Model: pre-siliconflow/deepseek-v3.2
298+ Scenario: Assistant 消息带 partial=True
299+ Expected: 200 OK (只要不开启 enable_thinking)
300+ """
301+ payload = {
302+ "model" : "pre-siliconflow/deepseek-v3.2" ,
303+ "input" : {
304+ "messages" : [
305+ {"role" : "user" , "content" : "你好" },
306+ {
307+ "role" : "assistant" ,
308+ "partial" : True ,
309+ "content" : "你好,我是"
310+ }
311+ ]
312+ },
313+ # 明确关闭 thinking 以测试单纯的前缀续写功能
314+ "parameters" : {"enable_thinking" : False }
315+ }
316+
317+ response = make_request (payload )
318+ assert response .status_code == 200 , f"Prefix completion failed with { response .status_code } . Body: { response .text } "
319+
320+ # 可选:验证返回内容确实是以前缀开始的续写
321+ # context = response.text...
0 commit comments