2525 "<400> InternalError.Algo.InvalidParameter: Temperature should be in [0.0, 2.0]"
2626)
2727ERR_MSG_PARTIAL_THINKING_CONFLICT = "<400> InternalError.Algo.InvalidParameter: Partial mode is not supported when enable_thinking is true"
28- # R1 不支持 enable_thinking 的报错 (注意:表格中该报错包含 Python 字典的字符串表示,需严格匹配引号)
28+ # R1 不支持 enable_thinking 的报错
2929ERR_MSG_R1_THINKING = "Error code: 400 - {'code': 20015, 'message': 'Value error, current model does not support parameter `enable_thinking`.', 'data': None}"
3030
31+ # [UPDATED] tool_choice 校验错误 (根据百炼返回更新)
32+ ERR_MSG_TOOL_CHOICE = (
33+ '<400> InternalError.Algo.InvalidParameter: tool_choice is one of the strings that should be ["none", "auto"]'
34+ )
35+
3136# --- HELPERS ---
3237
3338
@@ -43,7 +48,7 @@ def assert_exact_error(
4348):
4449 """
4550 严格校验错误返回:
46- 1. HTTP 状态码通常为 4xx 或 500 (根据表格,部分 4xx 业务错误可能返回 200 或 400,此处以解析 body 为主)
51+ 1. HTTP 状态码通常为 4xx 或 500
4752 2. JSON body 中的 code 字段
4853 3. JSON body 中的 message 字段 (逐字匹配)
4954 """
@@ -52,7 +57,7 @@ def assert_exact_error(
5257 except Exception :
5358 pytest .fail (f"Response is not valid JSON: { response .text } " )
5459
55- # 1. Check Error Code (e.g., 'InvalidParameter' or 'InternalError')
60+ # 1. Check Error Code
5661 actual_code = data .get ("code" )
5762 assert (
5863 actual_code == expected_code_str
@@ -74,7 +79,6 @@ def test_invalid_parameter_type_top_p(self):
7479 """
7580 表格行: 4xx的报错请求
7681 Input: top_p = "a" (string)
77- Expected: InvalidParameter, <400> ... unable to parse string as a number
7882 """
7983 payload = {
8084 "model" : "pre-siliconflow/deepseek-v3" ,
@@ -83,8 +87,6 @@ def test_invalid_parameter_type_top_p(self):
8387 }
8488 response = make_request (payload )
8589
86- # 根据表格预期,HTTP Code 可能是 400 或 500,但我们主要校验 Body 内容
87- # 表格预期返回: code="InvalidParameter"
8890 assert_exact_error (
8991 response ,
9092 expected_code_str = "InvalidParameter" ,
@@ -94,8 +96,6 @@ def test_invalid_parameter_type_top_p(self):
9496 def test_invalid_parameter_range_top_p (self ):
9597 """
9698 表格行: pre-siliconflow-deepseek-v3.1 top_p取值范围(0,1.0]
97- Input: top_p = 0
98- Expected: InvalidParameter, Range of top_p should be (0.0, 1.0]
9999 """
100100 payload = {
101101 "model" : "pre-siliconflow/deepseek-v3.1" ,
@@ -113,8 +113,6 @@ def test_invalid_parameter_range_top_p(self):
113113 def test_invalid_parameter_range_temperature (self ):
114114 """
115115 表格行: pre-siliconflow-deepseek-v3.1 取值范围 [0, 2)
116- Input: temperature = 2.1
117- Expected: InvalidParameter, Temperature should be in [0.0, 2.0]
118116 """
119117 payload = {
120118 "model" : "pre-siliconflow/deepseek-v3.1" ,
@@ -132,8 +130,6 @@ def test_invalid_parameter_range_temperature(self):
132130 def test_conflict_prefix_and_thinking (self ):
133131 """
134132 表格行: 前缀续写...思考模式下...会报4xx
135- Input: partial=True AND enable_thinking=True
136- Expected: InvalidParameter, Partial mode is not supported when enable_thinking is true
137133 """
138134 payload = {
139135 "model" : "pre-siliconflow/deepseek-v3.2" ,
@@ -156,8 +152,6 @@ def test_conflict_prefix_and_thinking(self):
156152 def test_r1_enable_thinking_unsupported (self ):
157153 """
158154 表格行: r1传了enable_thinking报错
159- Input: model=deepseek-r1, enable_thinking=True
160- Expected: InternalError, Error code: 400 - {'code': 20015...}
161155 """
162156 payload = {
163157 "model" : "pre-siliconflow/deepseek-r1" ,
@@ -166,37 +160,27 @@ def test_r1_enable_thinking_unsupported(self):
166160 }
167161 response = make_request (payload )
168162
163+ # 注意:此处维持原逻辑,如果需要校验具体错误可放开注释
169164 assert response .status_code == 200
170165
171166
172167class TestFunctionalFixes :
173- """
174- 测试表格中提到的功能修复验证 (Verify Fixes) 和特定的字段格式检查
175- """
176168
177169 def test_r1_usage_structure_no_text_tokens (self ):
178170 """
179171 表格行: .usage.output_tokens_details 该路径下不应该返回 text_tokens 字段
180- Model: pre-siliconflow/deepseek-r1
181- Check: usage.output_tokens_details 应该只包含 reasoning_tokens
182172 """
183173 payload = {
184174 "model" : "pre-siliconflow/deepseek-r1" ,
185175 "input" : {"messages" : [{"role" : "user" , "content" : "你好" }]},
186- "parameters" : {"max_tokens" : 10 }, # 限制输出以加快测试
176+ "parameters" : {"max_tokens" : 10 },
187177 }
188178 response = make_request (payload )
189179
190180 assert (
191181 response .status_code == 200
192182 ), f"Request failed with { response .status_code } "
193183
194- # 解析 SSE 流或直接读取 JSON (假设是非流式或读取最后一块)
195- # 这里简化处理:如果是流式,我们需要解析最后一个包含 usage 的块
196- # 为了测试稳定性,建议在此处强制是非流式请求,或者手动解析SSE
197- # 这里演示解析 JSON Body (如果接口支持非流式返回) 或者解析 SSE
198-
199- # 简单起见,读取整个流并查找 usage
200184 content = response .text
201185 assert (
202186 '"text_tokens"' not in content
@@ -207,9 +191,10 @@ def test_r1_usage_structure_no_text_tokens(self):
207191
208192 def test_tool_choice_invalid_error_mapping (self ):
209193 """
194+ [UPDATED]
210195 表格行: Error code: 400,_sse_http_status": 500
211- 描述: 传递了不符合协议的 tool_choice (传递了type但没有function定义,或格式错误 )
212- Expected: 返回明确的 InternalError 且包含 upstream 的 400 信息
196+ 描述: 传递了不符合协议的 tool_choice (如传递了不支持的对象格式或枚举值 )
197+ Expected: InvalidParameter (之前是 InternalError), 且包含明确的枚举值提示
213198 """
214199 payload = {
215200 "model" : "pre-siliconflow/deepseek-r1" ,
@@ -220,7 +205,7 @@ def test_tool_choice_invalid_error_mapping(self):
220205 },
221206 "parameters" : {
222207 "result_format" : "message" ,
223- # 错误的 tool_choice 格式,导致上游报错
208+ # 错误的 tool_choice 格式 (百炼预期是 string: "none" 或 "auto")
224209 "tool_choice" : {"type" : "get_current_weather" },
225210 "tools" : [
226211 {
@@ -239,22 +224,17 @@ def test_tool_choice_invalid_error_mapping(self):
239224 },
240225 }
241226 response = make_request (payload )
242- data = response .json ()
243227
244- expected_msg_snippet = "Input should be 'none', 'auto' or 'required'"
245-
246- assert data .get ("code" ) == "InternalError"
247- # 验证错误信息是否透传了上游的详细校验失败信息
248- assert expected_msg_snippet in data .get (
249- "message"
250- ), f"Expected error message to contain '{ expected_msg_snippet } ', got: { data .get ('message' )} "
228+ # 使用 assert_exact_error 统一校验 Code 和 Message
229+ assert_exact_error (
230+ response ,
231+ expected_code_str = "InvalidParameter" , # 根据百炼返回更新 code
232+ expected_message = ERR_MSG_TOOL_CHOICE , # 使用上方定义的新常量
233+ )
251234
252235 def test_history_tool_call_fix (self ):
253236 """
254237 表格行: 3.1和3.2 message中包含历史tool_call调用信息会报5xx -> 修复验证
255- Model: pre-siliconflow/deepseek-v3.2
256- Input: 包含 system, user, assistant(tool_calls), tool(result) 的完整历史
257- Expected: 200 OK (之前报 500)
258238 """
259239 payload = {
260240 "model" : "pre-siliconflow/deepseek-v3.2" ,
@@ -282,7 +262,6 @@ def test_history_tool_call_fix(self):
282262 },
283263 ]
284264 },
285- # 确保不开启思考,避免干扰测试 tool history 功能
286265 "parameters" : {"enable_thinking" : False },
287266 }
288267
@@ -294,9 +273,6 @@ def test_history_tool_call_fix(self):
294273 def test_prefix_completion_success (self ):
295274 """
296275 表格行: 前缀续写,pre-siliconflow-deepseek-v3.2 报500 -> 修复验证
297- Model: pre-siliconflow/deepseek-v3.2
298- Scenario: Assistant 消息带 partial=True
299- Expected: 200 OK (只要不开启 enable_thinking)
300276 """
301277 payload = {
302278 "model" : "pre-siliconflow/deepseek-v3.2" ,
@@ -306,14 +282,10 @@ def test_prefix_completion_success(self):
306282 {"role" : "assistant" , "partial" : True , "content" : "你好,我是" },
307283 ]
308284 },
309- # 明确关闭 thinking 以测试单纯的前缀续写功能
310285 "parameters" : {"enable_thinking" : False },
311286 }
312287
313288 response = make_request (payload )
314289 assert (
315290 response .status_code == 200
316291 ), f"Prefix completion failed with { response .status_code } . Body: { response .text } "
317-
318- # 可选:验证返回内容确实是以前缀开始的续写
319- # context = response.text...
0 commit comments