File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
main/kotlin/com/google/firebase/vertexai
test/java/com/google/firebase/vertexai Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -195,7 +195,11 @@ internal constructor(
195
195
* @return A [CountTokensResponse] containing the amount of tokens in the prompt.
196
196
*/
197
197
suspend fun countTokens (vararg prompt : Content ): CountTokensResponse {
198
- return controller.countTokens(constructCountTokensRequest(* prompt)).toPublic()
198
+ try {
199
+ return controller.countTokens(constructCountTokensRequest(* prompt)).toPublic()
200
+ } catch (e: Throwable ) {
201
+ throw FirebaseVertexAIException .from(e)
202
+ }
199
203
}
200
204
201
205
/* *
Original file line number Diff line number Diff line change @@ -427,4 +427,10 @@ internal class UnarySnapshotTests {
427
427
response.totalBillableCharacters shouldBe 0
428
428
}
429
429
}
430
+
431
+ @Test
432
+ fun `countTokens fails with model not found` () =
433
+ goldenUnaryFile(" failure-model-not-found.json" , HttpStatusCode .NotFound ) {
434
+ withTimeout(testTimeout) { shouldThrow<ServerException > { model.countTokens(" prompt" ) } }
435
+ }
430
436
}
You can’t perform that action at this time.
0 commit comments