Skip to content

Commit d3c77b2

Browse files
committed
format code
1 parent a02209a commit d3c77b2

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

Sources/Environment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,16 +860,16 @@ class Environment {
860860
guard let test = env.tests[testName.value] else {
861861
throw JinjaError.runtime("Unknown test '\(testName.value)'")
862862
}
863-
863+
864864
// Pre-compute additional arguments to avoid repeated array creation
865865
let additionalArgs = Array(args[2...])
866-
866+
867867
// Use compactMap for better functional style and performance
868868
let result = try arrayValue.value.compactMap { item -> (any RuntimeValue)? in
869869
let testArgs = [item] + additionalArgs
870870
return try !test(testArgs) ? item : nil
871871
}
872-
872+
873873
return ArrayValue(value: result)
874874
},
875875
"rejectattr": { args, env in

Tests/Templates/ChatTemplateTests.swift

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -890,48 +890,63 @@ final class ChatTemplateTests: XCTestCase {
890890
"""
891891
XCTAssertEqual(result, target)
892892
}
893-
893+
894894
func testQwen3CoderWithEnum() throws {
895895
let toolWithEnum: OrderedDictionary<String, Any> = [
896896
"type": "function",
897-
"function": OrderedDictionary<String, Any>(dictionaryLiteral:
898-
("name", "get_weather"),
897+
"function": OrderedDictionary<String, Any>(
898+
dictionaryLiteral: ("name", "get_weather"),
899899
("description", "Get weather information for a specified location"),
900-
("parameters", OrderedDictionary<String, Any>(dictionaryLiteral:
901-
("type", "object"),
902-
("properties", OrderedDictionary<String, Any>(dictionaryLiteral:
903-
("location", OrderedDictionary<String, Any>(dictionaryLiteral:
904-
("type", "string"),
905-
("description", "City and state, e.g. San Francisco, CA")
906-
)),
907-
("unit", OrderedDictionary<String, Any>(dictionaryLiteral:
908-
("type", "string"),
909-
("description", "Temperature unit"),
910-
("enum", ["celsius", "fahrenheit"])
911-
)),
912-
("format", OrderedDictionary<String, Any>(dictionaryLiteral:
913-
("type", "string"),
914-
("description", "Return format"),
915-
("enum", ["json", "text", "xml"])
916-
))
917-
)),
918-
("required", ["location"])
919-
))
920-
)
900+
(
901+
"parameters",
902+
OrderedDictionary<String, Any>(
903+
dictionaryLiteral: ("type", "object"),
904+
(
905+
"properties",
906+
OrderedDictionary<String, Any>(
907+
dictionaryLiteral: (
908+
"location",
909+
OrderedDictionary<String, Any>(
910+
dictionaryLiteral: ("type", "string"),
911+
("description", "City and state, e.g. San Francisco, CA")
912+
)
913+
),
914+
(
915+
"unit",
916+
OrderedDictionary<String, Any>(
917+
dictionaryLiteral: ("type", "string"),
918+
("description", "Temperature unit"),
919+
("enum", ["celsius", "fahrenheit"])
920+
)
921+
),
922+
(
923+
"format",
924+
OrderedDictionary<String, Any>(
925+
dictionaryLiteral: ("type", "string"),
926+
("description", "Return format"),
927+
("enum", ["json", "text", "xml"])
928+
)
929+
)
930+
)
931+
),
932+
("required", ["location"])
933+
)
934+
)
935+
),
921936
]
922-
937+
923938
let userMessage = [
924939
"role": "user",
925940
"content": "What's the weather like in Beijing today?",
926941
]
927-
942+
928943
let template = try Template(ChatTemplate.qwen3_coder)
929944
let result = try template.render([
930945
"messages": [userMessage],
931946
"tools": [toolWithEnum],
932947
"add_generation_prompt": true,
933948
])
934-
949+
935950
let target = """
936951
<|im_start|>system
937952
You are Qwen, a helpful AI assistant that can interact with a computer to solve tasks.
@@ -994,14 +1009,16 @@ final class ChatTemplateTests: XCTestCase {
9941009
"""
9951010
XCTAssertEqual(result, target)
9961011
}
997-
1012+
9981013
func testReject() throws {
999-
let template = try Template(#"""
1014+
let template = try Template(
1015+
#"""
10001016
{%- set handled_keys = ['type', 'description', 'enum', 'required'] %}
10011017
{%- set all_keys = ['type', 'name', 'enum', 'value', 'description', 'age', 'required', 'status'] %}
10021018
10031019
Filtered keys: {{ all_keys | reject("in", handled_keys) | list }}
1004-
"""#)
1020+
"""#
1021+
)
10051022
let result = try template.render([:])
10061023
print(result)
10071024
}

0 commit comments

Comments
 (0)