Skip to content

Commit 19dd95b

Browse files
authored
[VertexAI] Remove redundant tests (#6762)
There is an extra copy of some tests inside ` test/.../common` directory. This change removes them, and in the process: - Adds missing tests to the correct test file - Gets rid of duplicated tests and test-util code - Adds an exception type for quota exceeded
1 parent bdb330e commit 19dd95b

File tree

8 files changed

+52
-642
lines changed

8 files changed

+52
-642
lines changed

firebase-vertexai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Unreleased
2+
* [changed] Added new exception type for quota exceeded scenarios.
23
* [feature] `CountTokenRequest` now includes `GenerationConfig` from the model.
34

5+
46
# 16.2.0
57
* [fixed] Added support for new values sent by the server for `FinishReason` and `BlockReason`.
68
* [changed] Added support for modality-based token count. (#6658)

firebase-vertexai/api.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ package com.google.firebase.vertexai.type {
557557
@kotlin.RequiresOptIn(level=kotlin.RequiresOptIn.Level.ERROR, message="This API is part of an experimental public preview and may change in " + "backwards-incompatible ways without notice.") @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) public @interface PublicPreviewAPI {
558558
}
559559

560+
public final class QuotaExceededException extends com.google.firebase.vertexai.type.FirebaseVertexAIException {
561+
}
562+
560563
public final class RequestOptions {
561564
ctor public RequestOptions();
562565
ctor public RequestOptions(long timeoutInMillis = 180.seconds.inWholeMilliseconds);

firebase-vertexai/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=16.2.1
15+
version=16.3.0
1616
latestReleasedVersion=16.2.0

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ internal constructor(message: String, cause: Throwable? = null) : RuntimeExcepti
5959
UnknownException(cause.message ?: "", cause.cause)
6060
is com.google.firebase.vertexai.common.ContentBlockedException ->
6161
ContentBlockedException(cause.message ?: "", cause.cause)
62+
is com.google.firebase.vertexai.common.QuotaExceededException ->
63+
QuotaExceededException(cause.message ?: "", cause.cause)
6264
else -> UnknownException(cause.message ?: "", cause)
6365
}
6466
is TimeoutCancellationException ->
@@ -165,6 +167,14 @@ public class ServiceDisabledException
165167
internal constructor(message: String, cause: Throwable? = null) :
166168
FirebaseVertexAIException(message, cause)
167169

170+
/**
171+
* The request has hit a quota limit. Learn more about quotas in the
172+
* [Firebase documentation.](https://firebase.google.com/docs/vertex-ai/quotas)
173+
*/
174+
public class QuotaExceededException
175+
internal constructor(message: String, cause: Throwable? = null) :
176+
FirebaseVertexAIException(message, cause)
177+
168178
/** Catch all case for exceptions not explicitly expected. */
169179
public class UnknownException internal constructor(message: String, cause: Throwable? = null) :
170180
FirebaseVertexAIException(message, cause)

firebase-vertexai/src/test/java/com/google/firebase/vertexai/UnarySnapshotTests.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.google.firebase.vertexai.type.HarmSeverity
2727
import com.google.firebase.vertexai.type.InvalidAPIKeyException
2828
import com.google.firebase.vertexai.type.PromptBlockedException
2929
import com.google.firebase.vertexai.type.PublicPreviewAPI
30+
import com.google.firebase.vertexai.type.QuotaExceededException
3031
import com.google.firebase.vertexai.type.ResponseStoppedException
3132
import com.google.firebase.vertexai.type.SerializationException
3233
import com.google.firebase.vertexai.type.ServerException
@@ -72,6 +73,19 @@ internal class UnarySnapshotTests {
7273
}
7374
}
7475

76+
@Test
77+
fun `long reply`() =
78+
goldenUnaryFile("unary-success-basic-reply-long.json") {
79+
withTimeout(testTimeout) {
80+
val response = model.generateContent("prompt")
81+
82+
response.candidates.isEmpty() shouldBe false
83+
response.candidates.first().finishReason shouldBe FinishReason.STOP
84+
response.candidates.first().content.parts.isEmpty() shouldBe false
85+
response.candidates.first().safetyRatings.isEmpty() shouldBe false
86+
}
87+
}
88+
7589
@Test
7690
fun `response with detailed token-based usageMetadata`() =
7791
goldenUnaryFile("unary-success-basic-response-long-usage-metadata.json") {
@@ -177,6 +191,20 @@ internal class UnarySnapshotTests {
177191
}
178192
}
179193

194+
@Test
195+
fun `function call has no arguments field`() =
196+
goldenUnaryFile("unary-success-function-call-empty-arguments.json") {
197+
withTimeout(testTimeout) {
198+
val response = model.generateContent("prompt")
199+
val content = response.candidates.shouldNotBeNullOrEmpty().first().content
200+
content.shouldNotBeNull()
201+
val callPart = content.parts.shouldNotBeNullOrEmpty().first() as FunctionCallPart
202+
203+
callPart.name shouldBe "current_time"
204+
callPart.args shouldBe emptyMap()
205+
}
206+
}
207+
180208
@Test
181209
fun `prompt blocked for safety`() =
182210
goldenUnaryFile("unary-failure-prompt-blocked-safety.json") {
@@ -239,6 +267,14 @@ internal class UnarySnapshotTests {
239267
}
240268
}
241269

270+
@Test
271+
fun `quota exceeded`() =
272+
goldenUnaryFile("unary-failure-quota-exceeded.json", HttpStatusCode.BadRequest) {
273+
withTimeout(testTimeout) {
274+
shouldThrow<QuotaExceededException> { model.generateContent("prompt") }
275+
}
276+
}
277+
242278
@Test
243279
fun `stopped for safety with no content`() =
244280
goldenUnaryFile("unary-failure-finish-reason-safety-no-content.json") {

firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/StreamingSnapshotTests.kt

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)