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 = "DiscussServiceProto"; 29option java_package = "com.google.ai.generativelanguage.v1beta2"; 30 31// An API for using Generative Language Models (GLMs) in dialog applications. 32// 33// Also known as large language models (LLMs), this API provides models that 34// are trained for multi-turn dialog. 35service DiscussService { 36 option (google.api.default_host) = "generativelanguage.googleapis.com"; 37 38 // Generates a response from the model given an input `MessagePrompt`. 39 rpc GenerateMessage(GenerateMessageRequest) 40 returns (GenerateMessageResponse) { 41 option (google.api.http) = { 42 post: "/v1beta2/{model=models/*}:generateMessage" 43 body: "*" 44 }; 45 option (google.api.method_signature) = 46 "model,prompt,temperature,candidate_count,top_p,top_k"; 47 } 48 49 // Runs a model's tokenizer on a string and returns the token count. 50 rpc CountMessageTokens(CountMessageTokensRequest) 51 returns (CountMessageTokensResponse) { 52 option (google.api.http) = { 53 post: "/v1beta2/{model=models/*}:countMessageTokens" 54 body: "*" 55 }; 56 option (google.api.method_signature) = "model,prompt"; 57 } 58} 59 60// Request to generate a message response from the model. 61message GenerateMessageRequest { 62 // Required. The name of the model to use. 63 // 64 // Format: `name=models/{model}`. 65 string model = 1 [ 66 (google.api.field_behavior) = REQUIRED, 67 (google.api.resource_reference) = { 68 type: "generativelanguage.googleapis.com/Model" 69 } 70 ]; 71 72 // Required. The structured textual input given to the model as a prompt. 73 // 74 // Given a 75 // prompt, the model will return what it predicts is the next message in the 76 // discussion. 77 MessagePrompt prompt = 2 [(google.api.field_behavior) = REQUIRED]; 78 79 // Optional. Controls the randomness of the output. 80 // 81 // Values can range over `[0.0,1.0]`, 82 // inclusive. A value closer to `1.0` will produce responses that are more 83 // varied, while a value closer to `0.0` will typically result in 84 // less surprising responses from the model. 85 optional float temperature = 3 [(google.api.field_behavior) = OPTIONAL]; 86 87 // Optional. The number of generated response messages to return. 88 // 89 // This value must be between 90 // `[1, 8]`, inclusive. If unset, this will default to `1`. 91 optional int32 candidate_count = 4 [(google.api.field_behavior) = OPTIONAL]; 92 93 // Optional. The maximum cumulative probability of tokens to consider when 94 // sampling. 95 // 96 // The model uses combined Top-k and nucleus sampling. 97 // 98 // Nucleus sampling considers the smallest set of tokens whose probability 99 // sum is at least `top_p`. 100 optional float top_p = 5 [(google.api.field_behavior) = OPTIONAL]; 101 102 // Optional. The maximum number of tokens to consider when sampling. 103 // 104 // The model uses combined Top-k and nucleus sampling. 105 // 106 // Top-k sampling considers the set of `top_k` most probable tokens. 107 optional int32 top_k = 6 [(google.api.field_behavior) = OPTIONAL]; 108} 109 110// The response from the model. 111// 112// This includes candidate messages and 113// conversation history in the form of chronologically-ordered messages. 114message GenerateMessageResponse { 115 // Candidate response messages from the model. 116 repeated Message candidates = 1; 117 118 // The conversation history used by the model. 119 repeated Message messages = 2; 120 121 // A set of content filtering metadata for the prompt and response 122 // text. 123 // 124 // This indicates which `SafetyCategory`(s) blocked a 125 // candidate from this response, the lowest `HarmProbability` 126 // that triggered a block, and the HarmThreshold setting for that category. 127 repeated ContentFilter filters = 3; 128} 129 130// The base unit of structured text. 131// 132// A `Message` includes an `author` and the `content` of 133// the `Message`. 134// 135// The `author` is used to tag messages when they are fed to the 136// model as text. 137message Message { 138 // Optional. The author of this Message. 139 // 140 // This serves as a key for tagging 141 // the content of this Message when it is fed to the model as text. 142 // 143 // The author can be any alphanumeric string. 144 string author = 1 [(google.api.field_behavior) = OPTIONAL]; 145 146 // Required. The text content of the structured `Message`. 147 string content = 2 [(google.api.field_behavior) = REQUIRED]; 148 149 // Output only. Citation information for model-generated `content` in this 150 // `Message`. 151 // 152 // If this `Message` was generated as output from the model, this field may be 153 // populated with attribution information for any text included in the 154 // `content`. This field is used only on output. 155 optional CitationMetadata citation_metadata = 3 156 [(google.api.field_behavior) = OUTPUT_ONLY]; 157} 158 159// All of the structured input text passed to the model as a prompt. 160// 161// A `MessagePrompt` contains a structured set of fields that provide context 162// for the conversation, examples of user input/model output message pairs that 163// prime the model to respond in different ways, and the conversation history 164// or list of messages representing the alternating turns of the conversation 165// between the user and the model. 166message MessagePrompt { 167 // Optional. Text that should be provided to the model first to ground the 168 // response. 169 // 170 // If not empty, this `context` will be given to the model first before the 171 // `examples` and `messages`. When using a `context` be sure to provide it 172 // with every request to maintain continuity. 173 // 174 // This field can be a description of your prompt to the model to help provide 175 // context and guide the responses. Examples: "Translate the phrase from 176 // English to French." or "Given a statement, classify the sentiment as happy, 177 // sad or neutral." 178 // 179 // Anything included in this field will take precedence over message history 180 // if the total input size exceeds the model's `input_token_limit` and the 181 // input request is truncated. 182 string context = 1 [(google.api.field_behavior) = OPTIONAL]; 183 184 // Optional. Examples of what the model should generate. 185 // 186 // This includes both user input and the response that the model should 187 // emulate. 188 // 189 // These `examples` are treated identically to conversation messages except 190 // that they take precedence over the history in `messages`: 191 // If the total input size exceeds the model's `input_token_limit` the input 192 // will be truncated. Items will be dropped from `messages` before `examples`. 193 repeated Example examples = 2 [(google.api.field_behavior) = OPTIONAL]; 194 195 // Required. A snapshot of the recent conversation history sorted 196 // chronologically. 197 // 198 // Turns alternate between two authors. 199 // 200 // If the total input size exceeds the model's `input_token_limit` the input 201 // will be truncated: The oldest items will be dropped from `messages`. 202 repeated Message messages = 3 [(google.api.field_behavior) = REQUIRED]; 203} 204 205// An input/output example used to instruct the Model. 206// 207// It demonstrates how the model should respond or format its response. 208message Example { 209 // Required. An example of an input `Message` from the user. 210 Message input = 1 [(google.api.field_behavior) = REQUIRED]; 211 212 // Required. An example of what the model should output given the input. 213 Message output = 2 [(google.api.field_behavior) = REQUIRED]; 214} 215 216// Counts the number of tokens in the `prompt` sent to a model. 217// 218// Models may tokenize text differently, so each model may return a different 219// `token_count`. 220message CountMessageTokensRequest { 221 // Required. The model's resource name. This serves as an ID for the Model to 222 // use. 223 // 224 // This name should match a model name returned by the `ListModels` method. 225 // 226 // Format: `models/{model}` 227 string model = 1 [ 228 (google.api.field_behavior) = REQUIRED, 229 (google.api.resource_reference) = { 230 type: "generativelanguage.googleapis.com/Model" 231 } 232 ]; 233 234 // Required. The prompt, whose token count is to be returned. 235 MessagePrompt prompt = 2 [(google.api.field_behavior) = REQUIRED]; 236} 237 238// A response from `CountMessageTokens`. 239// 240// It returns the model's `token_count` for the `prompt`. 241message CountMessageTokensResponse { 242 // The number of tokens that the `model` tokenizes the `prompt` into. 243 // 244 // Always non-negative. 245 int32 token_count = 1; 246} 247