xref: /aosp_15_r20/external/googleapis/google/ai/generativelanguage/v1beta/content.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.v1beta;
18
19import "google/api/field_behavior.proto";
20import "google/protobuf/struct.proto";
21
22option go_package = "cloud.google.com/go/ai/generativelanguage/apiv1beta/generativelanguagepb;generativelanguagepb";
23option java_multiple_files = true;
24option java_outer_classname = "ContentProto";
25option java_package = "com.google.ai.generativelanguage.v1beta";
26
27// Type contains the list of OpenAPI data types as defined by
28// https://spec.openapis.org/oas/v3.0.3#data-types
29enum Type {
30  // Not specified, should not be used.
31  TYPE_UNSPECIFIED = 0;
32
33  // String type.
34  STRING = 1;
35
36  // Number type.
37  NUMBER = 2;
38
39  // Integer type.
40  INTEGER = 3;
41
42  // Boolean type.
43  BOOLEAN = 4;
44
45  // Array type.
46  ARRAY = 5;
47
48  // Object type.
49  OBJECT = 6;
50}
51
52// The base structured datatype containing multi-part content of a message.
53//
54// A `Content` includes a `role` field designating the producer of the `Content`
55// and a `parts` field containing multi-part data that contains the content of
56// the message turn.
57message Content {
58  // Ordered `Parts` that constitute a single message. Parts may have different
59  // MIME types.
60  repeated Part parts = 1;
61
62  // Optional. The producer of the content. Must be either 'user' or 'model'.
63  //
64  // Useful to set for multi-turn conversations, otherwise can be left blank
65  // or unset.
66  string role = 2 [(google.api.field_behavior) = OPTIONAL];
67}
68
69// A datatype containing media that is part of a multi-part `Content` message.
70//
71// A `Part` consists of data which has an associated datatype. A `Part` can only
72// contain one of the accepted types in `Part.data`.
73//
74// A `Part` must have a fixed IANA MIME type identifying the type and subtype
75// of the media if the `inline_data` field is filled with raw bytes.
76message Part {
77  oneof data {
78    // Inline text.
79    string text = 2;
80
81    // Inline media bytes.
82    Blob inline_data = 3;
83
84    // A predicted `FunctionCall` returned from the model that contains
85    // a string representing the `FunctionDeclaration.name` with the
86    // arguments and their values.
87    FunctionCall function_call = 4;
88
89    // The result output of a `FunctionCall` that contains a string
90    // representing the `FunctionDeclaration.name` and a structured JSON
91    // object containing any output from the function is used as context to
92    // the model.
93    FunctionResponse function_response = 5;
94
95    // URI based data.
96    FileData file_data = 6;
97  }
98}
99
100// Raw media bytes.
101//
102// Text should not be sent as raw bytes, use the 'text' field.
103message Blob {
104  // The IANA standard MIME type of the source data.
105  // Accepted types include: "image/png", "image/jpeg", "image/heic",
106  // "image/heif", "image/webp".
107  string mime_type = 1;
108
109  // Raw bytes for media formats.
110  bytes data = 2;
111}
112
113// URI based data.
114message FileData {
115  // Optional. The IANA standard MIME type of the source data.
116  string mime_type = 1 [(google.api.field_behavior) = OPTIONAL];
117
118  // Required. URI.
119  string file_uri = 2 [(google.api.field_behavior) = REQUIRED];
120}
121
122// Tool details that the model may use to generate response.
123//
124// A `Tool` is a piece of code that enables the system to interact with
125// external systems to perform an action, or set of actions, outside of
126// knowledge and scope of the model.
127message Tool {
128  // Optional. A list of `FunctionDeclarations` available to the model that can
129  // be used for function calling.
130  //
131  // The model or system does not execute the function. Instead the defined
132  // function may be returned as a [FunctionCall][content.part.function_call]
133  // with arguments to the client side for execution. The model may decide to
134  // call a subset of these functions by populating
135  // [FunctionCall][content.part.function_call] in the response. The next
136  // conversation turn may contain a
137  // [FunctionResponse][content.part.function_response]
138  // with the [content.role] "function" generation context for the next model
139  // turn.
140  repeated FunctionDeclaration function_declarations = 1
141      [(google.api.field_behavior) = OPTIONAL];
142}
143
144// The Tool configuration containing parameters for specifying `Tool` use
145// in the request.
146message ToolConfig {
147  // Optional. Function calling config.
148  FunctionCallingConfig function_calling_config = 1
149      [(google.api.field_behavior) = OPTIONAL];
150}
151
152// Configuration for specifying function calling behavior.
153message FunctionCallingConfig {
154  // Defines the execution behavior for function calling by defining the
155  // execution mode.
156  enum Mode {
157    // Unspecified function calling mode. This value should not be used.
158    MODE_UNSPECIFIED = 0;
159
160    // Default model behavior, model decides to predict either a function call
161    // or a natural language repspose.
162    AUTO = 1;
163
164    // Model is constrained to always predicting a function call only.
165    // If "allowed_function_names" are set, the predicted function call will be
166    // limited to any one of "allowed_function_names", else the predicted
167    // function call will be any one of the provided "function_declarations".
168    ANY = 2;
169
170    // Model will not predict any function call. Model behavior is same as when
171    // not passing any function declarations.
172    NONE = 3;
173  }
174
175  // Optional. Specifies the mode in which function calling should execute. If
176  // unspecified, the default value will be set to AUTO.
177  Mode mode = 1 [(google.api.field_behavior) = OPTIONAL];
178
179  // Optional. A set of function names that, when provided, limits the functions
180  // the model will call.
181  //
182  // This should only be set when the Mode is ANY. Function names
183  // should match [FunctionDeclaration.name]. With mode set to ANY, model will
184  // predict a function call from the set of function names provided.
185  repeated string allowed_function_names = 2
186      [(google.api.field_behavior) = OPTIONAL];
187}
188
189// Structured representation of a function declaration as defined by the
190// [OpenAPI 3.03 specification](https://spec.openapis.org/oas/v3.0.3). Included
191// in this declaration are the function name and parameters. This
192// FunctionDeclaration is a representation of a block of code that can be used
193// as a `Tool` by the model and executed by the client.
194message FunctionDeclaration {
195  // Required. The name of the function.
196  // Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum
197  // length of 63.
198  string name = 1 [(google.api.field_behavior) = REQUIRED];
199
200  // Required. A brief description of the function.
201  string description = 2 [(google.api.field_behavior) = REQUIRED];
202
203  // Optional. Describes the parameters to this function. Reflects the Open
204  // API 3.03 Parameter Object string Key: the name of the parameter. Parameter
205  // names are case sensitive. Schema Value: the Schema defining the type used
206  // for the parameter.
207  optional Schema parameters = 3 [(google.api.field_behavior) = OPTIONAL];
208}
209
210// A predicted `FunctionCall` returned from the model that contains
211// a string representing the `FunctionDeclaration.name` with the
212// arguments and their values.
213message FunctionCall {
214  // Required. The name of the function to call.
215  // Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum
216  // length of 63.
217  string name = 1 [(google.api.field_behavior) = REQUIRED];
218
219  // Optional. The function parameters and values in JSON object format.
220  optional google.protobuf.Struct args = 2
221      [(google.api.field_behavior) = OPTIONAL];
222}
223
224// The result output from a `FunctionCall` that contains a string
225// representing the `FunctionDeclaration.name` and a structured JSON
226// object containing any output from the function is used as context to
227// the model. This should contain the result of a`FunctionCall` made
228// based on model prediction.
229message FunctionResponse {
230  // Required. The name of the function to call.
231  // Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum
232  // length of 63.
233  string name = 1 [(google.api.field_behavior) = REQUIRED];
234
235  // Required. The function response in JSON object format.
236  google.protobuf.Struct response = 2 [(google.api.field_behavior) = REQUIRED];
237}
238
239// The `Schema` object allows the definition of input and output data types.
240// These types can be objects, but also primitives and arrays.
241// Represents a select subset of an [OpenAPI 3.0 schema
242// object](https://spec.openapis.org/oas/v3.0.3#schema).
243message Schema {
244  // Required. Data type.
245  Type type = 1 [(google.api.field_behavior) = REQUIRED];
246
247  // Optional. The format of the data. This is used only for primitive
248  // datatypes. Supported formats:
249  //  for NUMBER type: float, double
250  //  for INTEGER type: int32, int64
251  string format = 2 [(google.api.field_behavior) = OPTIONAL];
252
253  // Optional. A brief description of the parameter. This could contain examples
254  // of use. Parameter description may be formatted as Markdown.
255  string description = 3 [(google.api.field_behavior) = OPTIONAL];
256
257  // Optional. Indicates if the value may be null.
258  bool nullable = 4 [(google.api.field_behavior) = OPTIONAL];
259
260  // Optional. Possible values of the element of Type.STRING with enum format.
261  // For example we can define an Enum Direction as :
262  // {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]}
263  repeated string enum = 5 [(google.api.field_behavior) = OPTIONAL];
264
265  // Optional. Schema of the elements of Type.ARRAY.
266  optional Schema items = 6 [(google.api.field_behavior) = OPTIONAL];
267
268  // Optional. Properties of Type.OBJECT.
269  map<string, Schema> properties = 7 [(google.api.field_behavior) = OPTIONAL];
270
271  // Optional. Required properties of Type.OBJECT.
272  repeated string required = 8 [(google.api.field_behavior) = OPTIONAL];
273}
274
275// Passage included inline with a grounding configuration.
276message GroundingPassage {
277  // Identifier for the passage for attributing this passage in grounded
278  // answers.
279  string id = 1;
280
281  // Content of the passage.
282  Content content = 2;
283}
284
285// A repeated list of passages.
286message GroundingPassages {
287  // List of passages.
288  repeated GroundingPassage passages = 1;
289}
290