ইন্টারঅ্যাকশন API

ইন্টারঅ্যাকশনস এপিআই ( বিটা ) হলো জেমিনি মডেল এবং এজেন্টদের সাথে যোগাযোগের জন্য একটি সমন্বিত ইন্টারফেস। generateContent এপিআই-এর একটি উন্নত বিকল্প হিসেবে, এটি স্টেট ম্যানেজমেন্ট, টুল অর্কেস্ট্রেশন এবং দীর্ঘমেয়াদী কাজগুলোকে সহজ করে। এপিআই স্কিমার একটি বিস্তারিত চিত্র পেতে, এপিআই রেফারেন্স দেখুন। বিটা চলাকালীন, ফিচার এবং স্কিমাগুলোতে বড় ধরনের পরিবর্তন আসতে পারে। দ্রুত শুরু করার জন্য, ইন্টারঅ্যাকশনস এপিআই কুইকস্টার্ট নোটবুকটি ব্যবহার করে দেখুন।

কল করে

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি টেক্সট প্রম্পট দিয়ে ইন্টারঅ্যাকশনস এপিআই কল করতে হয়।

পাইথন

from google import genai

client = genai.Client()

interaction =  client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me a short joke about programming."
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction =  await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a short joke about programming.',
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a short joke about programming."
}'

মৌলিক মিথস্ক্রিয়া

ইন্টারঅ্যাকশনস এপিআই আমাদের বিদ্যমান এসডিকে-গুলোর মাধ্যমে উপলব্ধ। মডেলের সাথে ইন্টারঅ্যাক্ট করার সবচেয়ে সহজ উপায় হলো একটি টেক্সট প্রম্পট প্রদান করা। input একটি স্ট্রিং, কন্টেন্ট অবজেক্ট সম্বলিত একটি তালিকা, অথবা রোল এবং কন্টেন্ট অবজেক্ট সহ টার্নের একটি তালিকা হতে পারে।

পাইথন

from google import genai

client = genai.Client()

interaction =  client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me a short joke about programming."
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction =  await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a short joke about programming.',
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a short joke about programming."
}'

কথোপকথন

আপনি দুইভাবে একাধিক পালাবিশিষ্ট কথোপকথন গড়ে তুলতে পারেন:

  • পূর্ববর্তী কথোপকথনের উল্লেখ করে অবস্থা ব্যক্ত করে
  • সম্পূর্ণ কথোপকথনের ইতিহাস প্রদান করে রাষ্ট্রহীনভাবে

স্টেটফুল কথোপকথন

কথোপকথন চালিয়ে যেতে, পূর্ববর্তী ইন্টারঅ্যাকশনের id previous_interaction_id প্যারামিটারে পাঠান। এপিআই কথোপকথনের ইতিহাস মনে রাখে, তাই আপনাকে শুধু নতুন ইনপুট পাঠাতে হবে। কোন ফিল্ডগুলো উত্তরাধিকারসূত্রে প্রাপ্ত হয় এবং কোনগুলো পুনরায় নির্দিষ্ট করতে হবে, সে সম্পর্কে বিস্তারিত জানতে সার্ভার-সাইড স্টেট ম্যানেজমেন্ট দেখুন।

পাইথন

from google import genai

client = genai.Client()

# 1. First turn
interaction1 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Hi, my name is Phil."
)
print(f"Model: {interaction1.outputs[-1].text}")

# 2. Second turn (passing previous_interaction_id)
interaction2 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is my name?",
    previous_interaction_id=interaction1.id
)
print(f"Model: {interaction2.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. First turn
const interaction1 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Hi, my name is Phil.'
});
console.log(`Model: ${interaction1.outputs[interaction1.outputs.length - 1].text}`);

// 2. Second turn (passing previous_interaction_id)
const interaction2 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What is my name?',
    previous_interaction_id: interaction1.id
});
console.log(`Model: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);

বিশ্রাম

# 1. First turn
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Hi, my name is Phil."
}'

# 2. Second turn (Replace INTERACTION_ID with the ID from the previous interaction)
# curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
# -H "Content-Type: application/json" \
# -H "x-goog-api-key: $GEMINI_API_KEY" \
# -d '{
#     "model": "gemini-3-flash-preview",
#     "input": "What is my name?",
#     "previous_interaction_id": "INTERACTION_ID"
# }'

অতীতের অবস্থাপূর্ণ মিথস্ক্রিয়া পুনরুদ্ধার করুন

ইন্টারঅ্যাকশন id ব্যবহার করে কথোপকথনের পূর্ববর্তী পালাগুলো পুনরুদ্ধার করা।

পাইথন

previous_interaction = client.interactions.get("<YOUR_INTERACTION_ID>")

print(previous_interaction)

জাভাস্ক্রিপ্ট

const previous_interaction = await client.interactions.get("<YOUR_INTERACTION_ID>");
console.log(previous_interaction);

বিশ্রাম

curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/<YOUR_INTERACTION_ID>" \
-H "x-goog-api-key: $GEMINI_API_KEY"

মূল ইনপুট অন্তর্ভুক্ত করুন

ডিফল্টরূপে, interactions.get() শুধুমাত্র মডেলের আউটপুটগুলো ফেরত দেয়। রেসপন্সে মূল নর্মালাইজড ইনপুট অন্তর্ভুক্ত করতে, include_input কে true সেট করুন।

পাইথন

interaction = client.interactions.get(
    "<YOUR_INTERACTION_ID>",
    include_input=True
)

print(f"Input: {interaction.input}")
print(f"Output: {interaction.outputs}")

জাভাস্ক্রিপ্ট

const interaction = await client.interactions.get(
    "<YOUR_INTERACTION_ID>",
    { include_input: true }
);

console.log(`Input: ${JSON.stringify(interaction.input)}`);
console.log(`Output: ${JSON.stringify(interaction.outputs)}`);

বিশ্রাম

curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/<YOUR_INTERACTION_ID>?include_input=true" \
-H "x-goog-api-key: $GEMINI_API_KEY"

রাষ্ট্রহীন কথোপকথন

আপনি ক্লায়েন্ট সাইডে কথোপকথনের ইতিহাস ম্যানুয়ালি পরিচালনা করতে পারেন।

পাইথন

from google import genai

client = genai.Client()

conversation_history = [
    {
        "role": "user",
        "content": "What are the three largest cities in Spain?"
    }
]

interaction1 = client.interactions.create(
    model="gemini-3-flash-preview",
    input=conversation_history
)

print(f"Model: {interaction1.outputs[-1].text}")

conversation_history.append({"role": "model", "content": interaction1.outputs})
conversation_history.append({
    "role": "user",
    "content": "What is the most famous landmark in the second one?"
})

interaction2 = client.interactions.create(
    model="gemini-3-flash-preview",
    input=conversation_history
)

print(f"Model: {interaction2.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const conversationHistory = [
    {
        role: 'user',
        content: "What are the three largest cities in Spain?"
    }
];

const interaction1 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: conversationHistory
});

console.log(`Model: ${interaction1.outputs[interaction1.outputs.length - 1].text}`);

conversationHistory.push({ role: 'model', content: interaction1.outputs });
conversationHistory.push({
    role: 'user',
    content: "What is the most famous landmark in the second one?"
});

const interaction2 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: conversationHistory
});

console.log(`Model: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);

বিশ্রাম

 curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
 -H "Content-Type: application/json" \
 -H "x-goog-api-key: $GEMINI_API_KEY" \
 -d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {
            "role": "user",
            "content": "What are the three largest cities in Spain?"
        },
        {
            "role": "model",
            "content": "The three largest cities in Spain are Madrid, Barcelona, and Valencia."
        },
        {
            "role": "user",
            "content": "What is the most famous landmark in the second one?"
        }
    ]
}'

বহুমুখী সক্ষমতা

আপনি ইমেজ আন্ডারস্ট্যান্ডিং বা ভিডিও জেনারেশনের মতো মাল্টিমোডাল ব্যবহারের ক্ষেত্রে ইন্টারঅ্যাকশনস এপিআই ব্যবহার করতে পারেন।

বহুমাধ্যমীয় বোঝাপড়া

আপনি বেস৬৪-এনকোডেড ডেটা হিসেবে ইনলাইনে, বড় ফাইলের জন্য ফাইলস এপিআই ব্যবহার করে, অথবা ইউআরআই ফিল্ডে একটি সর্বজনীনভাবে অ্যাক্সেসযোগ্য লিঙ্ক পাস করে মাল্টিমোডাল ইনপুট প্রদান করতে পারেন। নিম্নলিখিত কোড নমুনাগুলো পাবলিক ইউআরএল পদ্ধতিটি প্রদর্শন করে।

চিত্র বোঝা

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "Describe the image."},
        {
            "type": "image",
            "uri": "YOUR_URL",
            "mime_type": "image/png"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import {GoogleGenAI} from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        {type: 'text', text: 'Describe the image.'},
        {
            type: 'image',
            uri: 'YOUR_URL',
            mime_type: 'image/png'
        }
    ]
});
console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

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-3-flash-preview",
    "input": [
    {
        "type": "text",
        "text": "Describe the image."
    },
    {
        "type": "image",
        "uri": "YOUR_URL",
        "mime_type": "image/png"
    }
    ]
}'

শ্রবণ বোধগম্যতা

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What does this audio say?"},
        {
            "type": "audio",
            "uri": "YOUR_URL",
            "mime_type": "audio/wav"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What does this audio say?' },
        {
            type: 'audio',
            uri: 'YOUR_URL',
            mime_type: 'audio/wav'
        }
    ]
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What does this audio say?"},
        {
            "type": "audio",
            "uri": "YOUR_URL",
            "mime_type": "audio/wav"
        }
    ]
}'

ভিডিও বোঝা

পাইথন

from google import genai
client = genai.Client()

print("Analyzing video...")
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What is happening in this video? Provide a timestamped summary."},
        {
            "type": "video",
            "uri": "YOUR_URL",
            "mime_type": "video/mp4"
        }
    ]
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

console.log('Analyzing video...');
const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What is happening in this video? Provide a timestamped summary.' },
        {
            type: 'video',
            uri: 'YOUR_URL',
            mime_type: 'video/mp4'
        }
    ]
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What is happening in this video?"},
        {
            "type": "video",
            "uri": "YOUR_URL",
            "mime_type": "video/mp4"
        }
    ]
}'

নথি (পিডিএফ) বোঝা

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What is this document about?"},
        {
            "type": "document",
            "uri": "YOUR_URL",
            "mime_type": "application/pdf"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What is this document about?' },
        {
            type: 'document',
            uri: 'YOUR_URL',
            mime_type: 'application/pdf'
        }
    ],
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What is this document about?"},
        {
            "type": "document",
            "uri": "YOUR_URL",
            "mime_type": "application/pdf"
        }
    ]
}'

মাল্টিমোডাল জেনারেশন

আপনি মাল্টিমোডাল আউটপুট তৈরি করতে ইন্টারঅ্যাকশনস এপিআই ব্যবহার করতে পারেন।

চিত্র তৈরি

পাইথন

import base64
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-pro-image-preview",
    input="Generate an image of a futuristic city.",
    response_modalities=["IMAGE"]
)

for output in interaction.outputs:
    if output.type == "image":
        print(f"Generated image with mime_type: {output.mime_type}")
        # Save the image
        with open("generated_city.png", "wb") as f:
            f.write(base64.b64decode(output.data))

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-pro-image-preview',
    input: 'Generate an image of a futuristic city.',
    response_modalities: ['IMAGE']
});

