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: [vertexai] enable AutomaticFunctionCallingResponder in ChatSession #10913

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1410,7 +1410,6 @@ public final GenerateContentResponse generateContent(String model, List<Content>
* .addAllContents(new ArrayList<Content>())
* .setSystemInstruction(Content.newBuilder().build())
* .addAllTools(new ArrayList<Tool>())
* .setToolConfig(ToolConfig.newBuilder().build())
* .addAllSafetySettings(new ArrayList<SafetySetting>())
* .setGenerationConfig(GenerationConfig.newBuilder().build())
* .build();
Expand Down Expand Up @@ -1444,7 +1443,6 @@ public final GenerateContentResponse generateContent(GenerateContentRequest requ
* .addAllContents(new ArrayList<Content>())
* .setSystemInstruction(Content.newBuilder().build())
* .addAllTools(new ArrayList<Tool>())
* .setToolConfig(ToolConfig.newBuilder().build())
* .addAllSafetySettings(new ArrayList<SafetySetting>())
* .setGenerationConfig(GenerationConfig.newBuilder().build())
* .build();
Expand Down Expand Up @@ -1479,7 +1477,6 @@ public final GenerateContentResponse generateContent(GenerateContentRequest requ
* .addAllContents(new ArrayList<Content>())
* .setSystemInstruction(Content.newBuilder().build())
* .addAllTools(new ArrayList<Tool>())
* .setToolConfig(ToolConfig.newBuilder().build())
* .addAllSafetySettings(new ArrayList<SafetySetting>())
* .setGenerationConfig(GenerationConfig.newBuilder().build())
* .build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ public EndpointServiceStub createStub() throws IOException {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns the default service name. */
@Override
public String getServiceName() {
Expand Down Expand Up @@ -989,6 +998,15 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return testIamPermissionsSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public EndpointServiceStubSettings build() throws IOException {
return new EndpointServiceStubSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
@Generated("by gapic-generator-java")
public class GrpcLlmUtilityServiceStub extends LlmUtilityServiceStub {
private static final MethodDescriptor<CountTokensRequest, CountTokensResponse>
// TODO(b/317255628): switch back to the google.cloud.aiplatform.v1.LlmUtilityServiceClient
countTokensMethodDescriptor =
MethodDescriptor.<CountTokensRequest, CountTokensResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.aiplatform.v1.LlmUtilityService/CountTokens")
.setRequestMarshaller(ProtoUtils.marshaller(CountTokensRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(CountTokensResponse.getDefaultInstance()))
.build();
MethodDescriptor.<CountTokensRequest, CountTokensResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.aiplatform.v1beta1.PredictionService/CountTokens")
.setRequestMarshaller(ProtoUtils.marshaller(CountTokensRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CountTokensResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<ComputeTokensRequest, ComputeTokensResponse>
computeTokensMethodDescriptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,12 @@ protected GrpcPredictionServiceStub(
streamDirectPredictTransportSettings =
GrpcCallSettings.<StreamDirectPredictRequest, StreamDirectPredictResponse>newBuilder()
.setMethodDescriptor(streamDirectPredictMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("endpoint", String.valueOf(request.getEndpoint()));
return builder.build();
})
.build();
GrpcCallSettings<StreamDirectRawPredictRequest, StreamDirectRawPredictResponse>
streamDirectRawPredictTransportSettings =
GrpcCallSettings
.<StreamDirectRawPredictRequest, StreamDirectRawPredictResponse>newBuilder()
.setMethodDescriptor(streamDirectRawPredictMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("endpoint", String.valueOf(request.getEndpoint()));
return builder.build();
})
.build();
GrpcCallSettings<StreamingPredictRequest, StreamingPredictResponse>
streamingPredictTransportSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,16 +688,6 @@ protected HttpJsonEndpointServiceStub(
"google.longrunning.Operations.CancelOperation",
HttpRule.newBuilder()
.setPost("/ui/{name=projects/*/locations/*/operations/*}:cancel")
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
"/ui/{name=projects/*/locations/*/agents/*/operations/*}:cancel")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
"/ui/{name=projects/*/locations/*/apps/*/operations/*}:cancel")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
Expand Down Expand Up @@ -1077,15 +1067,6 @@ protected HttpJsonEndpointServiceStub(
"google.longrunning.Operations.DeleteOperation",
HttpRule.newBuilder()
.setDelete("/ui/{name=projects/*/locations/*/operations/*}")
.addAdditionalBindings(
HttpRule.newBuilder()
.setDelete(
"/ui/{name=projects/*/locations/*/agents/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setDelete("/ui/{name=projects/*/locations/*/apps/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setDelete(
Expand Down Expand Up @@ -1495,14 +1476,6 @@ protected HttpJsonEndpointServiceStub(
"google.longrunning.Operations.GetOperation",
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/operations/*}")
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/agents/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/apps/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/datasets/*/operations/*}")
Expand Down Expand Up @@ -1919,14 +1892,6 @@ protected HttpJsonEndpointServiceStub(
"google.longrunning.Operations.ListOperations",
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*}/operations")
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/agents/*}/operations")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/apps/*}/operations")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/ui/{name=projects/*/locations/*/datasets/*}/operations")
Expand Down Expand Up @@ -2329,16 +2294,6 @@ protected HttpJsonEndpointServiceStub(
"google.longrunning.Operations.WaitOperation",
HttpRule.newBuilder()
.setPost("/ui/{name=projects/*/locations/*/operations/*}:wait")
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
"/ui/{name=projects/*/locations/*/agents/*/operations/*}:wait")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
"/ui/{name=projects/*/locations/*/apps/*/operations/*}:wait")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setPost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,43 @@ public class HttpJsonLlmUtilityServiceStub extends LlmUtilityServiceStub {
private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();

private static final ApiMethodDescriptor<CountTokensRequest, CountTokensResponse>
// TODO(b/317255628): switch back to the google.cloud.aiplatform.v1.LlmUtilityServiceClient
countTokensMethodDescriptor =
ApiMethodDescriptor.<CountTokensRequest, CountTokensResponse>newBuilder()
.setFullMethodName("google.cloud.aiplatform.v1.LlmUtilityService/CountTokens")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.<CountTokensRequest>newBuilder()
.setPath(
"/v1/{endpoint=projects/*/locations/*/endpoints/*}:countTokens",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<CountTokensRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "endpoint", request.getEndpoint());
return fields;
})
.setAdditionalPaths(
"/v1/{endpoint=projects/*/locations/*/publishers/*/models/*}:countTokens")
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
ProtoRestSerializer<CountTokensRequest> serializer =
ProtoRestSerializer.create();
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearEndpoint().build(), false))
.build())
.setResponseParser(
ProtoMessageResponseParser.<CountTokensResponse>newBuilder()
.setDefaultInstance(CountTokensResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
ApiMethodDescriptor.<CountTokensRequest, CountTokensResponse>newBuilder()
.setFullMethodName("google.cloud.aiplatform.v1beta1.PredictionService/CountTokens")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.<CountTokensRequest>newBuilder()
.setPath(
"/v1/{endpoint=projects/*/locations/*/endpoints/*}:countTokens",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<CountTokensRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "endpoint", request.getEndpoint());
return fields;
})
.setAdditionalPaths(
"/v1/{endpoint=projects/*/locations/*/publishers/*/models/*}:countTokens")
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
ProtoRestSerializer<CountTokensRequest> serializer =
ProtoRestSerializer.create();
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearEndpoint().build(), false))
.build())
.setResponseParser(
ProtoMessageResponseParser.<CountTokensResponse>newBuilder()
.setDefaultInstance(CountTokensResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();

private static final ApiMethodDescriptor<ComputeTokensRequest, ComputeTokensResponse>
computeTokensMethodDescriptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ public class HttpJsonPredictionServiceStub extends PredictionServiceStub {
serializer.putPathParam(fields, "endpoint", request.getEndpoint());
return fields;
})
.setAdditionalPaths(
"/v1/{endpoint=projects/*/locations/*/publishers/*/models/*}:directPredict")
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
Expand Down Expand Up @@ -249,8 +247,6 @@ public class HttpJsonPredictionServiceStub extends PredictionServiceStub {
serializer.putPathParam(fields, "endpoint", request.getEndpoint());
return fields;
})
.setAdditionalPaths(
"/v1/{endpoint=projects/*/locations/*/publishers/*/models/*}:directRawPredict")
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ public LlmUtilityServiceStub createStub() throws IOException {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns the default service name. */
@Override
public String getServiceName() {
Expand Down Expand Up @@ -531,6 +540,15 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return testIamPermissionsSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public LlmUtilityServiceStubSettings build() throws IOException {
return new LlmUtilityServiceStubSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@
public class PredictionServiceStubSettings extends StubSettings<PredictionServiceStubSettings> {
/** The default scopes of the service. */
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
ImmutableList.<String>builder()
.add("https://www.googleapis.com/auth/cloud-platform")
.add("https://www.googleapis.com/auth/cloud-platform.read-only")
.build();
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();

private final UnaryCallSettings<PredictRequest, PredictResponse> predictSettings;
private final UnaryCallSettings<RawPredictRequest, HttpBody> rawPredictSettings;
Expand Down Expand Up @@ -331,6 +328,15 @@ public PredictionServiceStub createStub() throws IOException {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns the default service name. */
@Override
public String getServiceName() {
Expand Down Expand Up @@ -800,6 +806,15 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return testIamPermissionsSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public PredictionServiceStubSettings build() throws IOException {
return new PredictionServiceStubSettings(this);
Expand Down
Loading
Loading