ZyphrZero commited on
Commit
b5594ae
·
1 Parent(s): db61ab8

Create test_system_field.py

Browse files
Files changed (1) hide show
  1. tests/test_system_field.py +68 -0
tests/test_system_field.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ 测试 Anthropic API system 字段数组类型支持
4
+ """
5
+ import json
6
+ import requests
7
+
8
+ # 测试数据
9
+ test_cases = [
10
+ {
11
+ "name": "字符串类型 system",
12
+ "data": {
13
+ "model": "GLM-4.5",
14
+ "messages": [{"role": "user", "content": "你好"}],
15
+ "system": "你是一个有帮助的助手",
16
+ "max_tokens": 100
17
+ }
18
+ },
19
+ {
20
+ "name": "数组类型 system",
21
+ "data": {
22
+ "model": "GLM-4.5",
23
+ "messages": [{"role": "user", "content": "你好"}],
24
+ "system": [
25
+ {
26
+ "type": "text",
27
+ "text": "你是一个有帮助的助手",
28
+ "cache_control": {"type": "ephemeral"}
29
+ }
30
+ ],
31
+ "max_tokens": 100
32
+ }
33
+ }
34
+ ]
35
+
36
+ def test_system_field():
37
+ """测试 system 字段的不同格式"""
38
+ print("=== 测试 system 字段支持 ===\n")
39
+
40
+ for test_case in test_cases:
41
+ print(f"测试: {test_case['name']}")
42
+
43
+ try:
44
+ response = requests.post(
45
+ "http://localhost:8080/v1/messages",
46
+ headers={"x-api-key": "sk-your-api-key"},
47
+ json=test_case["data"],
48
+ timeout=10
49
+ )
50
+
51
+ if response.status_code == 200:
52
+ result = response.json()
53
+ print("✅ 成功")
54
+ print(f" 消息ID: {result.get('id')}")
55
+ print(f" 内容预览: {result['content'][0]['text'][:50]}...")
56
+ else:
57
+ print(f"❌ 失败 - 状态码: {response.status_code}")
58
+ print(f" 错误: {response.text}")
59
+
60
+ except Exception as e:
61
+ print(f"❌ 异常: {e}")
62
+
63
+ print()
64
+
65
+ if __name__ == "__main__":
66
+ print("请确保服务器正在运行在 http://localhost:8080")
67
+ input("按 Enter 开始测试...")
68
+ test_system_field()