for (const output of interaction.outputs) {
    if (output.type === 'image') {
        console.log(`Generated image with mime_type: ${output.mime_type}`);
        // Save the image
        fs.writeFileSync('generated_city.png', Buffer.from(output.data, 'base64'));
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-pro-image-preview",
    "input": "Generate an image of a futuristic city.",
    "response_modalities": ["IMAGE"]
}'
ইমেজ আউটপুট কনফিগার করুন

আপনি generation_config মধ্যে থাকা image_config ব্যবহার করে তৈরি হওয়া ছবিগুলোর অ্যাস্পেক্ট রেশিও এবং রেজোলিউশন নিয়ন্ত্রণ করতে পারেন।

প্যারামিটার বিকল্প বর্ণনা
aspect_ratio 1:1 , 2:3 , 3:2 , 3:4 , 4:3 , 4:5 , 5:4 , 9:16 , 16:9 , 21:9 আউটপুট ছবির প্রস্থ ও উচ্চতার অনুপাত নিয়ন্ত্রণ করে।
image_size 1k , 2k , 4k আউটপুট ছবির রেজোলিউশন নির্ধারণ করে।

পাইথন

import base64
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-pro-image-preview",
    input="Generate an image of a futuristic city.",
    generation_config={
        "image_config": {
            "aspect_ratio": "9:16",
            "image_size": "2k"
        }
    }
)

for output in interaction.outputs:
    if output.type == "image":
        print(f"Generated image with mime_type: {output.mime_type}")
        # Save the image
        with open("generated_city.png", "wb") as f:
            f.write(base64.b64decode(output.data))

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-pro-image-preview',
    input: 'Generate an image of a futuristic city.',
    generation_config: {
        image_config: {
            aspect_ratio: '9:16',
            image_size: '2k'
        }
    }
});

for (const output of interaction.outputs) {
    if (output.type === 'image') {
        console.log(`Generated image with mime_type: ${output.mime_type}`);
        // Save the image
        fs.writeFileSync('generated_city.png', Buffer.from(output.data, 'base64'));
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-pro-image-preview",
    "input": "Generate an image of a futuristic city.",
    "generation_config": {
        "image_config": {
            "aspect_ratio": "9:16",
            "image_size": "2k"
        }
    }
}'

বক্তৃতা তৈরি

টেক্সট-টু-স্পিচ (TTS) মডেল ব্যবহার করে টেক্সট থেকে স্বাভাবিক শোনায় এমন কথা তৈরি করুন। speech_config প্যারামিটার দিয়ে ভয়েস, ভাষা এবং স্পিকার সেটিংস কনফিগার করুন।

পাইথন

import base64
from google import genai
import wave

# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
    with wave.open(filename, "wb") as wf:
        wf.setnchannels(channels)
        wf.setsampwidth(sample_width)
        wf.setframerate(rate)
        wf.writeframes(pcm)

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-2.5-flash-preview-tts",
    input="Say the following: WOOHOO This is so much fun!.",
    response_modalities=["AUDIO"],
    generation_config={
        "speech_config": {
            "language": "en-us",
            "voice": "kore"
        }
    }
)

for output in interaction.outputs:
    if output.type == "audio":
        print(f"Generated audio with mime_type: {output.mime_type}")
        # Save the audio as wave file to the current directory.
        wave_file("generated_audio.wav", base64.b64decode(output.data))

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
import wav from 'wav';

async function saveWaveFile(
    filename,
    pcmData,
    channels = 1,
    rate = 24000,
    sampleWidth = 2,
) {
    return new Promise((resolve, reject) => {
        const writer = new wav.FileWriter(filename, {
                channels,
                sampleRate: rate,
                bitDepth: sampleWidth * 8,
        });

        writer.on('finish', resolve);
        writer.on('error', reject);

        writer.write(pcmData);
        writer.end();
    });
}

async function main() {
    const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
    const client = new GoogleGenAI({apiKey: GEMINI_API_KEY});

    const interaction = await client.interactions.create({
        model: 'gemini-2.5-flash-preview-tts',
        input: 'Say the following: WOOHOO This is so much fun!.',
        response_modalities: ['AUDIO'],
        generation_config: {
            speech_config: {
                language: "en-us",
                voice: "kore"
            }
        }
    });

    for (const output of interaction.outputs) {
        if (output.type === 'audio') {
            console.log(`Generated audio with mime_type: ${output.mime_type}`);
            const audioBuffer = Buffer.from(output.data, 'base64');
            // Save the audio as wave file to the current directory
            await saveWaveFile("generated_audio.wav", audioBuffer);
        }
    }
}
await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-flash-preview-tts",
    "input": "Say the following: WOOHOO This is so much fun!.",
    "response_modalities": ["AUDIO"],
    "generation_config": {
        "speech_config": {
            "language": "en-us",
            "voice": "kore"
        }
    }
}' | jq -r '.outputs[] | select(.type == "audio") | .data' | base64 -d > generated_audio.pcm
# You may need to install ffmpeg.
ffmpeg -f s16le -ar 24000 -ac 1 -i generated_audio.pcm generated_audio.wav
একাধিক বক্তার বক্তৃতা তৈরি

প্রম্পটে স্পিকারের নাম উল্লেখ করে এবং speech_config এ সেগুলোকে মিলিয়ে একাধিক স্পিকার দিয়ে স্পিচ তৈরি করুন।

প্রম্পটে বক্তাদের নাম অন্তর্ভুক্ত থাকা উচিত:

TTS the following conversation between Alice and Bob:
Alice: Hi Bob, how are you doing today?
Bob: I'm doing great, thanks for asking! How about you?
Alice: Fantastic! I just learned about the Gemini API.

তারপর উপযুক্ত স্পিকার দিয়ে speech_config কনফিগার করুন:

"generation_config": {
    "speech_config": [
        {"voice": "Zephyr", "speaker": "Alice", "language": "en-US"},
        {"voice": "Puck", "speaker": "Bob", "language": "en-US"}
    ]
}

সঙ্গীত প্রজন্ম

Lyria 3 মডেল ব্যবহার করে টেক্সট প্রম্পট থেকে উচ্চ মানের সঙ্গীত তৈরি করুন। ইন্টারঅ্যাকশনস এপিআই (Interactions API) ছোট ক্লিপ এবং ভোকাল, লিরিক্স ও ইন্সট্রুমেন্টাল অ্যারেঞ্জমেন্ট সহ পূর্ণ দৈর্ঘ্যের গান উভয়ই সমর্থন করে।

কাস্টম লিরিক্স, টাইমিং কন্ট্রোল এবং ইমেজ-টু-মিউজিক সহ সম্পূর্ণ মিউজিক জেনারেশন গাইডের জন্য, 'Generate music with Lyria 3 ' দেখুন।

পাইথন

import base64
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="lyria-3-clip-preview",
    input="Create a 30-second cheerful acoustic folk song with "
          "guitar and harmonica.",
    response_modalities=["AUDIO", "TEXT"]
)

for output in interaction.outputs:
    if output.type == "audio":
        print(f"Generated audio with mime_type: {output.mime_type}")
        with open("music.mp3", "wb") as f:
            f.write(base64.b64decode(output.data))
    elif output.type == "text":
        print(f"Lyrics: {output.text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'lyria-3-clip-preview',
    input: 'Create a 30-second cheerful acoustic folk song with ' +
           'guitar and harmonica.',
    response_modalities: ['AUDIO', 'TEXT']
});

for (const output of interaction.outputs) {
    if (output.type === 'audio') {
        console.log(`Generated audio with mime_type: ${output.mime_type}`);
        fs.writeFileSync('music.mp3', Buffer.from(output.data, 'base64'));
    } else if (output.type === 'text') {
        console.log(`Lyrics: ${output.text}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "lyria-3-clip-preview",
    "input": "Create a 30-second cheerful acoustic folk song with guitar and harmonica.",
    "response_modalities": ["AUDIO", "TEXT"]
}'

সম্পূর্ণ দৈর্ঘ্যের গানের (প্রায় ৪ মিনিট পর্যন্ত) জন্য lyria-3-pro-preview মডেলটি ব্যবহার করুন:

পাইথন

interaction = client.interactions.create(
    model="lyria-3-pro-preview",
    input="An epic cinematic orchestral piece about a journey home. "
          "Starts with a solo piano intro, builds through sweeping "
          "strings, and climaxes with a massive wall of sound.",
    response_modalities=["AUDIO", "TEXT"]
)

জাভাস্ক্রিপ্ট

const interaction = await client.interactions.create({
    model: 'lyria-3-pro-preview',
    input: 'An epic cinematic orchestral piece about a journey home. ' +
           'Starts with a solo piano intro, builds through sweeping ' +
           'strings, and climaxes with a massive wall of sound.',
    response_modalities: ['AUDIO', 'TEXT']
});

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "lyria-3-pro-preview",
    "input": "An epic cinematic orchestral piece about a journey home. Starts with a solo piano intro, builds through sweeping strings, and climaxes with a massive wall of sound.",
    "response_modalities": ["AUDIO", "TEXT"]
}'

সক্রিয় ক্ষমতা

ইন্টারঅ্যাকশনস এপিআইটি এজেন্ট তৈরি এবং তাদের সাথে মিথস্ক্রিয়া করার জন্য ডিজাইন করা হয়েছে এবং এতে ফাংশন কলিং, বিল্ট-ইন টুলস, স্ট্রাকচার্ড আউটপুট এবং মডেল কনটেক্সট প্রোটোকল (এমসিপি)-এর সমর্থন অন্তর্ভুক্ত রয়েছে।

এজেন্টরা

জটিল কাজের জন্য আপনি deep-research-pro-preview-12-2025 মতো বিশেষায়িত এজেন্ট ব্যবহার করতে পারেন। জেমিনি ডিপ রিসার্চ এজেন্ট সম্পর্কে আরও জানতে, ডিপ রিসার্চ গাইডটি দেখুন।

পাইথন

import time
from google import genai

client = genai.Client()

# 1. Start the Deep Research Agent
initial_interaction = client.interactions.create(
    input="Research the history of the Google TPUs with a focus on 2025 and 2026.",
    agent="deep-research-pro-preview-12-2025",
    background=True
)

print(f"Research started. Interaction ID: {initial_interaction.id}")

# 2. Poll for results
while True:
    interaction = client.interactions.get(initial_interaction.id)
    print(f"Status: {interaction.status}")

    if interaction.status == "completed":
        print("\nFinal Report:\n", interaction.outputs[-1].text)
        break
    elif interaction.status in ["failed", "cancelled"]:
        print(f"Failed with status: {interaction.status}")
        break

    time.sleep(10)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. Start the Deep Research Agent
const initialInteraction = await client.interactions.create({
    input: 'Research the history of the Google TPUs with a focus on 2025 and 2026.',
    agent: 'deep-research-pro-preview-12-2025',
    background: true
});

console.log(`Research started. Interaction ID: ${initialInteraction.id}`);

// 2. Poll for results
while (true) {
    const interaction = await client.interactions.get(initialInteraction.id);
    console.log(`Status: ${interaction.status}`);

    if (interaction.status === 'completed') {
        console.log('\nFinal Report:\n', interaction.outputs[interaction.outputs.length - 1].text);
        break;
    } else if (['failed', 'cancelled'].includes(interaction.status)) {
        console.log(`Failed with status: ${interaction.status}`);
        break;
    }

    await new Promise(resolve => setTimeout(resolve, 10000));
}

বিশ্রাম

# 1. Start the Deep Research Agent
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "input": "Research the history of the Google TPUs with a focus on 2025 and 2026.",
    "agent": "deep-research-pro-preview-12-2025",
    "background": true
}'

# 2. Poll for results (Replace INTERACTION_ID with the ID from the previous interaction)
# curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/INTERACTION_ID" \
# -H "x-goog-api-key: $GEMINI_API_KEY"

সরঞ্জাম এবং ফাংশন কলিং

এই অংশে ফাংশন কলিং ব্যবহার করে কীভাবে কাস্টম টুল তৈরি করতে হয় এবং ইন্টারঅ্যাকশনস এপিআই (Interactions API)-এর মধ্যে গুগলের বিল্ট-ইন টুলগুলো কীভাবে ব্যবহার করতে হয়, তা ব্যাখ্যা করা হয়েছে।

ফাংশন কলিং

পাইথন

from google import genai

client = genai.Client()

# 1. Define the tool
def get_weather(location: str):
    """Gets the weather for a given location."""
    return f"The weather in {location} is sunny."

weather_tool = {
    "type": "function",
    "name": "get_weather",
    "description": "Gets the weather for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
        },
        "required": ["location"]
    }
}

# 2. Send the request with tools
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is the weather in Paris?",
    tools=[weather_tool]
)

# 3. Handle the tool call
for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Tool Call: {output.name}({output.arguments})")
        # Execute tool
        result = get_weather(**output.arguments)

        # Send result back
        interaction = client.interactions.create(
            model="gemini-3-flash-preview",
            previous_interaction_id=interaction.id,
            input=[{
                "type": "function_result",
                "name": output.name,
                "call_id": output.id,
                "result": result
            }]
        )
        print(f"Response: {interaction.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. Define the tool
const weatherTool = {
    type: 'function',
    name: 'get_weather',
    description: 'Gets the weather for a given location.',
    parameters: {
        type: 'object',
        properties: {
            location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA' }
        },
        required: ['location']
    }
};

// 2. Send the request with tools
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What is the weather in Paris?',
    tools: [weatherTool]
});

// 3. Handle the tool call
for (const output of interaction.outputs) {
    if (output.type === 'function_call') {
        console.log(`Tool Call: ${output.name}(${JSON.stringify(output.arguments)})`);

        // Execute tool (Mocked)
        const result = `The weather in ${output.arguments.location} is sunny.`;

        // Send result back
        interaction = await client.interactions.create({
            model: 'gemini-3-flash-preview',
            previous_interaction_id:interaction.id,
            input: [{
                type: 'function_result',
                name: output.name,
                call_id: output.id,
                result: result
            }]
        });
        console.log(`Response: ${interaction.outputs[interaction.outputs.length - 1].text}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the weather in Paris?",
    "tools": [{
        "type": "function",
        "name": "get_weather",
        "description": "Gets the weather for a given location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
            },
            "required": ["location"]
        }
    }]
}'

