@@ -39,6 +39,35 @@ public class TextPart(public val text: String) : Part {
39
39
@Serializable internal data class Internal (val text : String ) : InternalPart
40
40
}
41
41
42
+ public class CodeExecutionResultPart (public val outcome : String , public val output : String ) : Part {
43
+
44
+ @Serializable
45
+ internal data class Internal (
46
+ @SerialName(" codeExecutionResult" ) val codeExecutionResult : CodeExecutionResult
47
+ ) : InternalPart {
48
+
49
+ @Serializable
50
+ internal data class CodeExecutionResult (
51
+ @SerialName(" outcome" ) val outcome : String ,
52
+ val output : String
53
+ )
54
+ }
55
+ }
56
+
57
+ public class ExecutableCodePart (public val language : String , public val code : String ) : Part {
58
+
59
+ @Serializable
60
+ internal data class Internal (@SerialName(" executableCode" ) val executableCode : ExecutableCode ) :
61
+ InternalPart {
62
+
63
+ @Serializable
64
+ internal data class ExecutableCode (
65
+ @SerialName(" language" ) val language : String ,
66
+ val code : String
67
+ )
68
+ }
69
+ }
70
+
42
71
/* *
43
72
* Represents image data sent to and received from requests. The image is converted client-side to
44
73
* JPEG encoding at 80% quality before being sent to the server.
@@ -176,6 +205,8 @@ internal object PartSerializer :
176
205
val jsonObject = element.jsonObject
177
206
return when {
178
207
" text" in jsonObject -> TextPart .Internal .serializer()
208
+ " executableCode" in jsonObject -> ExecutableCodePart .Internal .serializer()
209
+ " codeExecutionResult" in jsonObject -> CodeExecutionResultPart .Internal .serializer()
179
210
" functionCall" in jsonObject -> FunctionCallPart .Internal .serializer()
180
211
" functionResponse" in jsonObject -> FunctionResponsePart .Internal .serializer()
181
212
" inlineData" in jsonObject -> InlineDataPart .Internal .serializer()
@@ -207,6 +238,12 @@ internal fun Part.toInternal(): InternalPart {
207
238
)
208
239
is FileDataPart ->
209
240
FileDataPart .Internal (FileDataPart .Internal .FileData (mimeType = mimeType, fileUri = uri))
241
+ is ExecutableCodePart ->
242
+ ExecutableCodePart .Internal (ExecutableCodePart .Internal .ExecutableCode (language, code))
243
+ is CodeExecutionResultPart ->
244
+ CodeExecutionResultPart .Internal (
245
+ CodeExecutionResultPart .Internal .CodeExecutionResult (outcome, output)
246
+ )
210
247
else ->
211
248
throw com.google.firebase.ai.type.SerializationException (
212
249
" The given subclass of Part (${javaClass.simpleName} ) is not supported in the serialization yet."
@@ -241,6 +278,10 @@ internal fun InternalPart.toPublic(): Part {
241
278
is FunctionResponsePart .Internal ->
242
279
FunctionResponsePart (functionResponse.name, functionResponse.response, functionResponse.id)
243
280
is FileDataPart .Internal -> FileDataPart (fileData.mimeType, fileData.fileUri)
281
+ is ExecutableCodePart .Internal ->
282
+ ExecutableCodePart (executableCode.language, executableCode.code)
283
+ is CodeExecutionResultPart .Internal ->
284
+ CodeExecutionResultPart (codeExecutionResult.outcome, codeExecutionResult.output)
244
285
else ->
245
286
throw com.google.firebase.ai.type.SerializationException (
246
287
" Unsupported part type \" ${javaClass.simpleName} \" provided. This model may not be supported by this SDK."
0 commit comments