Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public class GenerateContentResponse(
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
}

/**
* Convenience field to list all the [CodeExecutionResultPart]s in the response, if they exist.
*/
public val codeExecutionResults: List<CodeExecutionResultPart> by lazy {
candidates.first().content.parts.filterIsInstance<CodeExecutionResultPart>()
}

/** Convenience field to list all the [ExecutableCodePart]s in the response, if they exist. */
public val executableCodeList: List<ExecutableCodePart> by lazy {
candidates.first().content.parts.filterIsInstance<ExecutableCodePart>()
}

/**
* Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist.
*
Expand Down
15 changes: 11 additions & 4 deletions firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Tool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import kotlinx.serialization.json.JsonObject
public class Tool
internal constructor(
internal val functionDeclarations: List<FunctionDeclaration>?,
internal val googleSearch: GoogleSearch?
internal val googleSearch: GoogleSearch?,
internal val codeExecution: JsonObject?,
) {
internal fun toInternal() =
Internal(
functionDeclarations?.map { it.toInternal() } ?: emptyList(),
googleSearch = this.googleSearch?.toInternal()
googleSearch = this.googleSearch?.toInternal(),
codeExecution = this.codeExecution
)
@Serializable
internal data class Internal(
Expand All @@ -49,7 +51,12 @@ internal constructor(
*/
@JvmStatic
public fun functionDeclarations(functionDeclarations: List<FunctionDeclaration>): Tool {
return Tool(functionDeclarations, null)
return Tool(functionDeclarations, null, null)
}

@JvmStatic
public fun codeExecution(): Tool {
return Tool(null, null, JsonObject(emptyMap()))
}

/**
Expand All @@ -70,7 +77,7 @@ internal constructor(
*/
@JvmStatic
public fun googleSearch(googleSearch: GoogleSearch = GoogleSearch()): Tool {
return Tool(null, googleSearch)
return Tool(null, googleSearch, null)
}
}
}
Loading