# Handle the tool call and send result back (Replace INTERACTION_ID and CALL_ID)
# curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
# -H "Content-Type: application/json" \
# -H "x-goog-api-key: $GEMINI_API_KEY" \
# -d '{
#     "model": "gemini-3-flash-preview",
#     "previous_interaction_id": "INTERACTION_ID",
#     "input": [{
#         "type": "function_result",
#         "name": "get_weather",
#         "call_id": "FUNCTION_CALL_ID",
#         "result": "The weather in Paris is sunny."
#     }]
# }'
ক্লায়েন্ট-সাইড স্টেট দিয়ে ফাংশন কল করা

আপনি যদি সার্ভার-সাইড স্টেট ব্যবহার করতে না চান, তবে ক্লায়েন্ট সাইডেই সবকিছু পরিচালনা করতে পারেন।

পাইথন

from google import genai
client = genai.Client()

functions = [
    {
        "type": "function",
        "name": "schedule_meeting",
        "description": "Schedules a meeting with specified attendees at a given time and date.",
        "parameters": {
            "type": "object",
            "properties": {
                "attendees": {"type": "array", "items": {"type": "string"}},
                "date": {"type": "string", "description": "Date of the meeting (e.g., 2024-07-29)"},
                "time": {"type": "string", "description": "Time of the meeting (e.g., 15:00)"},
                "topic": {"type": "string", "description": "The subject of the meeting."},
            },
            "required": ["attendees", "date", "time", "topic"],
        },
    }
]

history = [{"role": "user","content": [{"type": "text", "text": "Schedule a meeting for 2025-11-01 at 10 am with Peter and Amir about the Next Gen API."}]}]

# 1. Model decides to call the function
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=history,
    tools=functions
)

# add model interaction back to history
history.append({"role": "model", "content": interaction.outputs})

for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Function call: {output.name} with arguments {output.arguments}")

        # 2. Execute the function and get a result
        # In a real app, you would call your function here.
        # call_result = schedule_meeting(**json.loads(output.arguments))
        call_result = "Meeting scheduled successfully."

        # 3. Send the result back to the model
        history.append({"role": "user", "content": [{"type": "function_result", "name": output.name, "call_id": output.id, "result": call_result}]})

        interaction2 = client.interactions.create(
            model="gemini-3-flash-preview",
            input=history,
        )
        print(f"Final response: {interaction2.outputs[-1].text}")
    else:
        print(f"Output: {output}")

জাভাস্ক্রিপ্ট

// 1. Define the tool
const functions = [
    {
        type: 'function',
        name: 'schedule_meeting',
        description: 'Schedules a meeting with specified attendees at a given time and date.',
        parameters: {
            type: 'object',
            properties: {
                attendees: { type: 'array', items: { type: 'string' } },
                date: { type: 'string', description: 'Date of the meeting (e.g., 2024-07-29)' },
                time: { type: 'string', description: 'Time of the meeting (e.g., 15:00)' },
                topic: { type: 'string', description: 'The subject of the meeting.' },
            },
            required: ['attendees', 'date', 'time', 'topic'],
        },
    },
];

const history = [
    { role: 'user', content: [{ type: 'text', text: 'Schedule a meeting for 2025-11-01 at 10 am with Peter and Amir about the Next Gen API.' }] }
];

// 2. Model decides to call the function
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: history,
    tools: functions
});

// add model interaction back to history
history.push({ role: 'model', content: interaction.outputs });

for (const output of interaction.outputs) {
    if (output.type === 'function_call') {
        console.log(`Function call: ${output.name} with arguments ${JSON.stringify(output.arguments)}`);

        // 3. Send the result back to the model
        history.push({ role: 'user', content: [{ type: 'function_result', name: output.name, call_id: output.id, result: 'Meeting scheduled successfully.' }] });

        const interaction2 = await client.interactions.create({
            model: 'gemini-3-flash-preview',
            input: history,
        });
        console.log(`Final response: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);
    }
}
মাল্টিমোডাল ফাংশনের ফলাফল

function_result এর ` result ফিল্ডটি একটি সাধারণ স্ট্রিং অথবা TextContent এবং ImageContent অবজেক্টের একটি অ্যারে গ্রহণ করে। এর ফলে আপনি আপনার ফাংশন কল থেকে প্রাপ্ত টেক্সটের পাশাপাশি স্ক্রিনশট বা চার্টের মতো ছবিও রিটার্ন করতে পারেন, যাতে মডেলটি সেই ভিজ্যুয়াল আউটপুটের ওপর ভিত্তি করে সিদ্ধান্ত নিতে পারে।

পাইথন

import base64
from google import genai

client = genai.Client()

functions = [
    {
        "type": "function",
        "name": "take_screenshot",
        "description": "Takes a screenshot of a specified website.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL to take a screenshot of."},
            },
            "required": ["url"],
        },
    }
]

# 1. Model decides to call the function
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Can you take a screenshot of https://google.com and tell me what you see?",
    tools=functions
)

for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Function call: {output.name}({output.arguments})")

        # 2. Execute the function and load the image
        # Replace with actual function call, pseudo code for reading image from disk
        with open("screenshot.png", "rb") as f:
            base64_image = base64.b64encode(f.read()).decode("utf-8")

        # 3. Return a multimodal result (text + image)
        call_result = [
            {"type": "text", "text": "Screenshot captured successfully."},
            {"type": "image", "mime_type": "image/png", "data": base64_image}
        ]

        response = client.interactions.create(
            model="gemini-3-flash-preview",
            tools=functions,
            previous_interaction_id=interaction.id,
            input=[{
                "type": "function_result",
                "name": output.name,
                "call_id": output.id,
                "result": call_result
            }]
        )
        print(f"Response: {response.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';

const client = new GoogleGenAI({});

const functions = [
    {
        type: 'function',
        name: 'take_screenshot',
        description: 'Takes a screenshot of a specified website.',
        parameters: {
            type: 'object',
            properties: {
                url: { type: 'string', description: 'The URL to take a screenshot of.' },
            },
            required: ['url'],
        },
    }
];

// 1. Model decides to call the function
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Can you take a screenshot of https://google.com and tell me what you see?',
    tools: functions
});

for (const output of interaction.outputs) {
    if (output.type === 'function_call') {
        console.log(`Function call: ${output.name}(${JSON.stringify(output.arguments)})`);

        // 2. Execute the function and load the image
        // Replace with actual function call, pseudo code for reading image from disk
        const base64Image = fs.readFileSync('screenshot.png').toString('base64');

        // 3. Return a multimodal result (text + image)
        const callResult = [
            { type: 'text', text: 'Screenshot captured successfully.' },
            { type: 'image', mime_type: 'image/png', data: base64Image }
        ];

        const response = await client.interactions.create({
            model: 'gemini-3-flash-preview',
            tools: functions,
            previous_interaction_id: interaction.id,
            input: [{
                type: 'function_result',
                name: output.name,
                call_id: output.id,
                result: callResult
            }]
        });
        console.log(`Response: ${response.outputs[response.outputs.length - 1].text}`);
    }
}

বিশ্রাম

# 1. Send request with tools (will return a function_call)
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Can you take a screenshot of https://google.com and tell me what you see?",
    "tools": [{
        "type": "function",
        "name": "take_screenshot",
        "description": "Takes a screenshot of a specified website.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL to take a screenshot of."}
            },
            "required": ["url"]
        }
    }]
}'

# 2. Send multimodal result back (Replace INTERACTION_ID, CALL_ID, and BASE64_IMAGE)
# curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
# -H "Content-Type: application/json" \
# -H "x-goog-api-key: $GEMINI_API_KEY" \
# -d '{
#     "model": "gemini-3-flash-preview",
#     "tools": [{"type": "function", "name": "take_screenshot", "description": "Takes a screenshot of a specified website.", "parameters": {"type": "object", "properties": {"url": {"type": "string"}}, "required": ["url"]}}],
#     "previous_interaction_id": "INTERACTION_ID",
#     "input": [{
#         "type": "function_result",
#         "name": "take_screenshot",
#         "call_id": "CALL_ID",
#         "result": [
#             {"type": "text", "text": "Screenshot captured successfully."},
#             {"type": "image", "mime_type": "image/png", "data": "BASE64_IMAGE"}
#         ]
#     }]
# }'

অন্তর্নির্মিত সরঞ্জাম

জেমিনিতে গুগল সার্চের মাধ্যমে গ্রাউন্ডিং , গুগল ইমেজ সার্চের মাধ্যমে গ্রাউন্ডিং , গুগল ম্যাপসের মাধ্যমে গ্রাউন্ডিং , কোড এক্সিকিউশন , ইউআরএল কনটেক্সট এবং কম্পিউটার ব্যবহারের মতো বিল্ট-ইন টুল রয়েছে।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Who won the last Super Bowl?",
    tools=[{"type": "google_search"}]
)
# Find the text output (not the GoogleSearchResultContent)
text_output = next((o for o in interaction.outputs if o.type == "text"), None)
if text_output:
    print(text_output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Who won the last Super Bowl?',
    tools: [{ type: 'google_search' }]
});
// Find the text output (not the GoogleSearchResultContent)
const textOutput = interaction.outputs.find(o => o.type === 'text');
if (textOutput) console.log(textOutput.text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Who won the last Super Bowl?",
    "tools": [{"type": "google_search"}]
}'
গুগল ইমেজ সার্চের মাধ্যমে প্রাথমিক ধারণা লাভ (শুধুমাত্র ৩.১ ফ্ল্যাশ ইমেজের জন্য)

গ্রাউন্ডিং উইথ গুগল ইমেজ সার্চ মডেলদেরকে ইমেজ তৈরির জন্য ভিজ্যুয়াল কনটেক্সট হিসেবে গুগল ইমেজ সার্চের মাধ্যমে প্রাপ্ত ওয়েব ইমেজ ব্যবহার করার সুযোগ দেয়। ইমেজ সার্চ হলো বিদ্যমান গ্রাউন্ডিং উইথ গুগল সার্চ টুলের অন্তর্ভুক্ত একটি নতুন ধরনের সার্চ, যা স্ট্যান্ডার্ড ওয়েব সার্চের পাশাপাশি কাজ করে।

