From a9e4e72e32b550a5451030feae99d1602ee40e0d Mon Sep 17 00:00:00 2001 From: Google APIs Date: Tue, 14 Nov 2023 16:19:42 -0800 Subject: [PATCH] feat: add ComputeTokens API PiperOrigin-RevId: 582473450 --- google/cloud/aiplatform/v1beta1/BUILD.bazel | 2 + .../v1beta1/aiplatform_v1beta1.yaml | 5 ++ .../v1beta1/llm_utility_service.proto | 86 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 google/cloud/aiplatform/v1beta1/llm_utility_service.proto diff --git a/google/cloud/aiplatform/v1beta1/BUILD.bazel b/google/cloud/aiplatform/v1beta1/BUILD.bazel index eef4055217a05..3223dcb6e552b 100644 --- a/google/cloud/aiplatform/v1beta1/BUILD.bazel +++ b/google/cloud/aiplatform/v1beta1/BUILD.bazel @@ -71,6 +71,7 @@ proto_library( "job_service.proto", "job_state.proto", "lineage_subgraph.proto", + "llm_utility_service.proto", "machine_resources.proto", "manual_batch_tuning_parameters.proto", "match_service.proto", @@ -213,6 +214,7 @@ java_gapic_test( "com.google.cloud.aiplatform.v1beta1.IndexEndpointServiceClientTest", "com.google.cloud.aiplatform.v1beta1.IndexServiceClientTest", "com.google.cloud.aiplatform.v1beta1.JobServiceClientTest", + "com.google.cloud.aiplatform.v1beta1.LlmUtilityServiceClientTest", "com.google.cloud.aiplatform.v1beta1.MetadataServiceClientTest", "com.google.cloud.aiplatform.v1beta1.MigrationServiceClientTest", "com.google.cloud.aiplatform.v1beta1.ModelServiceClientTest", diff --git a/google/cloud/aiplatform/v1beta1/aiplatform_v1beta1.yaml b/google/cloud/aiplatform/v1beta1/aiplatform_v1beta1.yaml index 7a6dbc04a2c1e..2b33166351c62 100644 --- a/google/cloud/aiplatform/v1beta1/aiplatform_v1beta1.yaml +++ b/google/cloud/aiplatform/v1beta1/aiplatform_v1beta1.yaml @@ -15,6 +15,7 @@ apis: - name: google.cloud.aiplatform.v1beta1.IndexEndpointService - name: google.cloud.aiplatform.v1beta1.IndexService - name: google.cloud.aiplatform.v1beta1.JobService +- name: google.cloud.aiplatform.v1beta1.LlmUtilityService - name: google.cloud.aiplatform.v1beta1.MatchService - name: google.cloud.aiplatform.v1beta1.MetadataService - name: google.cloud.aiplatform.v1beta1.MigrationService @@ -662,6 +663,10 @@ authentication: canonical_scopes: |- https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/cloud-platform.read-only + - selector: google.cloud.aiplatform.v1beta1.LlmUtilityService.ComputeTokens + oauth: + canonical_scopes: |- + https://www.googleapis.com/auth/cloud-platform - selector: google.cloud.aiplatform.v1beta1.MatchService.FindNeighbors oauth: canonical_scopes: |- diff --git a/google/cloud/aiplatform/v1beta1/llm_utility_service.proto b/google/cloud/aiplatform/v1beta1/llm_utility_service.proto new file mode 100644 index 0000000000000..3fddf3acc845f --- /dev/null +++ b/google/cloud/aiplatform/v1beta1/llm_utility_service.proto @@ -0,0 +1,86 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.cloud.aiplatform.v1beta1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/struct.proto"; + +option csharp_namespace = "Google.Cloud.AIPlatform.V1Beta1"; +option go_package = "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb;aiplatformpb"; +option java_multiple_files = true; +option java_outer_classname = "LlmUtilityServiceProto"; +option java_package = "com.google.cloud.aiplatform.v1beta1"; +option php_namespace = "Google\\Cloud\\AIPlatform\\V1beta1"; +option ruby_package = "Google::Cloud::AIPlatform::V1beta1"; + +// Service for LLM related utility functions. +service LlmUtilityService { + option (google.api.default_host) = "aiplatform.googleapis.com"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform"; + + // Return a list of tokens based on the input text. + rpc ComputeTokens(ComputeTokensRequest) returns (ComputeTokensResponse) { + option (google.api.http) = { + post: "/v1beta1/{endpoint=projects/*/locations/*/endpoints/*}:computeTokens" + body: "*" + additional_bindings { + post: "/v1beta1/{endpoint=projects/*/locations/*/publishers/*/models/*}:computeTokens" + body: "*" + } + }; + option (google.api.method_signature) = "endpoint,instances"; + } +} + +// Request message for ComputeTokens RPC call. +message ComputeTokensRequest { + // Required. The name of the Endpoint requested to get lists of tokens and + // token ids. + string endpoint = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "aiplatform.googleapis.com/Endpoint" + } + ]; + + // Required. The instances that are the input to token computing API call. + // Schema is identical to the prediction schema of the text model, even for + // the non-text models, like chat models, or Codey models. + repeated google.protobuf.Value instances = 2 + [(google.api.field_behavior) = REQUIRED]; +} + +// Tokens info with a list of tokens and the corresponding list of token ids. +message TokensInfo { + // A list of tokens from the input. + repeated bytes tokens = 1; + + // A list of token ids from the input. + repeated int64 token_ids = 2; +} + +// Response message for ComputeTokens RPC call. +message ComputeTokensResponse { + // Lists of tokens info from the input. A ComputeTokensRequest could have + // multiple instances with a prompt in each instance. We also need to return + // lists of tokens info for the request with multiple instances. + repeated TokensInfo tokens_info = 1; +}