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

feat: [aiplatform] Add generateContent Unary API for aiplatform_v1 #10319

Merged
merged 8 commits into from
Feb 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@
* </td>
* </tr>
* <tr>
* <td><p> StreamRawPredict</td>
* <td><p> Perform a streaming online prediction with an arbitrary HTTP payload.</td>
* <td>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
* <li><p> streamRawPredictCallable()
* </ul>
* </td>
* </tr>
* <tr>
* <td><p> DirectPredict</td>
* <td><p> Perform an unary online prediction request for Vertex first-party products and frameworks.</td>
* <td><p> Perform an unary online prediction request to a gRPC model server for Vertex first-party products and frameworks.</td>
* <td>
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
* <ul>
Expand All @@ -139,7 +149,7 @@
* </tr>
* <tr>
* <td><p> DirectRawPredict</td>
* <td><p> Perform an online prediction request through gRPC.</td>
* <td><p> Perform an unary online prediction request to a gRPC model server for custom containers.</td>
* <td>
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
* <ul>
Expand All @@ -152,6 +162,26 @@
* </td>
* </tr>
* <tr>
* <td><p> StreamDirectPredict</td>
* <td><p> Perform a streaming online prediction request to a gRPC model server for Vertex first-party products and frameworks.</td>
* <td>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
* <li><p> streamDirectPredictCallable()
* </ul>
* </td>
* </tr>
* <tr>
* <td><p> StreamDirectRawPredict</td>
* <td><p> Perform a streaming online prediction request to a gRPC model server for custom containers.</td>
* <td>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
* <li><p> streamDirectRawPredictCallable()
* </ul>
* </td>
* </tr>
* <tr>
* <td><p> StreamingPredict</td>
* <td><p> Perform a streaming online prediction request for Vertex first-party products and frameworks.</td>
* <td>
Expand Down Expand Up @@ -202,6 +232,24 @@
* </td>
* </tr>
* <tr>
* <td><p> GenerateContent</td>
* <td><p> Generate content with multimodal inputs.</td>
* <td>
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
* <ul>
* <li><p> generateContent(GenerateContentRequest request)
* </ul>
* <p>"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.</p>
* <ul>
* <li><p> generateContent(String model, List&lt;Content&gt; contents)
* </ul>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
* <li><p> generateContentCallable()
* </ul>
* </td>
* </tr>
* <tr>
* <td><p> StreamGenerateContent</td>
* <td><p> Generate content with multimodal inputs with streaming support.</td>
* <td>
Expand Down Expand Up @@ -740,7 +788,42 @@ public final UnaryCallable<RawPredictRequest, HttpBody> rawPredictCallable() {

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform an unary online prediction request for Vertex first-party products and frameworks.
* Perform a streaming online prediction with an arbitrary HTTP payload.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* StreamRawPredictRequest request =
* StreamRawPredictRequest.newBuilder()
* .setEndpoint(
* EndpointName.ofProjectLocationEndpointName(
* "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
* .toString())
* .setHttpBody(HttpBody.newBuilder().build())
* .build();
* ServerStream<HttpBody> stream =
* predictionServiceClient.streamRawPredictCallable().call(request);
* for (HttpBody response : stream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final ServerStreamingCallable<StreamRawPredictRequest, HttpBody>
streamRawPredictCallable() {
return stub.streamRawPredictCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform an unary online prediction request to a gRPC model server for Vertex first-party
* products and frameworks.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -773,7 +856,8 @@ public final DirectPredictResponse directPredict(DirectPredictRequest request) {

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform an unary online prediction request for Vertex first-party products and frameworks.
* Perform an unary online prediction request to a gRPC model server for Vertex first-party
* products and frameworks.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -806,7 +890,7 @@ public final UnaryCallable<DirectPredictRequest, DirectPredictResponse> directPr

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform an online prediction request through gRPC.
* Perform an unary online prediction request to a gRPC model server for custom containers.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -839,7 +923,7 @@ public final DirectRawPredictResponse directRawPredict(DirectRawPredictRequest r

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform an online prediction request through gRPC.
* Perform an unary online prediction request to a gRPC model server for custom containers.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -871,6 +955,79 @@ public final DirectRawPredictResponse directRawPredict(DirectRawPredictRequest r
return stub.directRawPredictCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform a streaming online prediction request to a gRPC model server for Vertex first-party
* products and frameworks.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* BidiStream<StreamDirectPredictRequest, StreamDirectPredictResponse> bidiStream =
* predictionServiceClient.streamDirectPredictCallable().call();
* StreamDirectPredictRequest request =
* StreamDirectPredictRequest.newBuilder()
* .setEndpoint(
* EndpointName.ofProjectLocationEndpointName(
* "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
* .toString())
* .addAllInputs(new ArrayList<Tensor>())
* .setParameters(Tensor.newBuilder().build())
* .build();
* bidiStream.send(request);
* for (StreamDirectPredictResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<StreamDirectPredictRequest, StreamDirectPredictResponse>
streamDirectPredictCallable() {
return stub.streamDirectPredictCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform a streaming online prediction request to a gRPC model server for custom containers.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* BidiStream<StreamDirectRawPredictRequest, StreamDirectRawPredictResponse> bidiStream =
* predictionServiceClient.streamDirectRawPredictCallable().call();
* StreamDirectRawPredictRequest request =
* StreamDirectRawPredictRequest.newBuilder()
* .setEndpoint(
* EndpointName.ofProjectLocationEndpointName(
* "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
* .toString())
* .setMethodName("methodName-723163380")
* .setInput(ByteString.EMPTY)
* .build();
* bidiStream.send(request);
* for (StreamDirectRawPredictResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<StreamDirectRawPredictRequest, StreamDirectRawPredictResponse>
streamDirectRawPredictCallable() {
return stub.streamDirectRawPredictCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Perform a streaming online prediction request for Vertex first-party products and frameworks.
Expand Down Expand Up @@ -1187,6 +1344,103 @@ public final UnaryCallable<ExplainRequest, ExplainResponse> explainCallable() {
return stub.explainCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generate content with multimodal inputs.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* String model = "model104069929";
* List<Content> contents = new ArrayList<>();
* GenerateContentResponse response = predictionServiceClient.generateContent(model, contents);
* }
* }</pre>
*
* @param model Required. The name of the publisher model requested to serve the prediction.
* Format: `projects/{project}/locations/{location}/publishers/&#42;/models/&#42;`
* @param contents Required. The content of the current conversation with the model.
* <p>For single-turn queries, this is a single instance. For multi-turn queries, this is a
* repeated field that contains conversation history + latest request.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final GenerateContentResponse generateContent(String model, List<Content> contents) {
GenerateContentRequest request =
GenerateContentRequest.newBuilder().setModel(model).addAllContents(contents).build();
return generateContent(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generate content with multimodal inputs.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* GenerateContentRequest request =
* GenerateContentRequest.newBuilder()
* .setModel("model104069929")
* .addAllContents(new ArrayList<Content>())
* .addAllTools(new ArrayList<Tool>())
* .addAllSafetySettings(new ArrayList<SafetySetting>())
* .setGenerationConfig(GenerationConfig.newBuilder().build())
* .build();
* GenerateContentResponse response = predictionServiceClient.generateContent(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final GenerateContentResponse generateContent(GenerateContentRequest request) {
return generateContentCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generate content with multimodal inputs.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
* GenerateContentRequest request =
* GenerateContentRequest.newBuilder()
* .setModel("model104069929")
* .addAllContents(new ArrayList<Content>())
* .addAllTools(new ArrayList<Tool>())
* .addAllSafetySettings(new ArrayList<SafetySetting>())
* .setGenerationConfig(GenerationConfig.newBuilder().build())
* .build();
* ApiFuture<GenerateContentResponse> future =
* predictionServiceClient.generateContentCallable().futureCall(request);
* // Do something.
* GenerateContentResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<GenerateContentRequest, GenerateContentResponse>
generateContentCallable() {
return stub.generateContentCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generate content with multimodal inputs with streaming support.
Expand Down
Loading
Loading