google_search টুলের জন্য ছবির ফলাফল অনুরোধ করতে search_types অ্যারেতে "image_search" যোগ করুন।

পাইথন

interaction = client.interactions.create(
    model="gemini-3.1-flash-image-preview",
    input="Search for an image of a vintage gold bitcoin coin.",
    tools=[{
        "type": "google_search",
        "search_types": ["web_search", "image_search"]
    }]
)

জাভাস্ক্রিপ্ট

const interaction = await client.interactions.create({
    model: 'gemini-3.1-flash-image-preview',
    input: 'Search for an image of a vintage gold bitcoin coin.',
    tools: [{
        type: 'google_search',
        search_types: ['web_search', 'image_search']
    }]
});

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3.1-flash-image-preview",
    "input": "Search for an image of a vintage gold bitcoin coin.",
    "tools": [{
        "type": "google_search",
        "search_types": ["web_search", "image_search"]
    }]
}'
বাধ্যতামূলক প্রদর্শনের প্রয়োজনীয়তা

গুগল সার্চ পরিষেবার শর্তাবলী মেনে চলার জন্য, আপনার UI-তে অ্যাট্রিবিউশনের দুটি স্বতন্ত্র স্তর প্রয়োগ করতে হবে:

  1. গুগল সার্চ অ্যাট্রিবিউশন

    আপনাকে অবশ্যই google_search_result ব্লকে প্রদত্ত 'Check on Google' সার্চ সাজেশনগুলো প্রদর্শন করতে হবে।

    • ক্ষেত্র: rendered_content (HTML/CSS)
    • করণীয়: মডেলের প্রতিক্রিয়ার কাছাকাছি এই চিপটিকে হুবহু রেন্ডার করুন।
  2. প্রকাশকের কৃতিত্ব

    প্রদর্শিত প্রতিটি ছবির জন্য আপনাকে অবশ্যই 'ধারণকারী পৃষ্ঠা' (ল্যান্ডিং পৃষ্ঠা)-এর একটি লিঙ্ক প্রদান করতে হবে।

    • ক্ষেত্র: url ( result অ্যারের মধ্যে পাওয়া গেছে)
    • শর্ত: আপনাকে অবশ্যই ছবি থেকে এর উৎস ওয়েবপেজে সরাসরি, এক-ক্লিকের পথ প্রদান করতে হবে। মধ্যবর্তী ইমেজ ভিউয়ার বা একাধিক-ক্লিকের পথ ব্যবহার করার অনুমতি নেই।
গ্রাউন্ডেড প্রতিক্রিয়া পরিচালনা

নিম্নলিখিত কোড স্নিপেটটি দেখায় কিভাবে র ইমেজ ডেটা এবং বাধ্যতামূলক অ্যাট্রিবিউশন উভয়ের জন্য ইন্টারলিভড রেসপন্স ব্লকগুলি পরিচালনা করতে হয়।

পাইথন

for output in interaction.outputs:
    # 1. Handle raw multimodal image data
    if output.type == "image":
        print(f"🖼️ Image received: {output.mime_type}")
        # 'data' contains base64-encoded image content
        display_image(output.data, output.mime_type)
    # 2. Handle mandatory Search and Publisher attribution
    elif output.type == "google_search_result":
        # Display Google Search Attribution
        if output.rendered_content:
            render_html_chips(output.rendered_content)

        # Provide Publisher Attribution

        for source in output.result:
            print(f"Source Page: {source['url']}")

জাভাস্ক্রিপ্ট

for (const output of interaction.outputs) {
  // 1. Handle raw multimodal image data
  if (output.type === 'image') {
    console.log(`🖼️ Image received: ${output.mimeType}`);
    // 'data' contains base64-encoded image content
    displayImage(output.data, output.mimeType);
  }
    // 2. Handle mandatory Search and Publisher attribution
    else if (output.type === 'google_search_result') {
      // Display Google Search Attribution
      if (output.renderedContent) {
        renderHtmlChips(output.renderedContent);
      }

      // Provide Publisher Attribution

    for (const source of output.result) {
      console.log(`Source Page: ${source.url}`);
    }
  }
}
প্রত্যাশিত আউটপুট স্কিমা

ইমেজ ব্লক (টাইপ: "image" ) -এ মডেল দ্বারা তৈরি বা সংগৃহীত কাঁচা ভিজ্যুয়াল ডেটা থাকে।

{
  "type": "image",
  "mime_type": "image/png",
  "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB..." // Base64 content
}

রেজাল্ট ব্লক (টাইপ: "google_search_result" ) -এ সার্চের সাথে যুক্ত বাধ্যতামূলক অ্যাট্রিবিউশন মেটাডেটা থাকে।

{
  "type": "google_search_result",
  "call_id": "search_002",
  "rendered_content": "<div class=\"search-suggestions\">...</div>", // Google Search Attribution

  "result": [
    {
      "url": "https://example.com/source-page", // Publisher Attribution
      "title": "Source Page Title"
    }
  ]
}
গুগল ম্যাপস দিয়ে গ্রাউন্ডিং

গুগল ম্যাপসের সাহায্যে গ্রাউন্ডিং মডেলগুলোকে ভিজ্যুয়াল কনটেক্সট, ম্যাপ পিন এবং অবস্থান-ভিত্তিক ডিসকভারির জন্য গুগল ম্যাপসের ডেটা ব্যবহার করার সুযোগ দেয়।

পাইথন

from google import genai
client = genai.Client()
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What's the best coffee shop near me?",
    tools=[{"type": "google_maps"}]
)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What\'s the best coffee shop near me?',
    tools: [{ type: 'google_maps' }]
});

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the best coffee shop near me?",
    "tools": [{"type": "google_maps"}]
}'
পরিষেবা ব্যবহারের প্রয়োজনীয়তা

গ্রাউন্ডিং-এর মাধ্যমে গুগল ম্যাপস-এর ফলাফল উপস্থাপন করার সময়, আপনাকে অবশ্যই গুগল ম্যাপস-এর পরিষেবার শর্তাবলী অনুসরণ করতে হবে। আপনাকে অবশ্যই আপনার ব্যবহারকারীদের নিম্নলিখিত বিষয়গুলি সম্পর্কে জানাতে হবে এবং এই প্রদর্শনের প্রয়োজনীয়তাগুলি পূরণ করতে হবে:

  • ব্যবহারকারীকে অবহিত করুন : তৈরি হওয়া কন্টেন্টের সাথে সাথেই সংশ্লিষ্ট গুগল ম্যাপস সোর্সগুলো যুক্ত করুন। ব্যবহারকারীর একটিমাত্র ইন্টারঅ্যাকশনের মধ্যেই সোর্সগুলো দেখার ব্যবস্থা থাকতে হবে।
  • লিঙ্ক প্রদর্শন : প্রতিটি উৎসের জন্য একটি লিঙ্ক প্রিভিউ তৈরি করুন (যদি থাকে, তবে রিভিউ স্নিপেট সহ)।
  • "Google Maps"-এর অ্যাট্রিবিউশন : টেক্সট অ্যাট্রিবিউশন নির্দেশিকা অনুসরণ করুন।
  • উৎসের শিরোনাম প্রদর্শন করুন
  • প্রদত্ত URL ব্যবহার করে উৎসের সাথে লিঙ্ক করুন
  • কৃতিত্ব প্রদানের নির্দেশিকা : "Google Maps" লেখাটি পরিবর্তন করবেন না (যেমন বড় হাতের অক্ষর ব্যবহার বা অক্ষরের মোড়ক পরিবর্তন)। translate="no" ব্যবহার করে ব্রাউজার অনুবাদ প্রতিরোধ করুন।
প্রতিক্রিয়া পরিচালনা করা

নিম্নলিখিত কোড স্নিপেটটি দেখায় কিভাবে প্রদর্শনের প্রয়োজনীয়তা পূরণের জন্য টেক্সট এবং ইনলাইন সাইটেশন (রিভিউ স্নিপেট সহ) নিষ্কাশন করে প্রতিক্রিয়াটি পরিচালনা করতে হয়।

পাইথন

for output in interaction.outputs:
    if output.type == "text":
        print(output.text)
        if output.annotations:
            print("\nSources:")
            for annotation in output.annotations:
                if annotation.get("type") == "place_citation":
                    # Display place citation
                    print(f"- {annotation['name']} (Google Maps): {annotation['url']}")
                    # Display review snippets if available
                    if "review_snippets" in annotation:
                        for snippet in annotation["review_snippets"]:
                            print(f"  - Review: {snippet['title']} ({snippet['url']})")
    elif output.type == "google_maps_result":
        # You can also access the raw place data here if needed for map pins
        pass

জাভাস্ক্রিপ্ট

for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
        if (output.annotations) {
            console.log('\nSources:');
            for (const annotation of output.annotations) {
                if (annotation.type === 'place_citation') {
                    console.log(`- ${annotation.name} (Google Maps): ${annotation.url}`);
                    if (annotation.review_snippets) {
                        for (const snippet of annotation.review_snippets) {
                            console.log(`  - Review: ${snippet.title} (${snippet.url})`);
                        }
                    }
                }
            }
        }
    }
}
প্রত্যাশিত আউটপুট স্কিমা

গুগল ম্যাপসের সাথে গ্রাউন্ডিং ব্যবহার করার সময় নিম্নলিখিত আউটপুট স্কিমাটি আশা করুন।

রেজাল্ট ব্লক (টাইপ: "google_maps_result" ) -এ কাঠামোগত স্থানের ডেটা থাকে।

{
  "type": "google_maps_result",
  "call_id": "maps_001",
  "result": {
    "places": [
      {
        "place_id": "ChIJ...",
        "name": "Blue Bottle Coffee", // Google Maps Source
        "url": "https://maps.google.com/?cid=...", // Google Maps Link
        "review_snippets": [
          {
            "title": "Amazing single-origin selections",
            "url": "https://maps.google.com/...",
            "review_id": "def456"
          }
        ]
      }
    ],
    "widget_context_token": "widgetcontent/..."
  },
  "signature": "..."
}

টেক্সট ব্লক (টাইপ: "text" ) -এ ইনলাইন টীকা সহ তৈরি করা বিষয়বস্তু থাকে।

{
  "type": "text",
  "text": "Blue Bottle Coffee (4.5★) on Mint Plaza was rated highly online...",
  "annotations": [
    {
      "type": "place_citation",
      "place_id": "ChIJ...",
      "name": "Blue Bottle Coffee", // Google Maps Source
      "url": "https://maps.google.com/?cid=...", // Google Maps Link
      "review_snippets": [
        {
          "title": "Amazing single-origin selections",
          "url": "https://maps.google.com/...",
          "review_id": "def456"
        }
      ],
      "start_index": 0,
      "end_index": 42
    }
  ]
}
কোড এক্সিকিউশন

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Calculate the 50th Fibonacci number.",
    tools=[{"type": "code_execution"}]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Calculate the 50th Fibonacci number.',
    tools: [{ type: 'code_execution' }]
});
console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Calculate the 50th Fibonacci number.",
    "tools": [{"type": "code_execution"}]
}'
URL প্রসঙ্গ

ইউআরএল কনটেক্সট দিয়ে গ্রাউন্ডিং করলে মডেলটি প্রম্পট বা টুল লিস্টে দেওয়া পাবলিক ইউআরএলগুলো পড়তে পারে।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Summarize the content of https://www.wikipedia.org/",
    tools=[{"type": "url_context"}]
)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Summarize the content of https://www.wikipedia.org/',
    tools: [{ type: 'url_context' }]
});

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Summarize the content of https://www.wikipedia.org/",
    "tools": [{"type": "url_context"}]
}'
প্রতিক্রিয়া পরিচালনা করা

নিম্নলিখিত কোড স্নিপেটটি দেখায় কিভাবে টেক্সট এবং ইনলাইন সাইটেশন ( url_citation টাইপ করুন) বের করে রেসপন্সটি হ্যান্ডেল করতে হয়।

