Apple-এর Foundation Models ফ্রেমওয়ার্কের মাধ্যমে Gemini API অ্যাক্সেস করার সময় মডেলকে টুল প্রদান করা


এই পৃষ্ঠার উদাহরণগুলি ধরে নেয় যে আপনি শুরু করুন: Apple-এর Foundation Models ফ্রেমওয়ার্কের মাধ্যমে Gemini API অ্যাক্সেস করুন সম্পূর্ণ করেছেন।


আপনি Gemini-কে বিল্ট-ইন টুল দিতে পারেন Gemini মডেলের জন্য যখন Apple-এর ফাউন্ডেশন মডেল ফ্রেমওয়ার্কের মাধ্যমে Gemini API অ্যাক্সেস করছেন মডেলকে এক্সটার্নাল ডেটা সোর্সের সাথে কানেক্ট করতে।

Gemini মডেলের জন্য নিম্নলিখিত বিল্ট-ইন টুল কীভাবে ব্যবহার করবেন তা এই পৃষ্ঠায় দেখানো হয়েছে:

Google Search-এর মাধ্যমে গ্রাউন্ডিং করার ফলে Gemini মডেল রিয়েল-টাইম, পাবলিক ডোমেনে উপলভ্য ওয়েব কন্টেন্টের সাথে যুক্ত হতে পারে। এর ফলে মডেলটি আরও সঠিক, আপ-টু-ডেট উত্তর দিতে এবং যাচাইযোগ্য সোর্স উল্লেখ করতে পারে।

বিস্তারিত, পেশাদার পদ্ধতি এবং ব্যবহারের কেসের জন্য, সাধারণ Google Search-এর সাথে গ্রাউন্ডিং গাইড দেখুন।

যেসব মডেলে কাজ করে

  • gemini-4-hydrogen
  • gemini-4-argon
  • gemini-4-carbon
  • gemini-3.8-flash
  • gemini-3.5-flash-lite (এবং পুরনো gemini-3.1-flash-lite)
  • gemini-nano-banana-2.1 (Nano Banana 2.1)
  • gemini-3.1-flash-image (Nano Banana 2)
  • gemini-3-pro-image (Nano Banana Pro)

পুরনো সাধারণ-ব্যবহারের Gemini 3.x Flash মডেল এই ক্ষমতাকে সমর্থন করে, কিন্তু আসন্ন বন্ধের তারিখ এবং/অথবা নতুন মডেলে অটোমেটিক রাউটিংয়ের কারণে সেগুলি আর ব্যবহারের জন্য সাজেস্ট করা হয় না।

geminiLanguageModel তৈরি করার অংশ হিসেবে googleSearch টুল প্রদান করুন:

import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Initialize a `geminiLanguageModel` with a Gemini model that supports your use case.
let model = ai.geminiLanguageModel(
  name: "GEMINI_MODEL_NAME",
  // Provide Google Search as a tool that the model can use to generate its response.
  serverTools: [GeminiTool.googleSearch()]
)

let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "What is the weather in Toronto today?")
for entry in response.transcriptEntries {
  if case let .response(responseEntry) = entry {
    if let groundingMetadata = responseEntry
        .metadata["groundingMetadata"] as? GroundingMetadata {
      for chunk in groundingMetadata.groundingChunks {
        let webChunk = chunk.web
        // use the webChunk
      }
    }
  }
}

// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result

তা জানুন

Google Maps-এর সাথে গ্রাউন্ডিং

Google Maps-এর সাথে গ্রাউন্ডিং, Gemini মডেলকে Google Maps-এর জিওস্পেশিয়াল ডেটার সাথে কানেক্ট করে, যাতে আপনি নিজের অ্যাপে লোকেশন-অ্যাওয়ার ফাংশনালিটি তৈরি করতে পারেন।

বিস্তারিত, পেশাদার পদ্ধতি এবং ব্যবহারের কেসের জন্য, সাধারণ Google Maps-এর সাথে গ্রাউন্ডিং গাইড দেখুন।

যেসব মডেলে কাজ করে

  • gemini-4-hydrogen
  • gemini-4-argon
  • gemini-4-carbon
  • gemini-3.8-flash
  • gemini-3.5-flash-lite (এবং পুরনো gemini-3.1-flash-lite)

পুরনো সাধারণ-ব্যবহারের Gemini 3.x Flash মডেল এই ক্ষমতাকে সমর্থন করে, কিন্তু আসন্ন বন্ধের তারিখ এবং/অথবা নতুন মডেলে অটোমেটিক রাউটিংয়ের কারণে সেগুলি আর ব্যবহারের জন্য সাজেস্ট করা হয় না।

Google Maps টুল চালু করুন

geminiLanguageModel তৈরি করার অংশ হিসেবে googleMaps টুল প্রদান করুন। এছাড়াও, আপনি চাইলে টুলের কনফিগারেশনে কোঅর্ডিনেট দিতে পারেন।

import FoundationModels
import FirebaseCore
import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Initialize a `geminiLanguageModel` with a Gemini model that supports your use case.
let model = ai.geminiLanguageModel(
  name: "GEMINI_MODEL_NAME",
  // Provide Google Maps as a tool that the model can use to generate its response.
  serverTools: [GeminiTool.googleMaps()]
)

let session = LanguageModelSession(model: model)

let response = try await session
      respond(to: "Where is a good place to grab a coffee near Alameda, CA?")

for entry in response.transcriptEntries {
  if case let .response(responseEntry) = entry {
    if let groundingMetadata = responseEntry
        .metadata["groundingMetadata"] as? GroundingMetadata {
      for chunk in groundingMetadata.groundingChunks {
        let mapsChunk = chunk.maps
        // use the mapsChunk
      }
    }
  }
}

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements


Apple-এর ফাউন্ডেশন মডেল ফ্রেমওয়ার্কের মাধ্যমে Gemini API অ্যাক্সেস করার ব্যাপারে মতামত দিন