Gemini API এর সাথে ফাংশন কলিং, Gemini API এর সাথে ফাংশন কলিং

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

  • পদক্ষেপ নিন: এপিআই (API) ব্যবহার করে বাহ্যিক সিস্টেমের সাথে যোগাযোগ করুন, যেমন—অ্যাপয়েন্টমেন্ট নির্ধারণ করা, ইনভয়েস তৈরি করা, ইমেল পাঠানো বা স্মার্ট হোম ডিভাইস নিয়ন্ত্রণ করা।
  • জ্ঞান বৃদ্ধি করুন: ডেটাবেস, এপিআই এবং নলেজ বেসের মতো বাহ্যিক উৎস থেকে তথ্য সংগ্রহ করুন।
  • কার্যক্ষমতা বৃদ্ধি করুন: গণনা সম্পাদন করতে এবং মডেলের সীমাবদ্ধতা বাড়াতে বাহ্যিক সরঞ্জাম ব্যবহার করুন, যেমন ক্যালকুলেটর ব্যবহার করা বা চার্ট তৈরি করা।

আপনি নিচে এই ব্যবহারগুলোর উদাহরণ দেখতে পারেন:

মিটিংয়ের সময়সূচী নির্ধারণ করুন

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

পাইথন

from google import genai

schedule_meeting_function = {
    "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 (e.g., '2024-07-29')"},
            "time": {"type": "string", "description": "Time (e.g., '15:00')"},
            "topic": {"type": "string", "description": "The meeting topic."},
        },
        "required": ["attendees", "date", "time", "topic"],
    },
}

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="Schedule a meeting with Bob and Alice for 03/14/2025 at 10:00 AM about Q3 planning.",
    tools=[{"type": "function", **schedule_meeting_function}],
)

for step in interaction.steps:
    if step.type == "function_call":
        print(f"Function to call: {step.name}")
        print(f"Arguments: {step.arguments}")

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

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

const client = new GoogleGenAI({});

const scheduleMeetingFunction = {
  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 (e.g., "2024-07-29")' },
      time: { type: 'string', description: 'Time (e.g., "15:00")' },
      topic: { type: 'string', description: 'The meeting topic.' },
    },
    required: ['attendees', 'date', 'time', 'topic'],
  },
};

const interaction = await client.interactions.create({
  model: 'gemini-3.7-flash',
  input: 'Schedule a meeting with Bob and Alice for 03/27/2025 at 10:00 AM about Q3 planning.',
  tools: [scheduleMeetingFunction],
});

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

বিশ্রাম

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.7-flash",
    "input": "Schedule a meeting with Bob and Alice for 03/27/2025 at 10:00 AM about Q3 planning.",
    "tools": [{
        "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"},
            "time": {"type": "string"},
            "topic": {"type": "string"}
          },
          "required": ["attendees", "date", "time", "topic"]
        }
    }]
  }'

আবহাওয়া পান

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

পাইথন

from google import genai

weather_function = {
    "type": "function",
    "name": "get_current_temperature",
    "description": "Gets the current temperature for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city name, e.g. San Francisco",
            },
        },
        "required": ["location"],
    },
}

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="What's the temperature in London?",
    tools=[weather_function],
)

for step in interaction.steps:
    if step.type == "function_call":
        print(f"Function to call: {step.name}")
        print(f"Arguments: {step.arguments}")

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

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

const client = new GoogleGenAI({});

const weatherFunctionDeclaration = {
  type: 'function',
  name: 'get_current_temperature',
  description: 'Gets the current temperature for a given location.',
  parameters: {
    type: 'object',
    properties: {
      location: {
        type: 'string',
        description: 'The city name, e.g. San Francisco',
      },
    },
    required: ['location'],
  },
};

const interaction = await client.interactions.create({
  model: 'gemini-3.7-flash',
  input: "What's the temperature in London?",
  tools: [weatherFunctionDeclaration],
});

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

বিশ্রাম

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.7-flash",
    "input": "What'\''s the temperature in London?",
    "tools": [{
      "type": "function",
      "name": "get_current_temperature",
      "description": "Gets the current temperature for a given location.",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {"type": "string", "description": "The city name"}
        },
        "required": ["location"]
      }
    }]
  }'

চার্ট তৈরি করুন

এই উদাহরণটি দেখায় কিভাবে স্ট্রাকচার্ড ডেটা থেকে একটি বার চার্ট তৈরি করার জন্য একটি ফাংশন সংজ্ঞায়িত করতে হয় এবং এটি প্রদর্শন করে যে, মডেলটি কীভাবে গণনা সম্পাদন করতে বা ভিজ্যুয়াল অ্যাসেট তৈরি করতে বাহ্যিক টুল ব্যবহার করতে পারে:

পাইথন

from google import genai

create_chart_function = {
    "type": "function",
    "name": "create_bar_chart",
    "description": "Creates a bar chart given a title, labels, and values.",
    "parameters": {
        "type": "object",
        "properties": {
            "title": {"type": "string", "description": "The title for the chart."},
            "labels": {"type": "array", "items": {"type":