| 이 페이지의 예시에서는 시작하기: Apple의 Foundation Models 프레임워크를 통해 Gemini API에 액세스하기를 완료했다고 가정합니다. |
Apple의 Foundation Models 프레임워크를 통해 Gemini API에 액세스하여 모델을 외부 데이터 소스에 연결할 때 Gemini 모델에 내장 도구를 제공할 수 있습니다.Gemini
이 페이지에서는 Gemini 모델에 다음 내장 도구를 사용하는 방법을 보여줍니다.
Google Search 로 그라운딩
자세한 내용, 권장사항, 사용 사례는 일반
지원되는 모델
gemini-3.1-pro-previewgemini-3.5-flashgemini-3.1-flash-litegemini-3-pro-image-preview('Nano Banana Pro')gemini-3.1-flash-image-preview('Nano Banana 2'라고도 함)
Google Search 도구 사용 설정
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 로 그라운딩
자세한 내용, 권장사항, 사용 사례는 일반
지원되는 모델
gemini-3.1-pro-previewgemini-3.5-flashgemini-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의 파운데이션 모델 프레임워크를 통해 Gemini API에 액세스하는 방법에 관한 의견 보내기