টেক্সট তৈরি

জেমিনি এপিআই টেক্সট, ছবি, ভিডিও এবং অডিও ইনপুট থেকে টেক্সট আউটপুট তৈরি করতে পারে।

এখানে একটি সাধারণ উদাহরণ দেওয়া হলো:

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input="How does AI work?"
)
print(interaction.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "How does AI work?",
  });
  console.log(interaction.output_text);
}

await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "How does AI work?"
  }'

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

সবচেয়ে সাধারণ হেল্পার হলো interaction.output_text (String), যা মডেলের রেসপন্সের শেষ টেক্সট ব্লকগুলো রিটার্ন করে। যদি রেসপন্সটি একাধিক পরপর TextContent ব্লকে বিভক্ত থাকে, তবে এটি স্বয়ংক্রিয়ভাবে সেগুলোকে একত্রিত করে। মনে রাখবেন যে, .output_text নন-টেক্সট কন্টেন্ট (যেমন চিন্তা, ছবি, অডিও বা টুল কল) দ্বারা বিভক্ত আগের টেক্সট ব্লকগুলোকে অন্তর্ভুক্ত করে না। জটিল বা ইন্টারলিভড মাল্টিমোডাল রেসপন্সের জন্য, আপনাকে এর পরিবর্তে ম্যানুয়ালি steps উপর পুনরাবৃত্তি করতে হবে। অন্যান্য মিডিয়া কনভেনিয়েন্স প্রপার্টি সম্পর্কে আরও জানতে, ইন্টারঅ্যাকশন ওভারভিউ দেখুন।

মিথুন রাশির সাথে চিন্তা

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

প্রতিটি মডেল বিভিন্ন থিঙ্কিং কনফিগারেশন সমর্থন করে, যা আপনাকে খরচ, ল্যাটেন্সি এবং ইন্টেলিজেন্সের উপর নিয়ন্ত্রণ দেয়। আরও বিস্তারিত জানতে, থিঙ্কিং গাইডটি দেখুন।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input="How does AI work?",
    generation_config={
        "thinking_level": "low"
    }
)
print(interaction.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "How does AI work?",
    generation_config: {
      thinking_level: "low",
    },
  });
  console.log(interaction.output_text);
}

await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "How does AI work?",
    "generation_config": {
      "thinking_level": "low"
    }
  }'

সিস্টেম নির্দেশাবলী এবং অন্যান্য কনফিগারেশন

আপনি সিস্টেম নির্দেশাবলীর মাধ্যমে জেমিনি মডেলের আচরণ নিয়ন্ত্রণ করতে পারেন। মডেলের আচরণ কনফিগার করতে একটি system_instruction প্যারামিটার পাস করুন।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    system_instruction="You are a cat. Your name is Neko.",
    input="Hello there"
)

print(interaction.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "Hello there",
    system_instruction: "You are a cat. Your name is Neko.",
  });
  console.log(interaction.output_text);
}

await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "system_instruction": "You are a cat. Your name is Neko.",
    "input": "Hello there"
  }'

আপনি generation_config প্যারামিটার ব্যবহার করে তাপমাত্রার মতো ডিফল্ট জেনারেশন প্যারামিটারগুলোও ওভাররাইড করতে পারেন।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input="Explain how AI works",
    generation_config={
        "temperature": 1.0
    }
)
print(interaction.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "Explain how AI works",
    generation_config: {
      temperature: 1.0,
    },
  });
  console.log(interaction.output_text);
}

await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "Explain how AI works",
    "generation_config": {
      "temperature": 1.0
    }
  }'

কনফিগারযোগ্য প্যারামিটারসমূহের সম্পূর্ণ তালিকা এবং তাদের বিবরণের জন্য ইন্টারঅ্যাকশনস এপিআই রেফারেন্স দেখুন।

মাল্টিমোডাল ইনপুট

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

পাইথন

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="path/to/organ.jpg")

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input=[
        {"type": "text", "text": "Tell me about this instrument"},
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        }
    ]
)
print(interaction.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const uploadedFile = await ai.files.upload({
    file: "path/to/organ.jpg",
    config: { mimeType: "image/jpeg" }
  });

  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: [
      {type: "text", text: "Tell me about this instrument"},
      {
        type: "image",
        uri: uploadedFile.uri,
        mime_type: uploadedFile.mimeType
      }
    ],
  });
  console.log(interaction.output_text);
}

