| Przykłady na tej stronie zakładają, że masz już za sobą etap Rozpoczęcie: dostęp do Gemini API za pomocą platformy Foundation Models firmy Apple. |
Podczas uzyskiwania dostępu do Gemini API za pomocą platformy modeli podstawowych Apple możesz udostępniać modelom Gemini wbudowane narzędzia, aby Gemini połączyć model z zewnętrznymi źródłami danych.
Na tej stronie dowiesz się, jak korzystać z tych wbudowanych narzędzi do modeli Gemini:
Powiązanie ze źródłami informacji przy użyciu Google Search
Powiązanie ze źródłem informacji z użyciem
Szczegółowe informacje, sprawdzone metody i przypadki użycia znajdziesz w ogólnym przewodniku
Uziemianie za pomocą
Obsługiwane modele
gemini-3.1-pro-previewgemini-3.8-flash(oraz starszegemini-3.7-flash,gemini-3.6-flashigemini-3.5-flash)gemini-3.5-flash-lite(i starszygemini-3.1-flash-lite)gemini-3-pro-image(znany też jako „Nano Banana Pro”)gemini-3.1-flash-image(znany też jako „Nano Banana 2”)
Włącz narzędzie Google Search
Podaj narzędzie googleSearch w ramach tworzenia geminiLanguageModel:
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
Powiązanie ze źródłami informacji przy użyciu Google Maps
Grounding z
Szczegółowe informacje, sprawdzone metody i przypadki użycia znajdziesz w ogólnym przewodniku
Uziemianie za pomocą
Obsługiwane modele
gemini-3.1-pro-previewgemini-3.5-flashgemini-3.1-flash-lite
Włącz narzędzie Google Maps
Udostępnij narzędzie googleMaps w ramach tworzenia geminiLanguageModel.
Opcjonalnie możesz też podać współrzędne w konfiguracji narzędzia.
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
Prześlij opinię o dostępie do Gemini API za pomocą platformy modeli podstawowych Apple