From efec09dd0384cfa6a80a4952a43cc834b4619f1f Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Mon, 13 May 2024 14:15:02 -0400 Subject: [PATCH 1/2] Bump vertex version to beta01 --- vertexai/app/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vertexai/app/build.gradle.kts b/vertexai/app/build.gradle.kts index 910d35de1..bfdbe2ce2 100644 --- a/vertexai/app/build.gradle.kts +++ b/vertexai/app/build.gradle.kts @@ -67,7 +67,7 @@ dependencies { implementation("io.coil-kt:coil-compose:2.5.0") implementation("com.google.firebase:firebase-analytics:21.6.1") - implementation("com.google.firebase:firebase-vertexai:16.0.0-alpha03") + implementation("com.google.firebase:firebase-vertexai:16.0.0-beta01") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") From c8995f7b7953e4aa067ef555ffbc321dad2c86d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20P=2E=20Fernandes?= Date: Mon, 13 May 2024 21:07:43 +0100 Subject: [PATCH 2/2] get first function call --- .../feature/functioncalling/FunctionsChatViewModel.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/functioncalling/FunctionsChatViewModel.kt b/vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/functioncalling/FunctionsChatViewModel.kt index fee83fe0d..eb2c50dae 100644 --- a/vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/functioncalling/FunctionsChatViewModel.kt +++ b/vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/functioncalling/FunctionsChatViewModel.kt @@ -73,15 +73,18 @@ class FunctionsChatViewModel( var response = chat.sendMessage("What would be the uppercase representation of the following text: $userMessage") - if (response.functionCall != null) { + // Getting the first matched function call + val firstFunctionCall = response.functionCalls.firstOrNull() + + if (firstFunctionCall != null) { val matchingFunction = generativeModel.tools?.flatMap { it.functionDeclarations } - ?.first { it.name == response.functionCall?.name } + ?.first { it.name == firstFunctionCall.name } ?: throw InvalidStateException( - "Model requested nonexistent function \"${response.functionCall?.name}\" " + "Model requested nonexistent function \"${firstFunctionCall.name}\" " ) - val funResult = matchingFunction.execute(response.functionCall!!) + val funResult = matchingFunction.execute(firstFunctionCall) response = chat.sendMessage( content(role = "function") {