1616
1717package com.google.firebase.ai.type
1818
19+ import kotlinx.serialization.InternalSerializationApi
1920import kotlinx.serialization.Serializable
2021
2122/* *
2223 * Contains a set of tools (like function declarations) that the server template model has access
2324 * to.
2425 */
2526public class TemplateTool
26- @OptIn(PublicPreviewAPI ::class )
27+ @OptIn(PublicPreviewAPI ::class , InternalSerializationApi :: class )
2728internal constructor (
2829 internal val functionDeclarations: List <TemplateFunctionDeclaration >? ,
2930 internal val autoFunctionDeclarations: List <TemplateAutoFunctionDeclaration <* , * >>? = null ,
31+ internal val googleMaps: GoogleMaps ? ,
3032) {
3133
3234 @OptIn(PublicPreviewAPI ::class )
@@ -36,11 +38,13 @@ internal constructor(
3638 functionDeclarations?.let { addAll(it.map { it.toInternal() }) }
3739 autoFunctionDeclarations?.let { addAll(it.map { it.toInternal() }) }
3840 },
41+ googleMaps?.toInternal(),
3942 )
4043
4144 @Serializable
4245 internal data class Internal (
4346 val templateFunctions : List <TemplateFunctionDeclaration .Internal >? = null ,
47+ val googleMaps : GoogleMaps .Internal ? = null ,
4448 )
4549
4650 public companion object {
@@ -56,7 +60,27 @@ internal constructor(
5660 functionDeclarations : List <TemplateFunctionDeclaration >,
5761 autoFunctionDeclarations : List <TemplateAutoFunctionDeclaration <* , * >>? = null,
5862 ): TemplateTool {
59- return TemplateTool (functionDeclarations, autoFunctionDeclarations)
63+ return TemplateTool (functionDeclarations, autoFunctionDeclarations, null )
64+ }
65+
66+ /* *
67+ * Creates a [TemplateTool] instance that allows the model to use grounding with Google Maps.
68+ *
69+ * Grounding with Google Maps can be used to allow the model to connect to Google Maps to
70+ * incorporate location-based information into its responses.
71+ *
72+ * When using this feature, you are required to comply with the "Grounding with Google Maps"
73+ * usage requirements for your chosen API provider:
74+ * [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or
75+ * Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms)
76+ * section within the Service Specific Terms).
77+ *
78+ * @return A [TemplateTool] configured for Google Maps.
79+ */
80+ @JvmStatic
81+ @JvmOverloads
82+ public fun googleMaps (googleMaps : GoogleMaps = GoogleMaps ()): TemplateTool {
83+ return TemplateTool (null , null , googleMaps)
6084 }
6185 }
6286}
@@ -127,8 +151,13 @@ internal constructor(
127151}
128152
129153/* * Config for template tools to use with server prompts. */
130- public class TemplateToolConfig {
131- internal fun toInternal (): ToolConfig .Internal ? {
132- return null // Empty config payload as defined in flutter API
154+ public class TemplateToolConfig public constructor(private val retrievalConfig : RetrievalConfig ? ) {
155+
156+ public constructor () : this (null )
157+ internal fun toInternal (): ToolConfig .Internal {
158+ return ToolConfig .Internal (
159+ functionCallingConfig = null ,
160+ retrievalConfig = retrievalConfig?.toInternal()
161+ )
133162 }
134163}
0 commit comments