Skip to content

Commit 3c0c2c4

Browse files
committed
add code exeuction parts
1 parent 5487034 commit 3c0c2c4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerateContentResponse.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public class GenerateContentResponse(
4444
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
4545
}
4646

47+
/**
48+
* Convenience field to list all the [CodeExecutionResultPart]s in the response, if they exist.
49+
*/
50+
public val codeExecutionResults: List<CodeExecutionResultPart> by lazy {
51+
candidates.first().content.parts.filterIsInstance<CodeExecutionResultPart>()
52+
}
53+
54+
/** Convenience field to list all the [ExecutableCodePart]s in the response, if they exist. */
55+
public val executableCodeList: List<ExecutableCodePart> by lazy {
56+
candidates.first().content.parts.filterIsInstance<ExecutableCodePart>()
57+
}
58+
4759
/**
4860
* Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist.
4961
*

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Tool.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import kotlinx.serialization.json.JsonObject
2626
public class Tool
2727
internal constructor(
2828
internal val functionDeclarations: List<FunctionDeclaration>?,
29-
internal val googleSearch: GoogleSearch?
29+
internal val googleSearch: GoogleSearch?,
30+
internal val codeExecution: JsonObject?,
3031
) {
3132
internal fun toInternal() =
3233
Internal(
3334
functionDeclarations?.map { it.toInternal() } ?: emptyList(),
34-
googleSearch = this.googleSearch?.toInternal()
35+
googleSearch = this.googleSearch?.toInternal(),
36+
codeExecution = this.codeExecution
3537
)
3638
@Serializable
3739
internal data class Internal(
@@ -49,7 +51,12 @@ internal constructor(
4951
*/
5052
@JvmStatic
5153
public fun functionDeclarations(functionDeclarations: List<FunctionDeclaration>): Tool {
52-
return Tool(functionDeclarations, null)
54+
return Tool(functionDeclarations, null, null)
55+
}
56+
57+
@JvmStatic
58+
public fun codeExecution(): Tool {
59+
return Tool(null, null, JsonObject(emptyMap()))
5360
}
5461

5562
/**
@@ -70,7 +77,7 @@ internal constructor(
7077
*/
7178
@JvmStatic
7279
public fun googleSearch(googleSearch: GoogleSearch = GoogleSearch()): Tool {
73-
return Tool(null, googleSearch)
80+
return Tool(null, googleSearch, null)
7481
}
7582
}
7683
}

0 commit comments

Comments
 (0)