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