Skip to content

Commit

Permalink
chore: [vertexai]Add integration test for generateContentAsync (#10680)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 622923522

Co-authored-by: Zhenyi Qi <[email protected]>
  • Loading branch information
copybara-service[bot] and Zhenyi Qi authored Apr 11, 2024
1 parent 4cbd770 commit ebaef51
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.api.core.ApiFuture;
import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.CountTokensResponse;
Expand Down Expand Up @@ -110,16 +111,15 @@ private static void assertNonEmptyAndLogTextContentOfResponseStream(
}

@Test
public void generateContent_withPlainText_respondWithNonEmptyCandidateList() throws IOException {
public void generateContent_withPlainText_nonEmptyCandidateList() throws IOException {
GenerateContentResponse response = textModel.generateContent(TEXT);

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
assertNonEmptyAndLogResponse(methodName, TEXT, response);
}

@Test
public void generateContent_withCompleteConfig_respondWithNonEmptyCandidateList()
throws IOException {
public void generateContent_withCompleteConfig_nonEmptyCandidateList() throws IOException {
logger.info(String.format("Generating response for question: %s", TEXT));
Integer maxOutputTokens = 50;
GenerationConfig generationConfig =
Expand Down Expand Up @@ -152,8 +152,16 @@ public void generateContent_withCompleteConfig_respondWithNonEmptyCandidateList(
}

@Test
public void generateContentStream_withPlainText_respondWithNonEmptyCandidateList()
throws IOException {
public void generateContentAsync_withPlainText_nonEmptyCandidateList() throws Exception {
ApiFuture<GenerateContentResponse> responseFuture = textModel.generateContentAsync(TEXT);
GenerateContentResponse response = responseFuture.get();

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
assertNonEmptyAndLogResponse(methodName, TEXT, response);
}

@Test
public void generateContentStream_withPlainText_nonEmptyCandidateList() throws IOException {
ResponseStream<GenerateContentResponse> stream = textModel.generateContentStream(TEXT);

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
Expand All @@ -163,8 +171,7 @@ public void generateContentStream_withPlainText_respondWithNonEmptyCandidateList
// TODO(b/333866041): Re-enable byteImage test
@Ignore("The test is not compatible with GraalVM native image test on GitHub.")
@Test
public void generateContentStream_withByteImage_respondWithNonEmptyCandidateList()
throws Exception {
public void generateContentStream_withByteImage_nonEmptyCandidateList() throws Exception {
ResponseStream<GenerateContentResponse> stream =
multiModalModel.generateContentStream(
ContentMaker.fromMultiModalData(
Expand All @@ -176,8 +183,7 @@ public void generateContentStream_withByteImage_respondWithNonEmptyCandidateList
}

@Test
public void generateContentStream_withGcsVideo_respondWithNonEmptyCandidateList()
throws Exception {
public void generateContentStream_withGcsVideo_nonEmptyCandidateList() throws Exception {
Part videoPart = PartMaker.fromMimeTypeAndData("video/mp4", GCS_VIDEO_URI);
Content content = ContentMaker.fromMultiModalData(VIDEO_INQUIRY, videoPart);

Expand All @@ -188,8 +194,7 @@ public void generateContentStream_withGcsVideo_respondWithNonEmptyCandidateList(
}

@Test
public void generateContentStream_withGcsImage_respondWithNonEmptyCandidateList()
throws Exception {
public void generateContentStream_withGcsImage_nonEmptyCandidateList() throws Exception {
Part imagePart = PartMaker.fromMimeTypeAndData("image/jpeg", GCS_IMAGE_URI);
Content content = ContentMaker.fromMultiModalData(IMAGE_INQUIRY, imagePart);

Expand Down

0 comments on commit ebaef51

Please sign in to comment.