@@ -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