@@ -48,15 +48,20 @@ final class GenerationConfigTests: XCTestCase {
48
48
let candidateCount = 2
49
49
let maxOutputTokens = 256
50
50
let stopSequences = [ " END " , " DONE " ]
51
- let responseMIMEType = " text/plain "
51
+ let responseMIMEType = " application/json "
52
+ let schemaType = DataType . object
53
+ let fieldName = " test-field "
54
+ let fieldType = DataType . string
55
+ let responseSchema = Schema ( type: schemaType, properties: [ fieldName: Schema ( type: fieldType) ] )
52
56
let generationConfig = GenerationConfig (
53
57
temperature: temperature,
54
58
topP: topP,
55
59
topK: topK,
56
60
candidateCount: candidateCount,
57
61
maxOutputTokens: maxOutputTokens,
58
62
stopSequences: stopSequences,
59
- responseMIMEType: responseMIMEType
63
+ responseMIMEType: responseMIMEType,
64
+ responseSchema: responseSchema
60
65
)
61
66
62
67
let jsonData = try encoder. encode ( generationConfig)
@@ -67,6 +72,14 @@ final class GenerationConfigTests: XCTestCase {
67
72
" candidateCount " : \( candidateCount) ,
68
73
" maxOutputTokens " : \( maxOutputTokens) ,
69
74
" responseMIMEType " : " \( responseMIMEType) " ,
75
+ " responseSchema " : {
76
+ " properties " : {
77
+ " \( fieldName) " : {
78
+ " type " : " \( fieldType. rawValue) "
79
+ }
80
+ },
81
+ " type " : " \( schemaType. rawValue) "
82
+ },
70
83
" stopSequences " : [
71
84
" END " ,
72
85
" DONE "
@@ -79,7 +92,7 @@ final class GenerationConfigTests: XCTestCase {
79
92
}
80
93
81
94
func testEncodeGenerationConfig_responseMIMEType( ) throws {
82
- let mimeType = " image/jpeg "
95
+ let mimeType = " text/plain "
83
96
let generationConfig = GenerationConfig ( responseMIMEType: mimeType)
84
97
85
98
let jsonData = try encoder. encode ( generationConfig)
@@ -91,4 +104,27 @@ final class GenerationConfigTests: XCTestCase {
91
104
}
92
105
""" )
93
106
}
107
+
108
+ func testEncodeGenerationConfig_responseMIMETypeWithSchema( ) throws {
109
+ let mimeType = " application/json "
110
+ let schemaType = DataType . array
111
+ let arrayItemType = DataType . integer
112
+ let schema = Schema ( type: schemaType, items: Schema ( type: arrayItemType) )
113
+ let generationConfig = GenerationConfig ( responseMIMEType: mimeType, responseSchema: schema)
114
+
115
+ let jsonData = try encoder. encode ( generationConfig)
116
+
117
+ let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
118
+ XCTAssertEqual ( json, """
119
+ {
120
+ " responseMIMEType " : " \( mimeType) " ,
121
+ " responseSchema " : {
122
+ " items " : {
123
+ " type " : " \( arrayItemType. rawValue) "
124
+ },
125
+ " type " : " \( schemaType. rawValue) "
126
+ }
127
+ }
128
+ """ )
129
+ }
94
130
}
0 commit comments