Apple의 Foundation Models 프레임워크를 통해 Gemini API에 액세스할 때 모델에 도구 제공


이 페이지의 예에서는 시작하기: Apple의 Foundation Models 프레임워크를 통해 Gemini API에 액세스를 완료했다고 가정합니다.


Apple의 Foundation Models 프레임워크를 통해 Gemini API에 액세스할 때 Gemini 모델에 Gemini 기본 제공 도구를 제공하여 모델을 외부 데이터 소스에 연결할 수 있습니다.

이 페이지에서는 Gemini 모델에 다음 기본 제공 도구를 사용하는 방법을 보여줍니다.

Google Search을(를) 사용한 그라운딩은 Gemini 모델을 공개적으로 사용 가능한 실시간 웹 콘텐츠에 연결합니다. 이를 통해 모델은 더 정확하고 최신 답변을 제공하고 검증 가능한 출처를 인용할 수 있습니다.

세부정보, 권장사항, 사용 사례는 일반적인 그라운딩 Google Search 가이드를 참고하세요.

지원되는 모델

  • gemini-3.1-pro-preview
  • gemini-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')

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 그라운딩은 Gemini 모델을 Google Maps의 지리공간 데이터에 연결하므로 앱에 위치 인식 기능 을 빌드할 수 있습니다.

세부정보, 권장사항, 사용 사례는 일반적인 Grounding with 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에 액세스하는 것에 관한 **의견 보내기**