xref: /aosp_15_r20/external/googleapis/google/ai/generativelanguage/v1beta2/text_service.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.ai.generativelanguage.v1beta2;
18
19import "google/ai/generativelanguage/v1beta2/citation.proto";
20import "google/ai/generativelanguage/v1beta2/safety.proto";
21import "google/api/annotations.proto";
22import "google/api/client.proto";
23import "google/api/field_behavior.proto";
24import "google/api/resource.proto";
25
26option go_package = "cloud.google.com/go/ai/generativelanguage/apiv1beta2/generativelanguagepb;generativelanguagepb";
27option java_multiple_files = true;
28option java_outer_classname = "TextServiceProto";
29option java_package = "com.google.ai.generativelanguage.v1beta2";
30
31// API for using Generative Language Models (GLMs) trained to generate text.
32//
33// Also known as Large Language Models (LLM)s, these generate text given an
34// input prompt from the user.
35service TextService {
36  option (google.api.default_host) = "generativelanguage.googleapis.com";
37
38  // Generates a response from the model given an input message.
39  rpc GenerateText(GenerateTextRequest) returns (GenerateTextResponse) {
40    option (google.api.http) = {
41      post: "/v1beta2/{model=models/*}:generateText"
42      body: "*"
43    };
44    option (google.api.method_signature) =
45        "model,prompt,temperature,candidate_count,max_output_tokens,top_p,top_k";
46  }
47
48  // Generates an embedding from the model given an input message.
49  rpc EmbedText(EmbedTextRequest) returns (EmbedTextResponse) {
50    option (google.api.http) = {
51      post: "/v1beta2/{model=models/*}:embedText"
52      body: "*"
53    };
54    option (google.api.method_signature) = "model,text";
55  }
56}
57
58// Request to generate a text completion response from the model.
59message GenerateTextRequest {
60  // Required. The model name to use with the format name=models/{model}.
61  string model = 1 [
62    (google.api.field_behavior) = REQUIRED,
63    (google.api.resource_reference) = {
64      type: "generativelanguage.googleapis.com/Model"
65    }
66  ];
67
68  // Required. The free-form input text given to the model as a prompt.
69  //
70  // Given a prompt, the model will generate a TextCompletion response it
71  // predicts as the completion of the input text.
72  TextPrompt prompt = 2 [(google.api.field_behavior) = REQUIRED];
73
74  // Controls the randomness of the output.
75  // Note: The default value varies by model, see the `Model.temperature`
76  // attribute of the `Model` returned the `getModel` function.
77  //
78  // Values can range from [0.0,1.0],
79  // inclusive. A value closer to 1.0 will produce responses that are more
80  // varied and creative, while a value closer to 0.0 will typically result in
81  // more straightforward responses from the model.
82  optional float temperature = 3;
83
84  // Number of generated responses to return.
85  //
86  // This value must be between [1, 8], inclusive. If unset, this will default
87  // to 1.
88  optional int32 candidate_count = 4;
89
90  // The maximum number of tokens to include in a candidate.
91  //
92  // If unset, this will default to 64.
93  optional int32 max_output_tokens = 5;
94
95  // The maximum cumulative probability of tokens to consider when sampling.
96  //
97  // The model uses combined Top-k and nucleus sampling.
98  //
99  // Tokens are sorted based on their assigned probabilities so that only the
100  // most liekly tokens are considered. Top-k sampling directly limits the
101  // maximum number of tokens to consider, while Nucleus sampling limits number
102  // of tokens based on the cumulative probability.
103  //
104  // Note: The default value varies by model, see the `Model.top_p`
105  // attribute of the `Model` returned the `getModel` function.
106  optional float top_p = 6;
107
108  // The maximum number of tokens to consider when sampling.
109  //
110  // The model uses combined Top-k and nucleus sampling.
111  //
112  // Top-k sampling considers the set of `top_k` most probable tokens.
113  // Defaults to 40.
114  //
115  // Note: The default value varies by model, see the `Model.top_k`
116  // attribute of the `Model` returned the `getModel` function.
117  optional int32 top_k = 7;
118
119  // A list of unique `SafetySetting` instances for blocking unsafe content.
120  //
121  // that will be enforced on the `GenerateTextRequest.prompt` and
122  // `GenerateTextResponse.candidates`. There should not be more than one
123  // setting for each `SafetyCategory` type. The API will block any prompts and
124  // responses that fail to meet the thresholds set by these settings. This list
125  // overrides the default settings for each `SafetyCategory` specified in the
126  // safety_settings. If there is no `SafetySetting` for a given
127  // `SafetyCategory` provided in the list, the API will use the default safety
128  // setting for that category.
129  repeated SafetySetting safety_settings = 8;
130
131  // The set of character sequences (up to 5) that will stop output generation.
132  // If specified, the API will stop at the first appearance of a stop
133  // sequence. The stop sequence will not be included as part of the response.
134  repeated string stop_sequences = 9;
135}
136
137// The response from the model, including candidate completions.
138message GenerateTextResponse {
139  // Candidate responses from the model.
140  repeated TextCompletion candidates = 1;
141
142  // A set of content filtering metadata for the prompt and response
143  // text.
144  //
145  // This indicates which `SafetyCategory`(s) blocked a
146  // candidate from this response, the lowest `HarmProbability`
147  // that triggered a block, and the HarmThreshold setting for that category.
148  // This indicates the smallest change to the `SafetySettings` that would be
149  // necessary to unblock at least 1 response.
150  //
151  // The blocking is configured by the `SafetySettings` in the request (or the
152  // default `SafetySettings` of the API).
153  repeated ContentFilter filters = 3;
154
155  // Returns any safety feedback related to content filtering.
156  repeated SafetyFeedback safety_feedback = 4;
157}
158
159// Text given to the model as a prompt.
160//
161// The Model will use this TextPrompt to Generate a text completion.
162message TextPrompt {
163  // Required. The prompt text.
164  string text = 1 [(google.api.field_behavior) = REQUIRED];
165}
166
167// Output text returned from a model.
168message TextCompletion {
169  // Output only. The generated text returned from the model.
170  string output = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
171
172  // Ratings for the safety of a response.
173  //
174  // There is at most one rating per category.
175  repeated SafetyRating safety_ratings = 2;
176
177  // Output only. Citation information for model-generated `output` in this
178  // `TextCompletion`.
179  //
180  // This field may be populated with attribution information for any text
181  // included in the `output`.
182  optional CitationMetadata citation_metadata = 3
183      [(google.api.field_behavior) = OUTPUT_ONLY];
184}
185
186// Request to get a text embedding from the model.
187message EmbedTextRequest {
188  // Required. The model name to use with the format model=models/{model}.
189  string model = 1 [
190    (google.api.field_behavior) = REQUIRED,
191    (google.api.resource_reference) = {
192      type: "generativelanguage.googleapis.com/Model"
193    }
194  ];
195
196  // Required. The free-form input text that the model will turn into an
197  // embedding.
198  string text = 2 [(google.api.field_behavior) = REQUIRED];
199}
200
201// The response to a EmbedTextRequest.
202message EmbedTextResponse {
203  // Output only. The embedding generated from the input text.
204  optional Embedding embedding = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
205}
206
207// A list of floats representing the embedding.
208message Embedding {
209  // The embedding values.
210  repeated float value = 1;
211}
212