forked from ziozzang/llm-toolcall-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_glm_formats.py
More file actions
126 lines (102 loc) · 3.17 KB
/
Copy pathtest_glm_formats.py
File metadata and controls
126 lines (102 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
Test new GLM tool calling formats with debugging
"""
from converters.glm import GLMToolCallConverter
def test_new_format():
"""Test new [TOOL_REQUEST] format"""
print("Testing New [TOOL_REQUEST] Format")
print("=" * 50)
converter = GLMToolCallConverter()
# Test case 1: Single parameter
content1 = '''
[TOOL_REQUEST]
{"name": "fetch_wikipedia_content", "arguments": {"search_query":"Namsan Seoul historical buildings"}}
[END_TOOL_REQUEST]
'''
print("Test 1: New format single parameter")
tool_calls = converter.parse_tool_calls(content1)
print(f"Result: {len(tool_calls)} tool calls")
print()
# Test case 2: Multiple parameters
content2 = '''
[TOOL_REQUEST]
{"name": "search_function", "arguments": {"query":"test query", "limit":10, "category":"books"}}
[END_TOOL_REQUEST]
'''
print("Test 2: New format multiple parameters")
tool_calls = converter.parse_tool_calls(content2)
print(f"Result: {len(tool_calls)} tool calls")
print()
def test_legacy_multi_param():
"""Test legacy format with multiple parameters"""
print("Testing Legacy Multi-Parameter Format")
print("=" * 50)
converter = GLMToolCallConverter()
# Test case: Multiple arg_key/arg_value pairs
content = '''
<tool_call>
search_function
<arg_key>query</arg_key>
<arg_value>test search</arg_value>
<arg_key>limit</arg_key>
<arg_value>5</arg_value>
<arg_key>category</arg_key>
<arg_value>science</arg_value>
</tool_call>
'''
print("Test: Legacy format multiple parameters")
tool_calls = converter.parse_tool_calls(content)
print(f"Result: {len(tool_calls)} tool calls")
print()
def test_multiline_json():
"""Test multiline JSON in new format"""
print("Testing Multiline JSON Format")
print("=" * 50)
converter = GLMToolCallConverter()
# Test case: Multiline JSON (common cause of parsing errors)
content = '''
[TOOL_REQUEST]
{
"name": "fetch_wikipedia_content",
"arguments": {
"search_query": "Seoul historical buildings",
"language": "en",
"limit": 3
}
}
[END_TOOL_REQUEST]
'''
print("Test: Multiline JSON format")
tool_calls = converter.parse_tool_calls(content)
print(f"Result: {len(tool_calls)} tool calls")
print()
def test_mixed_formats():
"""Test content with both formats"""
print("Testing Mixed Formats")
print("=" * 50)
converter = GLMToolCallConverter()
content = '''
First, I need to search for information.
[TOOL_REQUEST]
{"name": "search_info", "arguments": {"query": "test"}}
[END_TOOL_REQUEST]
Now let me use the legacy format too:
<tool_call>
legacy_function
<arg_key>param1</arg_key>
<arg_value>value1</arg_value>
</tool_call>
'''
print("Test: Mixed formats in same content")
tool_calls = converter.parse_tool_calls(content)
print(f"Result: {len(tool_calls)} tool calls")
print()
if __name__ == "__main__":
test_new_format()
test_legacy_multi_param()
test_multiline_json()
test_mixed_formats()
print("=" * 50)
print("GLM Format Testing Complete")
print("Check debug output above for detailed parsing information")