curl -X POST https://generativelanguage.googleapis.com/v1beta/interactions \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-flash-latest",
"tools": [{
"type": "function",
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}],
"input": "What is the weather like in Boston, MA?"
}'
from google import genai
client = genai.Client()
response = client.interactions.create(
model="gemini-flash-latest",
tools=[{
"type": "function",
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": (
"The city and state, e.g. San Francisco, CA"
),
}
},
"required": ["location"],
},
}],
input="What is the weather like in Boston?",
)
print(response.steps[-1])
import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: 'gemini-flash-latest',
tools: [
{
type: 'function',
name: 'get_weather',
description: 'Get the current weather in a given location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
],
input: 'What is the weather like in Boston?',
});
console.log(interaction.steps.at(-1));
import com.google.genai.Client;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Function;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Step;
Client client = new Client();
Map parameters =
Map.of(
"type", "object",
"properties",
Map.of(
"location",
Map.of(
"type", "string",
"description", "The city and state, e.g. San Francisco, CA")),
"required", List.of("location"));
Function functionTool =
Function.builder()
.name("get_weather")
.description("Get the current weather in a given location")
.parameters(parameters)
.build();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model("gemini-flash-latest")
.tools(List.of(functionTool))
.input(InteractionsInput.of("What is the weather like in Boston?"))
.build();
CreateInteractionResponse response =
client.interactions.create(CreateInteractionRequestBody.of(params));
Interaction interaction =
response.interaction().orElseThrow(() -> new RuntimeException("No interaction returned"));
List steps = interaction.steps().orElse(List.of());
if (!steps.isEmpty()) {
System.out.println(steps.get(steps.size() - 1));
}
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
gaos_interactions "google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
function := gaos_interactions.Function{
Name: genai.Ptr("get_weather"),
Description: genai.Ptr("Get the current weather in a given location"),
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"location": map[string]any{
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
},
"required": []string{"location"},
},
}
tool := gaos_interactions.NewTool(function)
body := operations.NewCreateInteractionRequestBody(gaos_interactions.CreateModelInteraction{
Model: gaos_interactions.Model("gemini-flash-latest"),
Input: genai.Ptr(gaos_interactions.NewInteractionsInput("What is the weather like in Boston, MA?")),
Tools: []gaos_interactions.Tool{tool},
})
req := operations.CreateInteractionRequest{
Body: body,
}
res, err := client.Interactions.Create(ctx, req)
if err != nil {
log.Fatal(err)
}
if res.Interaction != nil {
for _, step := range res.Interaction.Steps {
if step.FunctionCallStep != nil {
fmt.Println("Function Call:", step.FunctionCallStep.Name)
fmt.Println("Arguments:", step.FunctionCallStep.Arguments)
}
}
}
}