পাইথন

for output in interaction.outputs:
    if output.type == "text":
        print(output.text)
        if output.annotations:
            print("\nSources:")
            for annotation in output.annotations:
                if annotation.get("type") == "url_citation":
                    print(f"- {annotation['title']}: {annotation['url']}")

জাভাস্ক্রিপ্ট

for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
        if (output.annotations) {
            console.log('\nSources:');
            for (const annotation of output.annotations) {
                if (annotation.type === 'url_citation') {
                    console.log(`- ${annotation.title}: ${annotation.url}`);
                }
            }
        }
    }
}
প্রত্যাশিত আউটপুট স্কিমা

URL কনটেক্সট ব্যবহার করার সময় নিম্নলিখিত আউটপুট স্কিমাটি আশা করা যায়।

কল ব্লক (টাইপ: "url_context_call" )-এ সেই URL-টি থাকে যা মডেলটি পড়ার চেষ্টা করেছিল।

{
  "type": "url_context_call",
  "id": "browse_001",
  "arguments": {
    "urls": ["https://www.wikipedia.org/"]
  },
  "signature": "EkYKIGY5OT..."
}

রেজাল্ট ব্লক (টাইপ: "url_context_result" ) -এ ডেটা পুনরুদ্ধারের অবস্থা থাকে।

{
  "type": "url_context_result",
  "call_id": "browse_001",
  "result": {
    "url": "https://www.wikipedia.org/",
    "status": "URL_RETRIEVAL_STATUS_SUCCESS"
  },
  "signature": "EkYKIGY5OT..."
}

টেক্সট ব্লকটিতে তৈরি করা টেক্সট এবং ইনলাইন সাইটেশন থাকে।

{
  "type": "text",
  "text": "Wikipedia is a free online encyclopedia...",
  "annotations": [
    {
      "type": "url_citation",
      "url": "https://www.wikipedia.org/",
      "title": "Wikipedia — Main Page",
      "start_index": 0,
      "end_index": 42
    }
  ]
}
কম্পিউটার ব্যবহার

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-2.5-computer-use-preview-10-2025",
    input="Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.",
    tools=[{
        "type": "computer_use",
        "environment": "browser",
        "excludedPredefinedFunctions": ["drag_and_drop"]
    }]
)

# The response will contain tool calls (actions) for the computer interface
# or text explaining the action
for output in interaction.outputs:
    print(output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-2.5-computer-use-preview-10-2025',
    input: 'Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.',
    tools: [{
        type: 'computer_use',
        environment: 'browser',
        excludedPredefinedFunctions: ['drag_and_drop']
    }]
});

// The response will contain tool calls (actions) for the computer interface
// or text explaining the action
interaction.outputs.forEach(output => console.log(output));

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-computer-use-preview-10-2025",
    "input": "Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.",
    "tools": [{
        "type": "computer_use",
        "environment": "browser",
        "excludedPredefinedFunctions": ["drag_and_drop"]
    }]
}'
কম্পিউটার ব্যবহার ফাংশনের ফলাফল পরিচালনা করা

যেহেতু Computer Use একটি ক্লায়েন্ট-সাইড টুল লুপ, তাই আপনাকে অবশ্যই অ্যাকশনটি (যেমন, একটি ব্রাউজার খোলা) সম্পাদন করতে হবে এবং ফলাফলটি মডেলে ফেরত পাঠাতে হবে। open_web_browser এর মতো অ্যাকশনের জন্য function_result পাঠানোর সময়, নিচে দেখানো অনুযায়ী results লিস্টে URL রেসপন্সটি পাস করতে ভুলবেন না:

{
  "type": "function_result",
  "name": "open_web_browser",
  "call_id": "5q6h0z70",
  "result": [
    {
      "type": "text",
      "text": "{\"url\": \"https://google.com\", \"safety_acknowledgement\":true}"
    },
    {
      "type": "image",
      "data": "iVBORw0KGgoAAAANSUhEUgAA...",
      "mime_type": "image/png"
    }
  ]
}

ফাইল সার্চ সহ গ্রাউন্ডিং করলে মডেলটি ফাইল সার্চ স্টোর থেকে আপনার আপলোড করা ফাইলগুলো অনুসন্ধান করতে পারে।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me about the book 'I, Claudius'",
    tools=[{"type": "file_search", "file_search_store_names": ["fileSearchStores/my-store-name"]}]
)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: "Tell me about the book 'I, Claudius'",
    tools: [{ type: 'file_search', file_search_store_names: ['fileSearchStores/my-store-name'] }]
});

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me about the book 'I, Claudius'",
    "tools": [{"type": "file_search", "file_search_store_names": ["fileSearchStores/my-store-name"]}]
}'
প্রতিক্রিয়া পরিচালনা করা

নিম্নলিখিত কোড স্নিপেটটি দেখায় কিভাবে টেক্সট এবং ইনলাইন সাইটেশন (টাইপ file_citation ) বের করে রেসপন্সটি হ্যান্ডেল করতে হয়।

পাইথন

for output in interaction.outputs:
    if output.type == "text":
        print(output.text)
        if output.annotations:
            print("\nSources:")
            for annotation in output.annotations:
                if annotation.get("type") == "file_citation":
                    print(f"- {annotation['file_name']} ({annotation['document_uri']}):")
                    print(f"  Snippet: {annotation['source']}")

জাভাস্ক্রিপ্ট

for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
        if (output.annotations) {
            console.log('\nSources:');
            for (const annotation of output.annotations) {
                if (annotation.type === 'file_citation') {
                    console.log(`- ${annotation.fileName} (${annotation.documentUri}):`);
                    console.log(`  Snippet: ${annotation.source}`);
                }
            }
        }
    }
}
প্রত্যাশিত আউটপুট স্কিমা

ফাইল সার্চ ব্যবহার করার সময় নিম্নলিখিত আউটপুট স্কিমাটি আশা করা যায়।

কল ব্লক (ধরন: "file_search_call" )-এ কলের মেটাডেটা থাকে।

{
  "type": "file_search_call",
  "id": "filesearch_001",
  "signature": "EkYKIGY5OT..."
}

রেজাল্ট ব্লক (টাইপ: "file_search_result" ) -এ ফলাফলের মেটাডেটা থাকে।

{
  "type": "file_search_result",
  "call_id": "filesearch_001",
  "signature": "EkYKIGY5OT..."
}

টেক্সট ব্লকটিতে তৈরি করা টেক্সট এবং ইনলাইন সাইটেশন থাকে।

{
  "type": "text",
  "text": "The book 'I, Claudius' is a historical novel by Robert Graves...",
  "annotations": [
    {
      "type": "file_citation",
      "document_uri": "fileSearchStores/my-store-name/documents/abc",
      "file_name": "book_summaries.pdf",
      "source": "Claudius is the narrator of this historical novel...",
      "start_index": 0,
      "end_index": 60
    }
  ]
}

অন্তর্নির্মিত সরঞ্জাম এবং ফাংশন কলিং একত্রিত করা

আপনি একই অনুরোধে বিল্ট-ইন টুল এবং ফাংশন কলিং একসাথে ব্যবহার করতে পারেন।

পাইথন

from google import genai
import json

client = genai.Client()

get_weather = {
    "type": "function",
    "name": "getWeather",
    "description": "Gets the weather for a requested city.",
    "parameters": {
        "type": "object",
        "properties": {
            "city": {
                "type": "string",
                "description": "The city and state, e.g. Utqiaġvik, Alaska",
            },
        },
        "required": ["city"],
    },
}

tools = [
    {"type": "google_search"},  # Built-in tool
    get_weather                 # Custom tool (callable)
]

# Turn 1: Initial request with both tools enabled
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is the northernmost city in the United States? What's the weather like there today?",
    tools=tools
)

for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Function call: {output.name} (ID: {output.id})")
        # Execute your custom function locally
        result = {"response": "Very cold. 22 degrees Fahrenheit."}
        # Turn 2: Provide the function result back to the model.
        # Passing `previous_interaction_id` automatically circulates the
        # built-in Google Search context (and thought signatures) from Turn 1
        interaction_2 = client.interactions.create(
            model="gemini-3-flash-preview",
            previous_interaction_id=interaction.id,
            tools=tools,
            input=[{
                "type": "function_result",
                "name": output.name,
                "call_id": output.id,
                "result": json.dumps(result)
            }]
        )

        for output in interaction_2.outputs:
            if output.type == "text":
                print(output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const weatherTool = {
    type: 'function',
    name: 'get_weather',
    description: 'Gets the weather for a given location.',
    parameters: {
        type: 'object',
        properties: {
            location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA' }
        },
        required: ['location']
    }
};

const tools = [
    {type: 'google_search'}, // Built-in tool
    weatherTool              // Custom tool
];

// Turn 1: Initial request with both tools enabled
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: "What is the northernmost city in the United States? What's the weather like there today?",
    tools: tools
});

for (const output of interaction.outputs) {
    if (output.type == "function_call") {
        console.log(`Function call: ${output.name} (ID: ${output.id})`);
        // Execute your custom function locally
        const result = {response: "Very cold. 22 degrees Fahrenheit."};
        // Turn 2: Provide the function result back to the model.
        // Passing `previous_interaction_id` automatically circulates the
        // built-in Google Search context (and thought signatures) from Turn 1
        const interaction_2 = await client.interactions.create({
            model: "gemini-3-flash-preview",
            previous_interaction_id: interaction.id,
            tools: tools,
            input: [{
                type: "function_result",
                name: output.name,
                call_id: output.id,
                result: JSON.stringify(result)
            }]
        });

        for (const output_2 of interaction_2.outputs) {
            if (output_2.type == "text") {
                console.log(output_2.text);
            }
        }
    }
}

বিশ্রাম

# Turn 1: Initial request with both tools enabled
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the northernmost city in the United States? What is the weather like there today?",
    "tools": [
        {"type": "google_search"},
        {
            "type": "function",
            "name": "get_weather",
            "description": "Gets the weather for a given location.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
                },
                "required": ["location"]
            }
        }
    ]
}'

# Assuming Turn 1 returns a function_call for get_weather,
# replace INTERACTION_ID and CALL_ID with values from Turn 1 response.
# Turn 2: Provide the function result back to the model.
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "previous_interaction_id": "INTERACTION_ID",
    "tools": [
        {"type": "google_search"},
        {
            "type": "function",
            "name": "get_weather",
            "description": "Gets the weather for a given location.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
                },
                "required": ["location"]
            }
        }
    ],
    "input": [{
        "type": "function_result",
        "name": "get_weather",
        "call_id": "CALL_ID",
        "result": "{\"response\": \"Very cold. 22 degrees Fahrenheit.\"}"
    }]
}'
টুলের প্রসঙ্গ সঞ্চালন বোঝা

জেমিনি ৩ এবং এর পরবর্তী মডেলগুলো সার্ভার-সাইড অ্যাকশনের একটি নির্ভরযোগ্য 'স্মৃতি' বজায় রাখার জন্য টুল কনটেক্সট সার্কুলেশন সমর্থন করে। যখন কোনো বিল্ট-ইন টুল (যেমন গুগল সার্চ) ট্রিগার করা হয়, তখন এপিআই নির্দিষ্ট toolCall এবং toolResponse পার্ট তৈরি করে। এই পার্টগুলোতে সেই সুনির্দিষ্ট কনটেক্সট থাকে যা পরবর্তী ধাপে সেই ফলাফলগুলো সম্পর্কে সিদ্ধান্ত নিতে মডেলের প্রয়োজন হয়।

  • স্টেটফুল (প্রস্তাবিত) : আপনি যদি previous_interaction_id ব্যবহার করেন, তাহলে এপিআই আপনার জন্য এই সঞ্চালনটি স্বয়ংক্রিয়ভাবে পরিচালনা করে।
  • স্টেটলেস : আপনি যদি ম্যানুয়ালি হিস্ট্রি পরিচালনা করেন, তাহলে এপিআই থেকে প্রাপ্ত ব্লকগুলোকে হুবহু আপনার ইনপুট অ্যারেতে অন্তর্ভুক্ত করতে হবে।

