From 4f2eae9c54921fd80ace34074683a5ef3cedf2ba Mon Sep 17 00:00:00 2001 From: rosariopf Date: Tue, 13 May 2025 12:02:37 +0100 Subject: [PATCH 1/4] fix(ai): pass FunctionDeclaration#description arg to internal class --- .../firebase/ai/type/FunctionDeclaration.kt | 2 +- .../ai/type/FunctionDeclarationTest.kt | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/FunctionDeclaration.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/FunctionDeclaration.kt index ded9f889d29..2b73d5ccfb1 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/FunctionDeclaration.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/FunctionDeclaration.kt @@ -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( diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt new file mode 100644 index 00000000000..c75212b85d6 --- /dev/null +++ b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt @@ -0,0 +1,81 @@ +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) + } + + +} \ No newline at end of file From 2428d4cb96b2145fd63662d4b8c9f5c67f65ed23 Mon Sep 17 00:00:00 2001 From: rosariopf Date: Tue, 13 May 2025 12:03:26 +0100 Subject: [PATCH 2/4] newline at EOF --- .../com/google/firebase/ai/type/FunctionDeclarationTest.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt index c75212b85d6..854bd384d08 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt @@ -76,6 +76,4 @@ internal class FunctionDeclarationTest { Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson) } - - -} \ No newline at end of file +} From 34d0912f75136bb3bcbc677b1f0184c5f3da508d Mon Sep 17 00:00:00 2001 From: rosariopf Date: Tue, 13 May 2025 12:23:23 +0100 Subject: [PATCH 3/4] fix formatting and add CHANGELOG entry --- firebase-ai/CHANGELOG.md | 1 + .../ai/type/FunctionDeclarationTest.kt | 43 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 8d26e6850f1..3783c47ba70 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -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. diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt index 854bd384d08..1fdeaa9d266 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt @@ -9,15 +9,15 @@ 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 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 = """ + val expectedJson = + """ { "name": "isUserAGoat", "description": "Determine if the user is subject to teleportations.", @@ -34,24 +34,28 @@ internal class FunctionDeclarationTest { ] } } - """.trimIndent() + """ + .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 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 = """ + val expectedJson = + """ { "name": "isUserAGoat", "description": "Determine if the user is subject to teleportations.", @@ -72,7 +76,8 @@ internal class FunctionDeclarationTest { ] } } - """.trimIndent() + """ + .trimIndent() Json.encodeToString(functionDeclaration.toInternal()).shouldEqualJson(expectedJson) } From 00b8b89c8db95902d8393be12f14a6ddfcd281d3 Mon Sep 17 00:00:00 2001 From: rosariopf Date: Tue, 13 May 2025 17:48:55 +0100 Subject: [PATCH 4/4] add copyright to new test file --- .../firebase/ai/type/FunctionDeclarationTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt index 1fdeaa9d266..7719044b498 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/type/FunctionDeclarationTest.kt @@ -1,3 +1,19 @@ +/* + * 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