কোড এক্সিকিউশন

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

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

কোড এক্সিকিউশন সক্ষম করুন

কোড এক্সিকিউশন সক্ষম করতে, মডেলে কোড এক্সিকিউশন টুলটি কনফিগার করুন। এটি মডেলকে কোড তৈরি ও রান করার সুযোগ দেয়।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="What is the sum of the first 50 prime numbers? "
          "Generate and run code for the calculation, and make sure you get all 50.",
    tools=[{"type": "code_execution"}]
)

for step in interaction.steps:
    if step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print(content_block.text)
    elif step.type == "code_execution_call":
        print(step.arguments.code)
    elif step.type == "code_execution_result":
        print(step.result)

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

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

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.7-flash",
    input: "What is the sum of the first 50 prime numbers? " +
           "Generate and run code for the calculation, and make sure you get all 50.",
    tools: [{ type: "code_execution" }]
});

for (const step of interaction.steps) {
    if (step.type === "model_output") {
        for (const contentBlock of step.content) {
            if (contentBlock.type === "text") {
                console.log(contentBlock.text);
            }
        }
    } else if (step.type === "code_execution_call") {
        console.log(step.arguments.code);
    } else if (step.type === "code_execution_result") {
        console.log(step.result);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions"