| Các ví dụ trên trang này giả định rằng bạn đã hoàn tất hướng dẫn Bắt đầu: Truy cập vào Gemini API thông qua khung Mô hình nền tảng của Apple. |
Bạn có thể cung cấp các công cụ tích hợp sẵn của Gemini cho các mô hình Gemini khi truy cập vào Gemini API thông qua khung Mô hình nền tảng của Apple để kết nối mô hình với các nguồn dữ liệu bên ngoài.
Trang này hướng dẫn bạn cách sử dụng các công cụ tích hợp sẵn sau đây cho các mô hình Gemini:
Bám sát nguồn bằng Google Search
Tính năng Bám sát nguồn bằng
Để biết thông tin chi tiết, các phương pháp hay nhất và trường hợp sử dụng, hãy xem hướng dẫn chung về Tính năng Tạo sinh dựa trên dữ liệu thực tế bằng
Mô hình được hỗ trợ
gemini-4-argongemini-3.8-flashgemini-3.5-flash-lite(vàgemini-3.1-flash-litecũ hơn)gemini-nano-banana-2.1(Nano Banana 2.1)gemini-3.1-flash-image(Nano Banana 2)gemini-3-pro-image(Nano Banana Pro)
Các mô hình Gemini 3.x Flash đa năng cũ hơn hỗ trợ tính năng này, nhưng không còn được đề xuất sử dụng do ngày ngừng hoạt động sắp tới và/hoặc tự động định tuyến đến các mô hình mới hơn.
Bật công cụ Google Search
Cung cấp công cụ googleSearch trong quá trình tạo 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
Bám sát nguồn bằng Google Maps
Tính năng dựa trên dữ liệu thực tế của
Để biết thông tin chi tiết, các phương pháp hay nhất và trường hợp sử dụng, hãy xem hướng dẫn chung về Tính năng Tạo sinh dựa trên dữ liệu thực tế bằng
Mô hình được hỗ trợ
gemini-4-argongemini-3.8-flashgemini-3.5-flash-lite(vàgemini-3.1-flash-litecũ hơn)
Các mô hình Gemini 3.x Flash đa năng cũ hơn hỗ trợ tính năng này, nhưng không còn được đề xuất sử dụng do ngày ngừng hoạt động sắp tới và/hoặc tự động định tuyến đến các mô hình mới hơn.
Bật công cụ Google Maps
Cung cấp công cụ googleMaps trong quá trình tạo geminiLanguageModel.
Bạn cũng có thể cung cấp toạ độ trong cấu hình của công cụ (không bắt buộc).
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
Gửi ý kiến phản hồi về việc truy cập vào Gemini API thông qua khung Mô hình nền tảng của Apple