রিমোট মডেল প্রসঙ্গ প্রোটোকল (MCP)

রিমোট এমসিপি ইন্টিগ্রেশন জেমিনি এপিআই-কে রিমোট সার্ভারে হোস্ট করা এক্সটার্নাল টুলগুলোকে সরাসরি কল করার সুযোগ দিয়ে এজেন্ট ডেভেলপমেন্টকে সহজ করে তোলে।

পাইথন

import datetime
from google import genai

client = genai.Client()

mcp_server = {
    "type": "mcp_server",
    "name": "weather_service",
    "url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
}

today = datetime.date.today().strftime("%d %B %Y")

interaction = client.interactions.create(
    model="gemini-2.5-flash",
    input="What is the weather like in New York today?",
    tools=[mcp_server],
    system_instruction=f"Today is {today}."
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const mcpServer = {
    type: 'mcp_server',
    name: 'weather_service',
    url: 'https://gemini-api-demos.uc.r.appspot.com/mcp'
};

const today = new Date().toDateString();

const interaction = await client.interactions.create({
    model: 'gemini-2.5-flash',
    input: 'What is the weather like in New York today?',
    tools: [mcpServer],
    system_instruction: `Today is ${today}.`
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-flash",
    "input": "What is the weather like in New York today?",
    "tools": [{
        "type": "mcp_server",
        "name": "weather_service",
        "url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
    }],
    "system_instruction": "Today is '"$(date +"%du%Bt%Y")"' YYYY-MM-DD>."
}'

গুরুত্বপূর্ণ নোট:

  • রিমোট এমসিপি শুধুমাত্র স্ট্রিমেবল এইচটিটিপি সার্ভারের সাথেই কাজ করে (এসএসই সার্ভার সমর্থিত নয়)।
  • রিমোট এমসিপি জেমিনি ৩ মডেলের সাথে কাজ করে না (এটি শীঘ্রই আসছে)।
  • MCP সার্ভারের নামে "-" অক্ষরটি থাকা উচিত নয় (এর পরিবর্তে snake_case সার্ভারের নাম ব্যবহার করুন)।

কাঠামোগত আউটপুট (JSON স্কিমা)

response_format প্যারামিটারে একটি JSON স্কিমা প্রদান করে একটি নির্দিষ্ট JSON আউটপুট নিশ্চিত করুন। এটি মডারেশন, ক্লাসিফিকেশন বা ডেটা এক্সট্র্যাকশনের মতো কাজের জন্য উপযোগী।

পাইথন

from google import genai
from pydantic import BaseModel, Field
from typing import Literal, Union
client = genai.Client()

class SpamDetails(BaseModel):
    reason: str = Field(description="The reason why the content is considered spam.")
    spam_type: Literal["phishing", "scam", "unsolicited promotion", "other"]

class NotSpamDetails(BaseModel):
    summary: str = Field(description="A brief summary of the content.")
    is_safe: bool = Field(description="Whether the content is safe for all audiences.")

class ModerationResult(BaseModel):
    decision: Union[SpamDetails, NotSpamDetails]

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format=ModerationResult.model_json_schema(),
)

parsed_output = ModerationResult.model_validate_json(interaction.outputs[-1].text)
print(parsed_output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import { z } from 'zod';
const client = new GoogleGenAI({});

const moderationSchema = z.object({
    decision: z.union([
        z.object({
            reason: z.string().describe('The reason why the content is considered spam.'),
            spam_type: z.enum(['phishing', 'scam', 'unsolicited promotion', 'other']).describe('The type of spam.'),
        }).describe('Details for content classified as spam.'),
        z.object({
            summary: z.string().describe('A brief summary of the content.'),
            is_safe: z.boolean().describe('Whether the content is safe for all audiences.'),
        }).describe('Details for content classified as not spam.'),
    ]),
});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: "Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format: z.toJSONSchema(moderationSchema),
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    "response_format": {
        "type": "object",
        "properties": {
            "decision": {
                "type": "object",
                "properties": {
                    "reason": {"type": "string", "description": "The reason why the content is considered spam."},
                    "spam_type": {"type": "string", "description": "The type of spam."}
                },
                "required": ["reason", "spam_type"]
            }
        },
        "required": ["decision"]
    }
}'

সরঞ্জাম এবং কাঠামোগত আউটপুট একত্রিত করা

টুল দ্বারা সংগৃহীত তথ্যের উপর ভিত্তি করে একটি নির্ভরযোগ্য JSON অবজেক্ট পেতে, বিল্ট-ইন টুলগুলোকে স্ট্রাকচার্ড আউটপুটের সাথে একত্রিত করুন।

পাইথন

from google import genai
from pydantic import BaseModel, Field
from typing import Literal, Union

client = genai.Client()

class SpamDetails(BaseModel):
    reason: str = Field(description="The reason why the content is considered spam.")
    spam_type: Literal["phishing", "scam", "unsolicited promotion", "other"]

class NotSpamDetails(BaseModel):
    summary: str = Field(description="A brief summary of the content.")
    is_safe: bool = Field(description="Whether the content is safe for all audiences.")

class ModerationResult(BaseModel):
    decision: Union[SpamDetails, NotSpamDetails]

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format=ModerationResult.model_json_schema(),
    tools=[{"type": "url_context"}]
)

parsed_output = ModerationResult.model_validate_json(interaction.outputs[-1].text)
print(parsed_output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import { z } from 'zod'; // Assuming zod is used for schema generation, or define manually
const client = new GoogleGenAI({});

const obj = z.object({
    winning_team: z.string(),
    score: z.string(),
});
const schema = z.toJSONSchema(obj);

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Who won the last euro?',
    tools: [{ type: 'google_search' }],
    response_format: schema,
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Who won the last euro?",
    "tools": [{"type": "google_search"}],
    "response_format": {
        "type": "object",
        "properties": {
            "winning_team": {"type": "string"},
            "score": {"type": "string"}
        }
    }
}'

উন্নত বৈশিষ্ট্য

এছাড়াও কিছু অতিরিক্ত উন্নত বৈশিষ্ট্য রয়েছে যা আপনাকে ইন্টারঅ্যাকশন এপিআই (Interactions API) নিয়ে কাজ করার ক্ষেত্রে আরও বেশি নমনীয়তা প্রদান করে।

স্ট্রিমিং

প্রতিক্রিয়াগুলো তৈরি হওয়ার সাথে সাথে পর্যায়ক্রমে গ্রহণ করুন।

যখন stream=true , তখন চূড়ান্ত interaction.complete ইভেন্টের outputs ফিল্ডে তৈরি হওয়া কন্টেন্ট থাকে না। এতে শুধুমাত্র ব্যবহারের মেটাডেটা এবং চূড়ান্ত স্ট্যাটাস থাকে। সম্পূর্ণ রেসপন্স বা টুল কল আর্গুমেন্টগুলো পুনর্গঠন করতে আপনাকে ক্লায়েন্ট-সাইডে content.delta ইভেন্টগুলো অ্যাগ্রিগেট করতে হবে।

পাইথন

from google import genai

client = genai.Client()

stream = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Explain quantum entanglement in simple terms.",
    stream=True
)

for chunk in stream:
    if chunk.event_type == "content.delta":
        if chunk.delta.type == "text":
            print(chunk.delta.text, end="", flush=True)
        elif chunk.delta.type == "thought":
            print(chunk.delta.thought, end="", flush=True)
    elif chunk.event_type == "interaction.complete":
        print(f"\n\n--- Stream Finished ---")
        print(f"Total Tokens: {chunk.interaction.usage.total_tokens}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const stream = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Explain quantum entanglement in simple terms.',
    stream: true,
});

