Foundation Models Text Generation API, gRPC: TextGenerationService.Completion
A method for generating text completions in synchronous mode.
gRPC request
rpc Completion (CompletionRequest) returns (stream CompletionResponse)
CompletionRequest
{
"model_uri": "string",
"completion_options": {
"stream": "bool",
"temperature": "google.protobuf.DoubleValue",
"max_tokens": "google.protobuf.Int64Value"
},
"messages": [
{
"role": "string",
// Includes only one of the fields `text`, `tool_call_list`, `tool_result_list`
"text": "string",
"tool_call_list": {
"tool_calls": [
{
// Includes only one of the fields `function_call`
"function_call": {
"name": "string",
"arguments": "google.protobuf.Struct"
}
// end of the list of possible fields
}
]
},
"tool_result_list": {
"tool_results": [
{
// Includes only one of the fields `function_result`
"function_result": {
"name": "string",
// Includes only one of the fields `content`
"content": "string"
// end of the list of possible fields
}
// end of the list of possible fields
}
]
}
// end of the list of possible fields
}
],
"tools": [
{
// Includes only one of the fields `function`
"function": {
"name": "string",
"description": "string",
"parameters": "google.protobuf.Struct"
}
// end of the list of possible fields
}
]
}
Request for the service to generate text completion.
Field |
Description |
model_uri |
string The ID of the model to be used for completion generation. |
completion_options |
Configuration options for completion generation. |
messages[] |
A list of messages representing the context for the completion model. |
tools[] |
List of tools that are available for the model to invoke during the completion generation. |
CompletionOptions
Defines the options for completion generation.
Field |
Description |
stream |
bool Enables streaming of partially generated text. |
temperature |
Affects creativity and randomness of responses. Should be a double number between 0 (inclusive) and 1 (inclusive). |
max_tokens |
The limit on the number of tokens used for single completion generation. |
Message
A message object representing a wrapper over the inputs and outputs of the completion model.
Field |
Description |
role |
string The ID of the message sender. Supported roles:
|
text |
string Textual content of the message. Includes only one of the fields Message content. |
tool_call_list |
List of tool calls made by the model as part of the response generation. Includes only one of the fields Message content. |
tool_result_list |
List of tool results returned from external tools that were invoked by the model. Includes only one of the fields Message content. |
ToolCallList
Represents a list of tool calls.
Field |
Description |
tool_calls[] |
A list of tool calls to be executed. |
ToolCall
Represents a call to a tool.
Field |
Description |
function_call |
Represents a call to a function. Includes only one of the fields |
FunctionCall
Represents the invocation of a function with specific arguments.
Field |
Description |
name |
string The name of the function being called. |
arguments |
The structured arguments passed to the function. |
ToolResultList
Represents a list of tool results.
Field |
Description |
tool_results[] |
A list of tool results. |
ToolResult
Represents the result of a tool call.
Field |
Description |
function_result |
Represents the result of a function call. Includes only one of the fields |
FunctionResult
Represents the result of a function call.
Field |
Description |
name |
string The name of the function that was executed. |
content |
string The result of the function call, represented as a string. Includes only one of the fields |
Tool
Represents a tool that can be invoked during completion generation.
Field |
Description |
function |
Represents a function that can be called. Includes only one of the fields |
FunctionTool
Represents a function tool that can be invoked during completion generation.
Field |
Description |
name |
string The name of the function. |
description |
string A description of the function's purpose or behavior. |
parameters |
A JSON Schema that defines the expected parameters for the function. |
CompletionResponse
{
"alternatives": [
{
"message": {
"role": "string",
// Includes only one of the fields `text`, `tool_call_list`, `tool_result_list`
"text": "string",
"tool_call_list": {
"tool_calls": [
{
// Includes only one of the fields `function_call`
"function_call": {
"name": "string",
"arguments": "google.protobuf.Struct"
}
// end of the list of possible fields
}
]
},
"tool_result_list": {
"tool_results": [
{
// Includes only one of the fields `function_result`
"function_result": {
"name": "string",
// Includes only one of the fields `content`
"content": "string"
// end of the list of possible fields
}
// end of the list of possible fields
}
]
}
// end of the list of possible fields
},
"status": "AlternativeStatus"
}
],
"usage": {
"input_text_tokens": "int64",
"completion_tokens": "int64",
"total_tokens": "int64"
},
"model_version": "string"
}
Response containing generated text completions.
Field |
Description |
alternatives[] |
A list of generated completion alternatives. |
usage |
A set of statistics describing the number of content tokens used by the completion model. |
model_version |
string The model version changes with each new releases. |
Alternative
Represents a generated completion alternative, including its content and generation status.
Field |
Description |
message |
A message with the content of the alternative. |
status |
enum AlternativeStatus The generation status of the alternative.
|
Message
A message object representing a wrapper over the inputs and outputs of the completion model.
Field |
Description |
role |
string The ID of the message sender. Supported roles:
|
text |
string Textual content of the message. Includes only one of the fields Message content. |
tool_call_list |
List of tool calls made by the model as part of the response generation. Includes only one of the fields Message content. |
tool_result_list |
List of tool results returned from external tools that were invoked by the model. Includes only one of the fields Message content. |
ToolCallList
Represents a list of tool calls.
Field |
Description |
tool_calls[] |
A list of tool calls to be executed. |
ToolCall
Represents a call to a tool.
Field |
Description |
function_call |
Represents a call to a function. Includes only one of the fields |
FunctionCall
Represents the invocation of a function with specific arguments.
Field |
Description |
name |
string The name of the function being called. |
arguments |
The structured arguments passed to the function. |
ToolResultList
Represents a list of tool results.
Field |
Description |
tool_results[] |
A list of tool results. |
ToolResult
Represents the result of a tool call.
Field |
Description |
function_result |
Represents the result of a function call. Includes only one of the fields |
FunctionResult
Represents the result of a function call.
Field |
Description |
name |
string The name of the function that was executed. |
content |
string The result of the function call, represented as a string. Includes only one of the fields |
ContentUsage
An object representing the number of content tokens used by the completion model.
Field |
Description |
input_text_tokens |
int64 The number of tokens in the textual part of the model input. |
completion_tokens |
int64 The number of tokens in the generated completion. |
total_tokens |
int64 The total number of tokens, including all input tokens and all generated tokens. |