@@ -48,15 +48,16 @@ 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
52
let generationConfig = GenerationConfig (
53
53
temperature: temperature,
54
54
topP: topP,
55
55
topK: topK,
56
56
candidateCount: candidateCount,
57
57
maxOutputTokens: maxOutputTokens,
58
58
stopSequences: stopSequences,
59
- responseMIMEType: responseMIMEType
59
+ responseMIMEType: responseMIMEType,
60
+ responseSchema: Schema ( type: . array, items: Schema ( type: . string) )
60
61
)
61
62
62
63
let jsonData = try encoder. encode ( generationConfig)
@@ -67,6 +68,12 @@ final class GenerationConfigTests: XCTestCase {
67
68
" candidateCount " : \( candidateCount) ,
68
69
" maxOutputTokens " : \( maxOutputTokens) ,
69
70
" responseMIMEType " : " \( responseMIMEType) " ,
71
+ " responseSchema " : {
72
+ " items " : {
73
+ " type " : " STRING "
74
+ },
75
+ " type " : " ARRAY "
76
+ },
70
77
" stopSequences " : [
71
78
" END " ,
72
79
" DONE "
@@ -78,16 +85,46 @@ final class GenerationConfigTests: XCTestCase {
78
85
""" )
79
86
}
80
87
81
- func testEncodeGenerationConfig_responseMIMEType( ) throws {
82
- let mimeType = " image/jpeg "
83
- let generationConfig = GenerationConfig ( responseMIMEType: mimeType)
88
+ func testEncodeGenerationConfig_jsonResponse( ) throws {
89
+ let mimeType = " application/json "
90
+ let generationConfig = GenerationConfig (
91
+ responseMIMEType: mimeType,
92
+ responseSchema: Schema (
93
+ type: . object,
94
+ properties: [
95
+ " firstName " : Schema ( type: . string) ,
96
+ " lastName " : Schema ( type: . string) ,
97
+ " age " : Schema ( type: . integer) ,
98
+ ] ,
99
+ requiredProperties: [ " firstName " , " lastName " , " age " ]
100
+ )
101
+ )
84
102
85
103
let jsonData = try encoder. encode ( generationConfig)
86
104
87
105
let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
88
106
XCTAssertEqual ( json, """
89
107
{
90
- " responseMIMEType " : " \( mimeType) "
108
+ " responseMIMEType " : " \( mimeType) " ,
109
+ " responseSchema " : {
110
+ " properties " : {
111
+ " age " : {
112
+ " type " : " INTEGER "
113
+ },
114
+ " firstName " : {
115
+ " type " : " STRING "
116
+ },
117
+ " lastName " : {
118
+ " type " : " STRING "
119
+ }
120
+ },
121
+ " required " : [
122
+ " firstName " ,
123
+ " lastName " ,
124
+ " age "
125
+ ],
126
+ " type " : " OBJECT "
127
+ }
91
128
}
92
129
""" )
93
130
}
0 commit comments