for await (const chunk of stream) {
    if (chunk.event_type === 'content.delta') {
        if (chunk.delta.type === 'text' && 'text' in chunk.delta) {
            process.stdout.write(chunk.delta.text);
        } else if (chunk.delta.type === 'thought' && 'thought' in chunk.delta) {
            process.stdout.write(chunk.delta.thought);
        }
    } else if (chunk.event_type === 'interaction.complete') {
        console.log('\n\n--- Stream Finished ---');
        console.log(`Total Tokens: ${chunk.interaction.usage.total_tokens}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Explain quantum entanglement in simple terms.",
    "stream": true
}'

স্ট্রিমিং ইভেন্টের প্রকারভেদ

যখন স্ট্রিমিং সক্রিয় থাকে, তখন এপিআই সার্ভার-প্রেরিত ইভেন্ট (SSE) ফেরত দেয়। প্রতিটি ইভেন্টের একটি event_type ফিল্ড থাকে যা এর উদ্দেশ্য নির্দেশ করে। ইভেন্টের প্রকারগুলোর সম্পূর্ণ তালিকা এপিআই রেফারেন্সে পাওয়া যাবে।

ইভেন্টের ধরণ বর্ণনা
interaction.start প্রথম ইভেন্ট। এতে ইন্টারঅ্যাকশন id এবং প্রাথমিক status ( in_progress ) থাকে।
interaction.status_update অবস্থার পরিবর্তন নির্দেশ করে (যেমন, in_progress )।
content.start একটি নতুন আউটপুট ব্লকের সূচনা নির্দেশ করে। এতে index এবং বিষয়বস্তুর type (যেমন, text , thought ) থাকে।
content.delta পর্যায়ক্রমিক বিষয়বস্তু হালনাগাদ। এতে delta.type ) দ্বারা চিহ্নিত আংশিক ডেটা থাকে।
content.stop index . এ একটি আউটপুট ব্লকের সমাপ্তি নির্দেশ করে।
interaction.complete চূড়ান্ত ইভেন্ট। এতে id , status , usage এবং মেটাডেটা রয়েছে। দ্রষ্টব্য: outputs এর মান None —আপনাকে content.* ইভেন্টগুলো থেকে আউটপুটগুলো পুনর্গঠন করতে হবে।
error একটি ত্রুটি ঘটেছে তা নির্দেশ করে। এতে error.code এবং error.message রয়েছে।

স্ট্রিমিং ইভেন্ট থেকে ইন্টারঅ্যাকশন অবজেক্ট পুনর্গঠন

নন-স্ট্রিমিং রেসপন্সের বিপরীতে, স্ট্রিমিং রেসপন্সে কোনো outputs অ্যারে থাকে না । আপনাকে অবশ্যই content.delta ইভেন্টগুলো থেকে কন্টেন্ট সংগ্রহ করে আউটপুটগুলো পুনর্গঠন করতে হবে।

পাইথন

from google import genai

client = genai.Client()

stream = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Write a haiku about Python programming.",
    stream=True
)

# Accumulate outputs by index
outputs = {}
usage = None

for chunk in stream:
    if chunk.event_type == "content.start":
        outputs[chunk.index] = {"type": chunk.content.type}

    elif chunk.event_type == "content.delta":
        output = outputs[chunk.index]
        if chunk.delta.type == "text":
            output["text"] = output.get("text", "") + chunk.delta.text
        elif chunk.delta.type == "thought_signature":
            output["signature"] = chunk.delta.signature
        elif chunk.delta.type == "thought_summary":
            output["summary"] = output.get("summary", "") + getattr(chunk.delta.content, "text", "")

    elif chunk.event_type == "interaction.complete":
        usage = chunk.interaction.usage

# Final outputs list (sorted by index)
final_outputs = [outputs[i] for i in sorted(outputs.keys())]
print(f"\n\nOutputs: {final_outputs}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const stream = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Write a haiku about Python programming.',
    stream: true,
});

// Accumulate outputs by index
const outputs = new Map();
let usage = null;

for await (const chunk of stream) {
    if (chunk.event_type === 'content.start') {
        outputs.set(chunk.index, { type: chunk.content.type });

    } else if (chunk.event_type === 'content.delta') {
        const output = outputs.get(chunk.index);
        if (chunk.delta.type === 'text') {
            output.text = (output.text || '') + chunk.delta.text;
            process.stdout.write(chunk.delta.text);
        } else if (chunk.delta.type === 'thought_signature') {
            output.signature = chunk.delta.signature;
        } else if (chunk.delta.type === 'thought_summary') {
            output.summary = (output.summary || '') + (chunk.delta.content?.text || '');
        }

    } else if (chunk.event_type === 'interaction.complete') {
        usage = chunk.interaction.usage;
    }
}

// Final outputs list (sorted by index)
const finalOutputs = [...outputs.entries()]
    .sort((a, b) => a[0] - b[0])
    .map(([_, output]) => output);
console.log(`\n\nOutputs:`, finalOutputs);

স্ট্রিমিং টুল কল

স্ট্রিমিং-এর সাথে টুল ব্যবহার করার সময়, মডেলটি স্ট্রিমে content.delta ইভেন্টের একটি ক্রম হিসাবে ফাংশন কল তৈরি করে। টেক্সটের মতো নয়, টুলের আর্গুমেন্টগুলো একটি একক content.delta ইভেন্টের মধ্যে সম্পূর্ণ JSON অবজেক্ট হিসাবে সরবরাহ করা হয়। স্ট্রিমিং চলাকালীন interaction.complete ইভেন্টে outputs অ্যারেটি খালি থাকে, তাই আপনাকে নিচে দেখানো পদ্ধতি অনুযায়ী `delta` থেকে টুল কলগুলো ক্যাপচার করতে হবে।

পাইথন

from google import genai
import json

client = genai.Client()

weather_tool = {
    "type": "function",
    "name": "get_weather",
    "description": "Gets the weather for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "The city and state"}
        },
        "required": ["location"]
    }
}

stream = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is the weather in Paris?",
    tools=[weather_tool],
    stream=True
)

# A map to capture tool calls by their ID as they arrive
function_calls = {}

for chunk in stream:
    if chunk.event_type == "content.delta":
        if chunk.delta.type == "text" and chunk.delta.text:
            print(chunk.delta.text, end="", flush=True)

        elif chunk.delta.type == "function_call":
            print(f"\nExecuting {chunk.delta.name} immediately...")
            # result = my_tools[chunk.delta.name](**chunk.delta.arguments)
            function_calls[chunk.delta.id] = chunk.delta

    elif chunk.event_type == "interaction.complete":
        print("\n\nAll tools executed. Stream finished.")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const weatherTool = {
    type: 'function',
    name: 'get_weather',
    description: 'Gets the weather for a given location.',
    parameters: {
        type: 'object',
        properties: {
            location: { type: 'string', description: 'The city and state' }
        },
        required: ['location']
    }
};

const stream = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What is the weather in Paris?',
    tools: [weatherTool],
    stream: true,
});

const toolCalls = new Map();

for await (const chunk of stream) {
    if (chunk.event_type === 'content.delta') {
        if (chunk.delta.type === 'text' && chunk.delta.text) {
            process.stdout.write(chunk.delta.text);

        } else if (chunk.delta.type === 'function_call') {
            console.log(`\nExecuting ${chunk.delta.name} immediately...`);
            // const result = myTools[chunk.delta.name](chunk.delta.arguments);
            toolCalls.set(chunk.delta.id, chunk.delta);
        }
    } else if (chunk.event_type === 'interaction.complete') {
        console.log('\n\nAll tools executed. Stream finished.');
    }
}

বিশ্রাম

# When streaming via SSE, capture function_call data from content.delta events.
# The 'arguments' field arrives as a complete JSON object once generated.

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the weather in Paris?",
    "tools": [{
        "type": "function",
        "name": "get_weather",
        "description": "Gets the weather for a given location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "The city and state"}
            },
            "required": ["location"]
        }
    }],
    "stream": true
}'

কনফিগারেশন

generation_config ব্যবহার করে মডেলের আচরণ কাস্টমাইজ করুন।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me a story about a brave knight.",
    generation_config={
        "temperature": 0.7,
        "max_output_tokens": 500,
        "thinking_level": "low",
    }
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a story about a brave knight.',
    generation_config: {
        temperature: 0.7,
        max_output_tokens: 500,
        thinking_level: 'low',
    }
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a story about a brave knight.",
    "generation_config": {
        "temperature": 0.7,
        "max_output_tokens": 500,
        "thinking_level": "low"
    }
}'

চিন্তা

জেমিনি ২.৫ এবং এর পরবর্তী মডেলগুলো কোনো প্রতিক্রিয়া তৈরি করার আগে 'চিন্তা' নামক একটি অভ্যন্তরীণ যুক্তি প্রক্রিয়া ব্যবহার করে। এটি মডেলটিকে গণিত, কোডিং এবং বহু-ধাপের যুক্তির মতো জটিল কাজগুলোর জন্য আরও ভালো উত্তর তৈরি করতে সাহায্য করে।

চিন্তার স্তর

thinking_level প্যারামিটারটি আপনাকে মডেলের যুক্তির গভীরতা নিয়ন্ত্রণ করতে দেয়:

স্তর বর্ণনা সমর্থিত মডেল
minimal বেশিরভাগ কোয়েরির জন্য 'চিন্তাহীন' সেটিংয়ের সাথে মেলে। কিছু ক্ষেত্রে, মডেলগুলো খুব সামান্যই চিন্তা করতে পারে। লেটেন্সি এবং খরচ কমায়। শুধুমাত্র ফ্ল্যাশ মডেল
(যেমন জেমিনি ৩ ফ্ল্যাশ)
low সহজ নির্দেশনা অনুসরণ এবং চ্যাটের জন্য ল্যাটেন্সি ও খরচ সাশ্রয়কে অগ্রাধিকার দেয় এমন একটি সংক্ষিপ্ত কার্যপ্রণালী। সমস্ত চিন্তার মডেল
medium অধিকাংশ কাজের জন্য ভারসাম্যপূর্ণ চিন্তাভাবনা। শুধুমাত্র ফ্ল্যাশ মডেল
(যেমন জেমিনি ৩ ফ্ল্যাশ)
high (ডিফল্ট) যুক্তির গভীরতা সর্বাধিক করে। মডেলটির প্রথম টোকেনে পৌঁছাতে উল্লেখযোগ্যভাবে বেশি সময় লাগতে পারে, কিন্তু এর আউটপুট আরও যত্নসহকারে যুক্তিযুক্ত হবে। সমস্ত চিন্তার মডেল

চিন্তার সারসংক্ষেপ

মডেলের চিন্তাভাবনা প্রতিক্রিয়া আউটপুটে চিন্তার ব্লক ( type: "thought" ) হিসাবে উপস্থাপিত হয়। আপনি thinking_summaries প্যারামিটারটি ব্যবহার করে চিন্তন প্রক্রিয়ার পাঠযোগ্য সারাংশ গ্রহণ করবেন কিনা তা নিয়ন্ত্রণ করতে পারেন:

মূল্য বর্ণনা
auto (ডিফল্ট) উপলব্ধ থাকলে চিন্তার সারাংশ ফেরত দেয়।
none চিন্তার সারাংশ নিষ্ক্রিয় করে।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Solve this step by step: What is 15% of 240?",
    generation_config={
        "thinking_level": "high",
        "thinking_summaries": "auto"
    }
)

for output in interaction.outputs:
    if output.type == "thought":
        print(f"Thinking: {output.summary}")
    elif output.type == "text":
        print(f"Answer: {output.text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Solve this step by step: What is 15% of 240?',
    generation_config: {
        thinking_level: 'high',
        thinking_summaries: 'auto'
    }
});

for (const output of interaction.outputs) {
    if (output.type === 'thought') {
        console.log(`Thinking: ${output.summary}`);
    } else if (output.type === 'text') {
        console.log(`Answer: ${output.text}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Solve this step by step: What is 15% of 240?",
    "generation_config": {
        "thinking_level": "high",
        "thinking_summaries": "auto"
    }
}'

প্রতিটি থট ব্লকে একটি signature ফিল্ড (অভ্যন্তরীণ যুক্তির অবস্থার একটি ক্রিপ্টোগ্রাফিক হ্যাশ) এবং একটি ঐচ্ছিক summary ফিল্ড (মডেলের যুক্তির একটি পাঠযোগ্য সারাংশ) থাকে। signature সর্বদা উপস্থিত থাকে, কিন্তু নিম্নলিখিত ক্ষেত্রে একটি থট ব্লকে কোনো সারাংশ ছাড়াই শুধুমাত্র সিগনেচার থাকতে পারে:

  • সাধারণ অনুরোধ : মডেলটি একটি সারাংশ তৈরি করার জন্য যথেষ্ট কারণ দেখায়নি।
  • thinking_summaries: "none" : সারাংশ স্পষ্টভাবে নিষ্ক্রিয় করা হয়েছে

আপনার কোডে সর্বদা সেইসব থট ব্লক পরিচালনা করা উচিত যেখানে summary খালি বা অনুপস্থিত থাকে। ম্যানুয়ালি কথোপকথনের ইতিহাস পরিচালনা করার সময় (স্টেটলেস মোড), সত্যতা যাচাই করার জন্য আপনাকে পরবর্তী অনুরোধগুলিতে থট ব্লকগুলিকে তাদের স্বাক্ষর সহ অন্তর্ভুক্ত করতে হবে।

ফাইল নিয়ে কাজ করা

রিমোট ফাইল নিয়ে কাজ করা

এপিআই কলের মাধ্যমে সরাসরি রিমোট ইউআরএল ব্যবহার করে ফাইল অ্যাক্সেস করুন।

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {
            "type": "image",
            "uri": "https://github.com/<github-path>/cats-and-dogs.jpg",
        },
        {"type": "text", "text": "Describe what you see."}
    ],
)
for output in interaction.outputs:
    if output.type == "text":
        print(output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        {
            type: 'image',
            uri: 'https://github.com/<github-path>/cats-and-dogs.jpg',
        },
        { type: 'text', text: 'Describe what you see.' }
    ],
});
for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {
            "type": "image",
            "uri": "https://github.com/<github-path>/cats-and-dogs.jpg"
        },
        {"type": "text", "text": "Describe what you see."}
    ]
}'

জেমিনি ফাইলস এপিআই নিয়ে কাজ করা

ব্যবহার করার আগে ফাইলগুলো জেমিনি ফাইলস এপিআই- তে আপলোড করুন।

পাইথন

from google import genai
import time
import requests
client = genai.Client()

# 1. Download the file
url = "https://github.com/philschmid/gemini-samples/raw/refs/heads/main/assets/cats-and-dogs.jpg"
response = requests.get(url)
with open("cats-and-dogs.jpg", "wb") as f:
    f.write(response.content)

# 2. Upload to Gemini Files API
file = client.files.upload(file="cats-and-dogs.jpg")

# 3. Wait for processing
while client.files.get(name=file.name).state != "ACTIVE":
    time.sleep(2)

# 4. Use in Interaction
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {
            "type": "image",
            "uri": file.uri,
        },
        {"type": "text", "text": "Describe what you see."}
    ],
)
for output in interaction.outputs:
    if output.type == "text":
        print(output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
import fetch from 'node-fetch';
const client = new GoogleGenAI({});

// 1. Download the file
const url = 'https://github.com/philschmid/gemini-samples/raw/refs/heads/main/assets/cats-and-dogs.jpg';
const filename = 'cats-and-dogs.jpg';
const response = await fetch(url);
const buffer = await response.buffer();
fs.writeFileSync(filename, buffer);

// 2. Upload to Gemini Files API
const myfile = await client.files.upload({ file: filename, config: { mimeType: 'image/jpeg' } });

// 3. Wait for processing
while ((await client.files.get({ name: myfile.name })).state !== 'ACTIVE') {
    await new Promise(resolve => setTimeout(resolve, 2000));
}

// 4. Use in Interaction
const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'image', uri: myfile.uri, },
        { type: 'text', text: 'Describe what you see.' }
    ],
});
for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
    }
}

বিশ্রাম

