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


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


Gemini API को Apple के फ़ाउंडेशन मॉडल फ़्रेमवर्क के ज़रिए ऐक्सेस करते समय, 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-preview (इसे "Nano Banana Pro" भी कहा जाता है)
  • gemini-3.1-flash-image-preview (इसे "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 के साथ ग्राउंडिंग करने से, Google Maps मॉडल को Google Maps से मिले जियोस्पेशल डेटा से कनेक्ट किया जाता है. इससे, अपने ऐप्लिकेशन में जगह की जानकारी के हिसाब से काम करने वाली सुविधाएं बनाई जा सकती हैं.Gemini

ज़्यादा जानकारी, सबसे सही तरीके, और इस्तेमाल के उदाहरणों के लिए, 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 को ऐक्सेस करने में आपको क्या परेशानी हुई