@@ -37,16 +37,17 @@ public interface Part {
37
37
38
38
/* * Represents text or string based data sent to and received from requests. */
39
39
public class TextPart
40
- private constructor (public val text: String , public override val isThought: Boolean = false ) :
40
+ internal constructor (public val text: String , public override val isThought: Boolean = false ) :
41
41
Part {
42
42
43
43
public constructor (text: String ) : this (text, false )
44
44
45
- @Serializable internal data class Internal (val text : String ) : InternalPart
45
+ @Serializable
46
+ internal data class Internal (val text : String , val thought : Boolean? = null ) : InternalPart
46
47
}
47
48
48
49
public class CodeExecutionResultPart
49
- private constructor (
50
+ internal constructor (
50
51
public val outcome: String ,
51
52
public val output: String ,
52
53
public override val isThought: Boolean = false
@@ -62,13 +63,14 @@ private constructor(
62
63
@Serializable
63
64
internal data class CodeExecutionResult (
64
65
@SerialName(" outcome" ) val outcome : String ,
65
- val output : String
66
+ val output : String ,
67
+ val thought : Boolean? = null
66
68
)
67
69
}
68
70
}
69
71
70
72
public class ExecutableCodePart
71
- private constructor (
73
+ internal constructor (
72
74
public val language: String ,
73
75
public val code: String ,
74
76
public override val isThought: Boolean = false
@@ -83,7 +85,8 @@ private constructor(
83
85
@Serializable
84
86
internal data class ExecutableCode (
85
87
@SerialName(" language" ) val language : String ,
86
- val code : String
88
+ val code : String ,
89
+ val thought : Boolean? = null
87
90
)
88
91
}
89
92
}
@@ -95,15 +98,16 @@ private constructor(
95
98
* @param image [Bitmap] to convert into a [Part]
96
99
*/
97
100
public class ImagePart
98
- private constructor (public val image: Bitmap , public override val isThought: Boolean = false ) :
101
+ internal constructor (public val image: Bitmap , public override val isThought: Boolean = false ) :
99
102
Part {
100
103
101
104
public constructor (image: Bitmap ) : this (image, false )
102
105
103
106
internal fun toInlineDataPart () =
104
107
InlineDataPart (
105
108
android.util.Base64 .decode(encodeBitmapToBase64Jpeg(image), BASE_64_FLAGS ),
106
- " image/jpeg"
109
+ " image/jpeg" ,
110
+ isThought
107
111
)
108
112
}
109
113
@@ -115,7 +119,7 @@ private constructor(public val image: Bitmap, public override val isThought: Boo
115
119
* [Vertex AI documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-multimodal-prompts#media_requirements)
116
120
*/
117
121
public class InlineDataPart
118
- private constructor (
122
+ internal constructor (
119
123
public val inlineData: ByteArray ,
120
124
public val mimeType: String ,
121
125
public override val isThought: Boolean = false
@@ -128,7 +132,11 @@ private constructor(
128
132
InternalPart {
129
133
130
134
@Serializable
131
- internal data class InlineData (@SerialName(" mimeType" ) val mimeType : String , val data : Base64 )
135
+ internal data class InlineData (
136
+ @SerialName(" mimeType" ) val mimeType : String ,
137
+ val data : Base64 ,
138
+ val thought : Boolean? = null
139
+ )
132
140
}
133
141
}
134
142
@@ -141,7 +149,7 @@ private constructor(
141
149
* have a matching `id` field.
142
150
*/
143
151
public class FunctionCallPart
144
- private constructor (
152
+ internal constructor (
145
153
public val name: String ,
146
154
public val args: Map <String , JsonElement >,
147
155
public val id: String? = null ,
@@ -162,7 +170,8 @@ private constructor(
162
170
internal data class FunctionCall (
163
171
val name : String ,
164
172
val args : Map <String , JsonElement ?>? = null ,
165
- val id : String? = null
173
+ val id : String? = null ,
174
+ val thought : Boolean? = null
166
175
)
167
176
}
168
177
}
@@ -175,7 +184,7 @@ private constructor(
175
184
* @param id Matching `id` for a [FunctionCallPart], if one was provided.
176
185
*/
177
186
public class FunctionResponsePart
178
- private constructor (
187
+ internal constructor (
179
188
public val name: String ,
180
189
public val response: JsonObject ,
181
190
public val id: String? = null ,
@@ -196,12 +205,13 @@ private constructor(
196
205
internal data class FunctionResponse (
197
206
val name : String ,
198
207
val response : JsonObject ,
199
- val id : String? = null
208
+ val id : String? = null ,
209
+ val thought : Boolean? = null
200
210
)
201
211
}
202
212
203
213
internal fun toInternalFunctionCall (): Internal .FunctionResponse {
204
- return Internal .FunctionResponse (name, response, id)
214
+ return Internal .FunctionResponse (name, response, id, isThought )
205
215
}
206
216
}
207
217
@@ -214,7 +224,7 @@ private constructor(
214
224
* [Firebase documentation](https://firebase.google.com/docs/vertex-ai/input-file-requirements).
215
225
*/
216
226
public class FileDataPart
217
- private constructor (
227
+ internal constructor (
218
228
public val uri: String ,
219
229
public val mimeType: String ,
220
230
public override val isThought: Boolean = false
@@ -229,6 +239,7 @@ private constructor(
229
239
internal data class FileData (
230
240
@SerialName(" mime_type" ) val mimeType : String ,
231
241
@SerialName(" file_uri" ) val fileUri : String ,
242
+ val thought : Boolean? = null
232
243
)
233
244
}
234
245
}
@@ -270,31 +281,36 @@ internal object PartSerializer :
270
281
271
282
internal fun Part.toInternal (): InternalPart {
272
283
return when (this ) {
273
- is TextPart -> TextPart .Internal (text)
284
+ is TextPart -> TextPart .Internal (text, isThought )
274
285
is ImagePart ->
275
286
InlineDataPart .Internal (
276
- InlineDataPart .Internal .InlineData (" image/jpeg" , encodeBitmapToBase64Jpeg(image))
287
+ InlineDataPart .Internal .InlineData (" image/jpeg" , encodeBitmapToBase64Jpeg(image), isThought )
277
288
)
278
289
is InlineDataPart ->
279
290
InlineDataPart .Internal (
280
291
InlineDataPart .Internal .InlineData (
281
292
mimeType,
282
- android.util.Base64 .encodeToString(inlineData, BASE_64_FLAGS )
293
+ android.util.Base64 .encodeToString(inlineData, BASE_64_FLAGS ),
294
+ isThought
283
295
)
284
296
)
285
297
is FunctionCallPart ->
286
- FunctionCallPart .Internal (FunctionCallPart .Internal .FunctionCall (name, args, id))
298
+ FunctionCallPart .Internal (FunctionCallPart .Internal .FunctionCall (name, args, id, isThought ))
287
299
is FunctionResponsePart ->
288
300
FunctionResponsePart .Internal (
289
- FunctionResponsePart .Internal .FunctionResponse (name, response, id)
301
+ FunctionResponsePart .Internal .FunctionResponse (name, response, id, isThought )
290
302
)
291
303
is FileDataPart ->
292
- FileDataPart .Internal (FileDataPart .Internal .FileData (mimeType = mimeType, fileUri = uri))
304
+ FileDataPart .Internal (
305
+ FileDataPart .Internal .FileData (mimeType = mimeType, fileUri = uri, thought = isThought)
306
+ )
293
307
is ExecutableCodePart ->
294
- ExecutableCodePart .Internal (ExecutableCodePart .Internal .ExecutableCode (language, code))
308
+ ExecutableCodePart .Internal (
309
+ ExecutableCodePart .Internal .ExecutableCode (language, code, isThought)
310
+ )
295
311
is CodeExecutionResultPart ->
296
312
CodeExecutionResultPart .Internal (
297
- CodeExecutionResultPart .Internal .CodeExecutionResult (outcome, output)
313
+ CodeExecutionResultPart .Internal .CodeExecutionResult (outcome, output, isThought )
298
314
)
299
315
else ->
300
316
throw com.google.firebase.ai.type.SerializationException (
@@ -312,28 +328,43 @@ private fun encodeBitmapToBase64Jpeg(input: Bitmap): String {
312
328
313
329
internal fun InternalPart.toPublic (): Part {
314
330
return when (this ) {
315
- is TextPart .Internal -> TextPart (text)
331
+ is TextPart .Internal -> TextPart (text, thought ? : false )
316
332
is InlineDataPart .Internal -> {
317
333
val data = android.util.Base64 .decode(inlineData.data, BASE_64_FLAGS )
318
334
if (inlineData.mimeType.contains(" image" )) {
319
- ImagePart (decodeBitmapFromImage(data))
335
+ ImagePart (decodeBitmapFromImage(data), inlineData.thought ? : false )
320
336
} else {
321
- InlineDataPart (data, inlineData.mimeType)
337
+ InlineDataPart (data, inlineData.mimeType, inlineData.thought ? : false )
322
338
}
323
339
}
324
340
is FunctionCallPart .Internal ->
325
341
FunctionCallPart (
326
342
functionCall.name,
327
343
functionCall.args.orEmpty().mapValues { it.value ? : JsonNull },
328
- functionCall.id
344
+ functionCall.id,
345
+ functionCall.thought ? : false
329
346
)
330
347
is FunctionResponsePart .Internal ->
331
- FunctionResponsePart (functionResponse.name, functionResponse.response, functionResponse.id)
332
- is FileDataPart .Internal -> FileDataPart (fileData.mimeType, fileData.fileUri)
348
+ FunctionResponsePart (
349
+ functionResponse.name,
350
+ functionResponse.response,
351
+ functionResponse.id,
352
+ functionResponse.thought ? : false
353
+ )
354
+ is FileDataPart .Internal ->
355
+ FileDataPart (fileData.mimeType, fileData.fileUri, fileData.thought ? : false )
333
356
is ExecutableCodePart .Internal ->
334
- ExecutableCodePart (executableCode.language, executableCode.code)
357
+ ExecutableCodePart (
358
+ executableCode.language,
359
+ executableCode.code,
360
+ executableCode.thought ? : false
361
+ )
335
362
is CodeExecutionResultPart .Internal ->
336
- CodeExecutionResultPart (codeExecutionResult.outcome, codeExecutionResult.output)
363
+ CodeExecutionResultPart (
364
+ codeExecutionResult.outcome,
365
+ codeExecutionResult.output,
366
+ codeExecutionResult.thought ? : false
367
+ )
337
368
else ->
338
369
throw com.google.firebase.ai.type.SerializationException (
339
370
" Unsupported part type \" ${javaClass.simpleName} \" provided. This model may not be supported by this SDK."
0 commit comments