Apple के फ़ाउंडेशन मॉडल फ़्रेमवर्क के ज़रिए Gemini API को ऐक्सेस करते समय, मॉडल को टूल उपलब्ध कराना


इस पेज पर दिए गए उदाहरणों में यह माना गया है कि आपने शुरू करें: Apple के Foundation Models फ़्रेमवर्क के ज़रिए Gemini API को ऐक्सेस करना लेख में दिया गया तरीका पूरा कर लिया है.


Apple के Foundation Models फ़्रेमवर्क के ज़रिए Gemini API को ऐक्सेस करते समय, Gemini मॉडल को Gemini के बिल्ट-इन टूल उपलब्ध कराए जा सकते हैं. इससे मॉडल को बाहरी डेटा सोर्स से कनेक्ट किया जा सकता है.

इस पेज पर, Gemini मॉडल के लिए बिल्ट-इन इन टूल का इस्तेमाल करने का तरीका बताया गया है:

Google Search से सटीक जानकारी पाने की सुविधा, Gemini मॉडल को रीयल-टाइम में, सार्वजनिक तौर पर उपलब्ध वेब कॉन्टेंट से कनेक्ट करती है. इससे मॉडल, ज़्यादा सटीक और अप-टू-डेट जवाब दे पाता है. साथ ही, भरोसेमंद सोर्स के रेफ़रंस भी दे पाता है.

ज़्यादा जानकारी, सबसे सही तरीके, और इस्तेमाल के उदाहरणों के लिए, सामान्य गाइड देखें.Google Search

काम करने वाले मॉडल

  • gemini-3.1-pro-preview
  • gemini-3.5-flash
  • gemini-3.1-flash-lite
  • gemini-3-pro-image (इसे "Nano Banana Pro" भी कहा जाता है)
  • gemini-3.1-flash-image (इसे "Nano Banana 2" भी कहा जाता है)

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-3.1-pro-preview
  • gemini-3.5-flash
  • gemini-3.1-flash-lite

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 के Foundation Models फ़्रेमवर्क के ज़रिए Gemini API को ऐक्सेस करने के बारे में **सुझाव/राय दें या शिकायत करें**