You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Tests/TokenizersTests/ChatTemplateTests.swift
+62-1Lines changed: 62 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -80,5 +80,66 @@ class ChatTemplateTests: XCTestCase {
80
80
XCTAssertEqual(decoded, decodedTarget)
81
81
}
82
82
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:
0 commit comments