Skip to content

Commit 9c00477

Browse files
authored
fix(ai): pass FunctionDeclaration#description arg to internal class (#6957)
It seems like the value set in `FunctionDeclaration#description` was never making it to the API.
1 parent 331905b commit 9c00477

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API.
34

45
# 16.0.0
56
* [feature] Initial release of the Firebase AI SDK (`firebase-ai`). This SDK *replaces* the previous

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class FunctionDeclaration(
6161
internal val schema: Schema =
6262
Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)
6363

64-
internal fun toInternal() = Internal(name, "", schema.toInternal())
64+
internal fun toInternal() = Internal(name, description, schema.toInternal())
6565

6666
@Serializable
6767
internal data class Internal(
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.ai.type
18+
19+
import io.kotest.assertions.json.shouldEqualJson
20+
import kotlinx.serialization.encodeToString
21+
import kotlinx.serialization.json.Json
22+
import org.junit.Test
23+
24+
internal class FunctionDeclarationTest {
25+
26+
@Test
27+
fun `Basic FunctionDeclaration with name, description and parameters`() {
28+
val functionDeclaration =
29+
FunctionDeclaration(
30+
name = "isUserAGoat",
31+
description = "Determine if the user is subject to teleportations.",
32+
parameters = mapOf("userID" to Schema.string("ID of the User making the call"))
33+
)
34+
35+
val expectedJson =
36+
"""
37+
{
38+
"name": "isUserAGoat",
39+
"description": "Determine if the user is subject to teleportations.",
40+
"parameters": {
41+
"type": "OBJECT",
42+
"properties": {
43+
"userID": {
44+
"type": "STRING",
45+
"description": "ID of the User making the call"
46+
}
47+
},
48+
"required": [
49+
"userID"
50+
]
51+
}
52+
}
53+
"""
54+
.trimIndent()
55+
56+
Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson)
57+
}
58+
59+
@Test
60+
fun `FunctionDeclaration with optional parameters`() {
61+
val functionDeclaration =
62+
FunctionDeclaration(
63+
name = "isUserAGoat",
64+
description = "Determine if the user is subject to teleportations.",
65+
parameters =
66+
mapOf(
67+
"userID" to Schema.string("ID of the user making the call"),
68+
"userName" to Schema.string("Name of the user making the call")
69+
),
70+
optionalParameters = listOf("userName")
71+
)
72+
73+
val expectedJson =
74+
"""
75+
{
76+
"name": "isUserAGoat",
77+
"description": "Determine if the user is subject to teleportations.",
78+
"parameters": {
79+
"type": "OBJECT",
80+
"properties": {
81+
"userID": {
82+
"type": "STRING",
83+
"description": "ID of the user making the call"
84+
},
85+
"userName": {
86+
"type": "STRING",
87+
"description": "Name of the user making the call"
88+
}
89+
},
90+
"required": [
91+
"userID"
92+
]
93+
}
94+
}
95+
"""
96+
.trimIndent()
97+
98+
Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson)
99+
}
100+
}

0 commit comments

Comments
 (0)