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.5-flash
  • gemini-3.1-flash-lite
  • gemini-3-pro-image-preview('Nano Banana Pro')
  • gemini-3.1-flash-image-preview('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의 지리 공간 데이터에 연결하여 앱에 위치 인식 기능을 빌드할 수 있도록 합니다.

자세한 내용, 권장사항, 사용 사례는 일반 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의 파운데이션 모델 프레임워크를 통해 Gemini API에 액세스하는 방법에 관한 의견 보내기