await main();

বিশ্রাম

# First upload the file using the Files API, then use the URI:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": [
      {"type": "text", "text": "Tell me about this instrument"},
      {
        "type": "image",
        "uri": "YOUR_FILE_URI",
        "mime_type": "image/jpeg"
      }
    ]
  }'

ছবি প্রদানের বিকল্প পদ্ধতি এবং আরও উন্নত ইমেজ প্রসেসিং-এর জন্য, আমাদের ইমেজ আন্ডারস্ট্যান্ডিং গাইডটি দেখুন। এই এপিআই ডকুমেন্ট , ভিডিও এবং অডিও ইনপুট ও তা বুঝতেও সহায়তা করে।

স্ট্রিমিং প্রতিক্রিয়া

ডিফল্টরূপে, সম্পূর্ণ জেনারেশন প্রক্রিয়াটি সম্পন্ন হওয়ার পরেই মডেলটি একটি প্রতিক্রিয়া ফেরত দেয়।

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

পাইথন

from google import genai

client = genai.Client()

stream = client.interactions.create(
    model="gemini-3.5-flash",
    input="Explain how AI works",
    stream=True
)
for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "text":
            print(event.delta.text, end="")

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

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

const ai = new GoogleGenAI({});

async function main() {
  const stream = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "Explain how AI works",
    stream: true,
  });

  for await (const event of stream) {
    if (event.event_type === "step.delta") {
      if (event.delta.type === "text") {
        process.stdout.write(event.delta.text);
      }
    }
  }
}

await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  --no-buffer \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "Explain how AI works",
    "stream": true
  }'

একাধিক পালা কথোপকথন

ইন্টারঅ্যাকশনস এপিআই previous_interaction_id ব্যবহার করে ইন্টারঅ্যাকশনগুলোকে একসাথে শৃঙ্খলিত করার মাধ্যমে একাধিক পালাবিশিষ্ট কথোপকথন সমর্থন করে। প্রতিটি পালা একটি পৃথক ইন্টারঅ্যাকশন, এবং এপিআই স্বয়ংক্রিয়ভাবে কথোপকথনের ইতিহাস পরিচালনা করে।

পাইথন

from google import genai

client = genai.Client()

interaction1 = client.interactions.create(
    model="gemini-3.5-flash",
    input="I have 2 dogs in my house.",
)
print(interaction1.output_text)

interaction2 = client.interactions.create(
    model="gemini-3.5-flash",
    input="How many paws are in my house?",
    previous_interaction_id=interaction1.id,
)
print(interaction2.output_text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction1 = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "I have 2 dogs in my house.",
  });
  console.log("Response 1:", interaction1.output_text);

  const interaction2 = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "How many paws are in my house?",
    previous_interaction_id: interaction1.id,
  });
  console.log("Response 2:", interaction2.output_text);
}

await main();

বিশ্রাম

RESPONSE1=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "I have 2 dogs in my house."
  }')

INTERACTION_ID=$(echo "$RESPONSE1" | jq -r '.id')

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "I have two dogs in my house. How many paws are in my house?",
    "previous_interaction_id": "'$INTERACTION_ID'"
  }'

previous_interaction_id স্ট্রিমিং মেথডগুলোর সাথে যুক্ত করে একাধিক পালাবিশিষ্ট কথোপকথনের জন্যও স্ট্রিমিং ব্যবহার করা যেতে পারে।

পাইথন

from google import genai

client = genai.Client()

interaction1 = client.interactions.create(
    model="gemini-3.5-flash",
    input="I have 2 dogs in my house.",
)
print(interaction1.output_text)

stream = client.interactions.create(
    model="gemini-3.5-flash",
    input="How many paws are in my house?",
    previous_interaction_id=interaction1.id,
    stream=True
)
for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "text":
            print(event.delta.text, end="")

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

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

const ai = new GoogleGenAI({});

async function main() {
  const interaction1 = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "I have 2 dogs in my house.",
  });
  console.log("Response 1:", interaction1.output_text);

  const stream = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "How many paws are in my house?",
    previous_interaction_id: interaction1.id,
    stream: true,
  });
  for await (const event of stream) {
    if (event.event_type === "step.delta") {
      if (event.delta.type === "text") {
        process.stdout.write(event.delta.text);
      }
    }
  }
}

