Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire through new countTokenRequest #6011

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
Loading