Skip to content

Commit 151aff0

Browse files
committed
Add disabled tool use test
1 parent f7277e2 commit 151aff0

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

Tests/TokenizersTests/ChatTemplateTests.swift

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,66 @@ class ChatTemplateTests: XCTestCase {
8080
XCTAssertEqual(decoded, decodedTarget)
8181
}
8282

83-
// TODO: Add tests for tool use template
83+
// This test fails because of Swift's non-deterministic key order in dictionaries. We're already testing tool use templates in Swift Jinja.
84+
85+
// func testQwen2_5WithTools() async throws {
86+
// let tokenizer = try await AutoTokenizer.from(pretrained: "mlx-community/Qwen2.5-7B-Instruct-4bit")
87+
//
88+
// let weatherQueryMessages: [[String: String]] = [
89+
// [
90+
// "role": "user",
91+
// "content": "What is the weather in Paris today?",
92+
// ]
93+
// ]
94+
//
95+
// let getCurrentWeatherToolSpec: [String: Any] = [
96+
// "type": "function",
97+
// "function": [
98+
// "name": "get_current_weather",
99+
// "description": "Get the current weather in a given location",
100+
// "parameters": [
101+
// "type": "object",
102+
// "properties": [
103+
// "location": [
104+
// "type": "string",
105+
// "description": "The city and state, e.g. San Francisco, CA"
106+
// ],
107+
// "unit": [
108+
// "type": "string",
109+
// "enum": ["celsius", "fahrenheit"]
110+
// ]
111+
// ],
112+
// "required": ["location"]
113+
// ]
114+
// ]
115+
// ]
116+
//
117+
// let encoded = try tokenizer.applyChatTemplate(messages: weatherQueryMessages, tools: [getCurrentWeatherToolSpec])
118+
// let decoded = tokenizer.decode(tokens: encoded)
119+
//
120+
// let target = """
121+
//<|im_start|>system
122+
//You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
123+
//
124+
//# Tools
125+
//
126+
//You may call one or more functions to assist with the user query.
127+
//
128+
//You are provided with function signatures within <tools></tools> XML tags:
129+
//<tools>
130+
//{"type": "function", "function": {"name": "get_current_weather", "parameters": {"type": "object", "required": ["location"], "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}}}, "description": "Get the current weather in a given location"}}
131+
//</tools>
132+
//
133+
//For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
134+
//<tool_call>
135+
//{"name": <function-name>, "arguments": <args-json-object>}
136+
//</tool_call><|im_end|>
137+
//<|im_start|>user
138+
//What is the weather in Paris today?<|im_end|>
139+
//<|im_start|>assistant
140+
//
141+
//"""
142+
//
143+
// XCTAssertEqual(decoded, target)
144+
// }
84145
}

0 commit comments

Comments
 (0)