await main();

বিশ্রাম

RESPONSE1=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "I have 2 dogs in my house."
  }')
INTERACTION_ID=$(echo "$RESPONSE1" | jq -r '.id')

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  --no-buffer \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "How many paws are in my house?",
    "previous_interaction_id": "'$INTERACTION_ID'",
    "stream": true
  }'

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

ডিফল্টরূপে, আপনি যখন previous_interaction_id ব্যবহার করেন, তখন ইন্টারঅ্যাকশনস এপিআই সার্ভার-সাইডে কথোপকথনের অবস্থা পরিচালনা করে। তবে, আপনি ক্লায়েন্ট সাইডে নিজেই কথোপকথনের ইতিহাস পরিচালনা করে স্টেটলেস মোডেও কাজ করতে পারেন।

স্টেটলেস মোড ব্যবহার করতে: ১. সার্ভার-সাইড স্টোরেজ এড়িয়ে যেতে আপনার অনুরোধে store=false সেট করুন। ২. ক্লায়েন্ট সাইডে কথোপকথনের ইতিহাসকে ধাপগুলোর একটি অ্যারে হিসেবে সংরক্ষণ করুন। ৩. পরবর্তী অনুরোধগুলোতে, input ফিল্ডে সঞ্চিত ধাপগুলো পাস করুন এবং আপনার নতুন পালাটিকে একটি user_input ধাপ হিসেবে যুক্ত করুন।

পাইথন

from google import genai

client = genai.Client()

history = [
    {
        "type": "user_input",
        "content": [{"type": "text", "text": "I have 2 dogs in my house."}]
    }
]

interaction1 = client.interactions.create(
    model="gemini-3.5-flash",
    store=False,
    input=history
)
print("Response 1:", interaction1.steps[-1].content[0].text)

for step in interaction1.steps:
    history.append(step.model_dump())

history.append({
    "type": "user_input",
    "content": [{"type": "text", "text": "How many paws are in my house?"}]
})

interaction2 = client.interactions.create(
    model="gemini-3.5-flash",
    store=False,
    input=history
)
print("Response 2:", interaction2.steps[-1].content[0].text)

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

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

const ai = new GoogleGenAI({});

async function main() {
  const history = [
    {
      type: "user_input",
      content: [{ type: "text", text: "I have 2 dogs in my house." }]
    }
  ];

  const interaction1 = await ai.interactions.create({
    model: "gemini-3.5-flash",
    store: false,
    input: history
  });
  console.log("Response 1:", interaction1.steps.at(-1).content[0].text);

  history.push(...interaction1.steps);

  history.push({
    type: "user_input",
    content: [{ type: "text", text: "How many paws are in my house?" }]
  });

  const interaction2 = await ai.interactions.create({
    model: "gemini-3.5-flash",
    store: false,
    input: history
  });
  console.log("Response 2:", interaction2.steps.at(-1).content[0].text);
}

await main();

বিশ্রাম

# Turn 1: Send request with store: false
RESPONSE1=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.5-flash",
    "store": false,
    "input": [
      {
        "type": "user_input",
        "content": "I have 2 dogs in my house."
      }
    ]
  }')

# Extract the steps from response
MODEL_STEPS=$(echo "$RESPONSE1" | jq '.steps')

# Reconstruct the full history for Turn 2 by combining:
# 1. First user input
# 2. Model response steps
# 3. Second user input
HISTORY=$(jq -n \
  --argjson first_input '[{"type": "user_input", "content": "I have 2 dogs in my house."}]' \
  --argjson model_steps "$MODEL_STEPS" \
  --argjson second_input '[{"type": "user_input", "content": "How many paws are in my house?"}]' \
  "'"'"'$first_input + $model_steps + $second_input'"'"'")

# Turn 2: Send the full history
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d "{
    \"model\": \"gemini-3.5-flash\",
    \"store\": false,
    \"input\": $HISTORY
  }"

প্রম্পটিং টিপস

জেমিনি থেকে সর্বোত্তম সুবিধা পাওয়ার পরামর্শের জন্য আমাদের দ্রুত প্রকৌশল নির্দেশিকাটি দেখুন।

এরপর কী?