From 9cfc04a47187ff2cc28294808421c9e22c4415f9 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Mon, 3 Jun 2024 15:11:19 -0700 Subject: [PATCH 1/4] wire through new countTokenRequest --- .../com/google/firebase/vertexai/GenerativeModel.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt index 048964c8297..00f93aad0e4 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt @@ -19,7 +19,7 @@ package com.google.firebase.vertexai import android.graphics.Bitmap import android.util.Log import com.google.ai.client.generativeai.common.APIController -import com.google.ai.client.generativeai.common.CountTokensRequest +import com.google.ai.client.generativeai.common.VertexCountTokensRequest import com.google.ai.client.generativeai.common.GenerateContentRequest import com.google.ai.client.generativeai.common.HeaderProvider import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider @@ -195,7 +195,7 @@ internal constructor( * @return A [CountTokensResponse] containing the amount of tokens in the prompt. */ suspend fun countTokens(vararg prompt: Content): CountTokensResponse { - return controller.countTokens(constructCountTokensRequest(*prompt)).toPublic() + return controller.vertexCountTokens(constructCountTokensRequest(*prompt)).toPublic() } /** @@ -230,7 +230,11 @@ internal constructor( ) private fun constructCountTokensRequest(vararg prompt: Content) = - CountTokensRequest(modelName, prompt.map { it.toInternal() }) + VertexCountTokensRequest( + modelName, + prompt.map { it.toInternal() }, + systemInstruction?.toInternal(), + tools?.map { it.toInternal() }) private fun GenerateContentResponse.validate() = apply { if (candidates.isEmpty() && promptFeedback == null) { From cef8e6b482a0839aaf6f4b2bfeee1a11aa6c0cfa Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 4 Jun 2024 10:01:30 -0700 Subject: [PATCH 2/4] reduce code change with overlapping object --- .../com/google/firebase/vertexai/GenerativeModel.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt index 00f93aad0e4..2c836cea7fb 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt @@ -195,7 +195,7 @@ internal constructor( * @return A [CountTokensResponse] containing the amount of tokens in the prompt. */ suspend fun countTokens(vararg prompt: Content): CountTokensResponse { - return controller.vertexCountTokens(constructCountTokensRequest(*prompt)).toPublic() + return controller.countTokens(constructCountTokensRequest(*prompt)).toPublic() } /** @@ -230,11 +230,11 @@ internal constructor( ) private fun constructCountTokensRequest(vararg prompt: Content) = - VertexCountTokensRequest( - modelName, - prompt.map { it.toInternal() }, - systemInstruction?.toInternal(), - tools?.map { it.toInternal() }) + CountTokensRequest( + model = modelName, + contents = prompt.map { it.toInternal() }, + systemInstruction = systemInstruction?.toInternal(), + tools = tools?.map { it.toInternal() }) private fun GenerateContentResponse.validate() = apply { if (candidates.isEmpty() && promptFeedback == null) { From c4d5ddc2485ace915935f630d527b7bde14de7cd Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 4 Jun 2024 11:09:16 -0700 Subject: [PATCH 3/4] ktfmt --- .../kotlin/com/google/firebase/vertexai/GenerativeModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt index 2c836cea7fb..d7ffbffc7ac 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt @@ -19,7 +19,6 @@ package com.google.firebase.vertexai import android.graphics.Bitmap import android.util.Log import com.google.ai.client.generativeai.common.APIController -import com.google.ai.client.generativeai.common.VertexCountTokensRequest import com.google.ai.client.generativeai.common.GenerateContentRequest import com.google.ai.client.generativeai.common.HeaderProvider import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider @@ -234,7 +233,8 @@ internal constructor( model = modelName, contents = prompt.map { it.toInternal() }, systemInstruction = systemInstruction?.toInternal(), - tools = tools?.map { it.toInternal() }) + tools = tools?.map { it.toInternal() } + ) private fun GenerateContentResponse.validate() = apply { if (candidates.isEmpty() && promptFeedback == null) { From 67fea4f2c1e0fa2c4940d0c0ecbe1c6f093b884f Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 7 Jun 2024 12:27:56 -0700 Subject: [PATCH 4/4] update to match genai pr --- .../com/google/firebase/vertexai/GenerativeModel.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt index d7ffbffc7ac..4cb667a2270 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt @@ -19,6 +19,7 @@ package com.google.firebase.vertexai import android.graphics.Bitmap import android.util.Log import com.google.ai.client.generativeai.common.APIController +import com.google.ai.client.generativeai.common.CountTokensRequest import com.google.ai.client.generativeai.common.GenerateContentRequest import com.google.ai.client.generativeai.common.HeaderProvider import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider @@ -229,12 +230,7 @@ internal constructor( ) private fun constructCountTokensRequest(vararg prompt: Content) = - CountTokensRequest( - model = modelName, - contents = prompt.map { it.toInternal() }, - systemInstruction = systemInstruction?.toInternal(), - tools = tools?.map { it.toInternal() } - ) + CountTokensRequest.forVertexAI(constructRequest(*prompt)) private fun GenerateContentResponse.validate() = apply { if (candidates.isEmpty() && promptFeedback == null) {