@@ -48,15 +48,16 @@ final class GenerationConfigTests: XCTestCase {
4848 let candidateCount = 2
4949 let maxOutputTokens = 256
5050 let stopSequences = [ " END " , " DONE " ]
51- let responseMIMEType = " text/plain "
51+ let responseMIMEType = " application/json "
5252 let generationConfig = GenerationConfig (
5353 temperature: temperature,
5454 topP: topP,
5555 topK: topK,
5656 candidateCount: candidateCount,
5757 maxOutputTokens: maxOutputTokens,
5858 stopSequences: stopSequences,
59- responseMIMEType: responseMIMEType
59+ responseMIMEType: responseMIMEType,
60+ responseSchema: Schema ( type: . array, items: Schema ( type: . string) )
6061 )
6162
6263 let jsonData = try encoder. encode ( generationConfig)
@@ -67,6 +68,12 @@ final class GenerationConfigTests: XCTestCase {
6768 " candidateCount " : \( candidateCount) ,
6869 " maxOutputTokens " : \( maxOutputTokens) ,
6970 " responseMIMEType " : " \( responseMIMEType) " ,
71+ " responseSchema " : {
72+ " items " : {
73+ " type " : " STRING "
74+ },
75+ " type " : " ARRAY "
76+ },
7077 " stopSequences " : [
7178 " END " ,
7279 " DONE "
@@ -78,16 +85,46 @@ final class GenerationConfigTests: XCTestCase {
7885 """ )
7986 }
8087
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+ )
84102
85103 let jsonData = try encoder. encode ( generationConfig)
86104
87105 let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
88106 XCTAssertEqual ( json, """
89107 {
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+ }
91128 }
92129 """ )
93130 }
0 commit comments