# 1. Upload the file (Requires File API setup)
# See https://ai.google.dev/gemini-api/docs/files for details.
# Assume FILE_URI is obtained from the upload step.

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "image", "uri": "FILE_URI"},
        {"type": "text", "text": "Describe what you see."}
    ]
}'

ডেটা মডেল

আপনি এপিআই রেফারেন্স- এ ডেটা মডেল সম্পর্কে আরও জানতে পারবেন। নিচে এর প্রধান উপাদানগুলোর একটি সংক্ষিপ্ত বিবরণ দেওয়া হলো।

মিথস্ক্রিয়া

সম্পত্তি প্রকার বর্ণনা
id string মিথস্ক্রিয়ার জন্য অনন্য শনাক্তকারী।
model / agent string ব্যবহৃত মডেল বা এজেন্ট। শুধুমাত্র একটিই প্রদান করা যাবে।
input Content[] প্রদত্ত ইনপুটগুলো।
outputs Content[] মডেলের প্রতিক্রিয়াগুলো।
tools Tool[] ব্যবহৃত সরঞ্জামগুলো।
previous_interaction_id string প্রাসঙ্গিকতার জন্য পূর্ববর্তী কথোপকথনের আইডি।
stream boolean কথোপকথনটি স্ট্রিমিং হচ্ছে কি না।
status string অবস্থা: completed , in_progress , requires_action , failed , ইত্যাদি।
background boolean ইন্টারঅ্যাকশনটি ব্যাকগ্রাউন্ড মোডে আছে কিনা।
store boolean ইন্টারঅ্যাকশনটি সংরক্ষণ করা হবে কিনা। ডিফল্ট: true । এটি থেকে বিরত থাকতে false সেট করুন।
usage ব্যবহার ইন্টারঅ্যাকশন অনুরোধের টোকেন ব্যবহার।

সমর্থিত মডেল এবং এজেন্ট

মডেলের নাম প্রকার মডেল আইডি
জেমিনি ৩.১ ফ্ল্যাশ-লাইট প্রিভিউ মডেল gemini-3.1-flash-lite-preview
জেমিনি ৩.১ প্রো প্রিভিউ মডেল gemini-3.1-pro-preview
জেমিনি ৩ ফ্ল্যাশ প্রিভিউ মডেল gemini-3-flash-preview
জেমিনি ২.৫ প্রো মডেল gemini-2.5-pro
জেমিনি ২.৫ ফ্ল্যাশ মডেল gemini-2.5-flash
জেমিনি ২.৫ ফ্ল্যাশ-লাইট মডেল gemini-2.5-flash-lite
লিরিয়া ৩ ক্লিপ প্রিভিউ মডেল lyria-3-clip-preview
লাইরিয়া ৩ প্রো প্রিভিউ মডেল lyria-3-pro-preview
গভীর গবেষণা পূর্বরূপ এজেন্ট deep-research-pro-preview-12-2025

ইন্টারঅ্যাকশন এপিআই কীভাবে কাজ করে

ইন্টারঅ্যাকশনস এপিআই-টি একটি কেন্দ্রীয় রিসোর্স, অর্থাৎ Interaction কেন্দ্র করে ডিজাইন করা হয়েছে। একটি Interaction কোনো কথোপকথন বা কাজের একটি সম্পূর্ণ পর্যায়কে উপস্থাপন করে। এটি একটি সেশন রেকর্ড হিসেবে কাজ করে, যেখানে একটি ইন্টারঅ্যাকশনের সম্পূর্ণ ইতিহাস থাকে, যার মধ্যে অন্তর্ভুক্ত থাকে ব্যবহারকারীর সমস্ত ইনপুট, মডেলের ভাবনা, টুলের কল, টুলের ফলাফল এবং মডেলের চূড়ান্ত আউটপুট।

যখন আপনি interactions.create কল করেন, তখন আপনি একটি নতুন Interaction রিসোর্স তৈরি করেন।

সার্ভার-সাইড স্টেট ম্যানেজমেন্ট

পরবর্তী কলে কথোপকথন চালিয়ে যাওয়ার জন্য, আপনি previous_interaction_id প্যারামিটার ব্যবহার করে একটি সম্পন্ন হওয়া ইন্টারঅ্যাকশনের id ব্যবহার করতে পারেন। সার্ভার এই আইডিটি ব্যবহার করে কথোপকথনের ইতিহাস পুনরুদ্ধার করে, ফলে আপনাকে সম্পূর্ণ চ্যাট ইতিহাস পুনরায় পাঠাতে হয় না।

previous_interaction_id ব্যবহার করে শুধুমাত্র কথোপকথনের ইতিহাস (ইনপুট এবং আউটপুট) সংরক্ষিত হয়। অন্যান্য প্যারামিটারগুলো ইন্টারঅ্যাকশন-ভিত্তিক এবং কেবল সেই নির্দিষ্ট ইন্টারঅ্যাকশনের ক্ষেত্রেই প্রযোজ্য যা আপনি বর্তমানে তৈরি করছেন:

  • tools
  • system_instruction
  • generation_config ( thinking_level , temperature ইত্যাদি সহ)

এর মানে হলো, এই প্যারামিটারগুলো প্রয়োগ করতে চাইলে প্রতিটি নতুন ইন্টারঅ্যাকশনে আপনাকে অবশ্যই সেগুলো পুনরায় উল্লেখ করতে হবে। এই সার্ভার-সাইড স্টেট ম্যানেজমেন্ট ঐচ্ছিক; আপনি প্রতিটি অনুরোধে সম্পূর্ণ কথোপকথনের ইতিহাস পাঠিয়ে স্টেটলেস মোডেও কাজ করতে পারেন।

ডেটা সংরক্ষণ এবং ধরে রাখা

ডিফল্টরূপে, সার্ভার-সাইড স্টেট ম্যানেজমেন্ট ফিচার ( previous_interaction_id ব্যবহার করে), ব্যাকগ্রাউন্ড এক্সিকিউশন ( background=true ব্যবহার করে) এবং পর্যবেক্ষণযোগ্যতার উদ্দেশ্যগুলোর ব্যবহার সহজ করার জন্য সমস্ত Interaction অবজেক্ট সংরক্ষণ করা হয় ( store=true )।

  • পেইড টিয়ার : ইন্টারঅ্যাকশনগুলো ৫৫ দিনের জন্য সংরক্ষিত থাকে।
  • ফ্রি টিয়ার : ইন্টারঅ্যাকশনগুলো ১ দিনের জন্য সংরক্ষিত থাকে।

আপনি যদি এটি না চান, তাহলে আপনার অনুরোধে store=false সেট করতে পারেন। এই নিয়ন্ত্রণটি স্টেট ম্যানেজমেন্ট থেকে আলাদা; আপনি যেকোনো ইন্টারঅ্যাকশনের জন্য স্টোরেজ বাদ দিতে পারেন। তবে, মনে রাখবেন যে store=false background=true এর সাথে সামঞ্জস্যপূর্ণ নয় এবং পরবর্তী টার্নগুলোর জন্য previous_interaction_id ব্যবহার করতে বাধা দেয়।

আপনি এপিআই রেফারেন্সে থাকা ডিলিট মেথডটি ব্যবহার করে যেকোনো সময় সংরক্ষিত ইন্টারঅ্যাকশনগুলো মুছে ফেলতে পারেন। আপনি শুধুমাত্র ইন্টারঅ্যাকশন আইডি জানা থাকলেই তা মুছতে পারবেন।

সংরক্ষণের সময়সীমা শেষ হওয়ার পর আপনার ডেটা স্বয়ংক্রিয়ভাবে মুছে যাবে।

ইন্টারঅ্যাকশন অবজেক্টগুলো শর্তাবলী অনুযায়ী প্রক্রিয়াজাত করা হয়।

সর্বোত্তম অনুশীলন

  • ক্যাশ হিট রেট : কথোপকথন চালিয়ে যাওয়ার জন্য previous_interaction_id ব্যবহার করলে সিস্টেমটি কথোপকথনের ইতিহাসের জন্য অন্তর্নিহিত ক্যাশিং আরও সহজে ব্যবহার করতে পারে, যা কর্মক্ষমতা উন্নত করে এবং খরচ কমায়।
  • ইন্টারঅ্যাকশনের মিশ্রণ : একটি কথোপকথনের মধ্যে এজেন্ট এবং মডেলের ইন্টারঅ্যাকশনগুলোকে আপনার পছন্দমতো মিলিয়ে ব্যবহার করার স্বাধীনতা আপনার রয়েছে। উদাহরণস্বরূপ, আপনি প্রাথমিক ডেটা সংগ্রহের জন্য ডিপ রিসার্চ এজেন্টের মতো একটি বিশেষায়িত এজেন্ট ব্যবহার করতে পারেন এবং তারপরে সারসংক্ষেপ করা বা পুনঃবিন্যাস করার মতো ফলো-আপ কাজগুলোর জন্য একটি স্ট্যান্ডার্ড জেমিনি মডেল ব্যবহার করতে পারেন, এই ধাপগুলোকে previous_interaction_id সাথে লিঙ্ক করে।

এসডিকে

ইন্টারঅ্যাকশনস এপিআই অ্যাক্সেস করার জন্য আপনি গুগল জেনএআই এসডিকে-এর সর্বশেষ সংস্করণ ব্যবহার করতে পারেন।

  • পাইথনে, 1.55.0 সংস্করণ থেকে এটি হলো google-genai প্যাকেজ।
  • জাভাস্ক্রিপ্টে, 1.33.0 সংস্করণ থেকে এটি হলো @google/genai প্যাকেজ।

লাইব্রেরি পেজে আপনি এসডিকেগুলো কীভাবে ইনস্টল করবেন সে সম্পর্কে আরও জানতে পারবেন।

সীমাবদ্ধতা

  • বিটা স্ট্যাটাস : ইন্টারঅ্যাকশনস এপিআইটি বিটা/প্রিভিউ পর্যায়ে রয়েছে। এর ফিচার ও স্কিমা পরিবর্তিত হতে পারে।
  • রিমোট এমসিপি : জেমিনি ৩ রিমোট এমসিপি সমর্থন করে না, এটি শীঘ্রই আসছে।

ব্রেকিং পরিবর্তন

ইন্টারঅ্যাকশনস এপিআই বর্তমানে একটি প্রাথমিক বিটা পর্যায়ে রয়েছে। আমরা বাস্তব ব্যবহার এবং ডেভেলপারদের মতামতের উপর ভিত্তি করে এপিআই-এর সক্ষমতা, রিসোর্স স্কিমা এবং এসডিকে ইন্টারফেস সক্রিয়ভাবে উন্নত ও পরিমার্জন করছি।

এর ফলে বড় ধরনের পরিবর্তন আসতে পারে । আপডেটে নিম্নলিখিত বিষয়গুলোতে পরিবর্তন অন্তর্ভুক্ত থাকতে পারে:

  • ইনপুট এবং আউটপুটের জন্য স্কিমা।
  • এসডিকে মেথড সিগনেচার এবং অবজেক্ট স্ট্রাকচার।
  • নির্দিষ্ট বৈশিষ্ট্যের আচরণ।

প্রোডাকশন ওয়ার্কলোডের জন্য, আপনার স্ট্যান্ডার্ড generateContent API ব্যবহার করা চালিয়ে যাওয়া উচিত। স্থিতিশীল ডেপ্লয়মেন্টের জন্য এটিই প্রস্তাবিত পথ এবং এর সক্রিয়ভাবে উন্নয়ন ও রক্ষণাবেক্ষণ অব্যাহত থাকবে।

প্রতিক্রিয়া

ইন্টারঅ্যাকশনস এপিআই-এর উন্নয়নের জন্য আপনার মতামত অত্যন্ত গুরুত্বপূর্ণ। আমাদের গুগল এআই ডেভেলপার কমিউনিটি ফোরামে আপনার ভাবনা শেয়ার করুন, বাগ রিপোর্ট করুন, অথবা নতুন ফিচারের জন্য অনুরোধ জানান।

এরপর কী?