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") 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") {