Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions firebase-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
* [feature] Added support for the `id` field on `FunctionResponsePart` and `FunctionCallPart`. (#6910)
* [feature] Add support for specifying response modalities in `GenerationConfig`. (#6921)
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6922)
* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class FunctionDeclaration(
internal val schema: Schema =
Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)

internal fun toInternal() = Internal(name, "", schema.toInternal())
internal fun toInternal() = Internal(name, description, schema.toInternal())

@Serializable
internal data class Internal(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.ai.type

import io.kotest.assertions.json.shouldEqualJson
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.Test

internal class FunctionDeclarationTest {

@Test
fun `Basic FunctionDeclaration with name, description and parameters`() {
val functionDeclaration =
FunctionDeclaration(
name = "isUserAGoat",
description = "Determine if the user is subject to teleportations.",
parameters = mapOf("userID" to Schema.string("ID of the User making the call"))
)

val expectedJson =
"""
{
"name": "isUserAGoat",
"description": "Determine if the user is subject to teleportations.",
"parameters": {
"type": "OBJECT",
"properties": {
"userID": {
"type": "STRING",
"description": "ID of the User making the call"
}
},
"required": [
"userID"
]
}
}
"""
.trimIndent()

Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson)
}

@Test
fun `FunctionDeclaration with optional parameters`() {
val functionDeclaration =
FunctionDeclaration(
name = "isUserAGoat",
description = "Determine if the user is subject to teleportations.",
parameters =
mapOf(
"userID" to Schema.string("ID of the user making the call"),
"userName" to Schema.string("Name of the user making the call")
),
optionalParameters = listOf("userName")
)

val expectedJson =
"""
{
"name": "isUserAGoat",
"description": "Determine if the user is subject to teleportations.",
"parameters": {
"type": "OBJECT",
"properties": {
"userID": {
"type": "STRING",
"description": "ID of the user making the call"
},
"userName": {
"type": "STRING",
"description": "Name of the user making the call"
}
},
"required": [
"userID"
]
}
}
"""
.trimIndent()

Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson)
}
}
Loading