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


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


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

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

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

자세한 내용, 권장사항, 사용 사례는 일반 Google Search로 그라운딩 가이드를 참조하세요.

지원되는 모델

  • gemini-4-argon
  • gemini-3.8-flash
  • gemini-3.5-flash-lite (이전 버전인 gemini-3.1-flash-lite)
  • gemini-nano-banana-2.1(Nano Banana 2.1)
  • gemini-3.1-flash-image(Nano Banana 2)
  • gemini-3-pro-image(Nano Banana Pro)

이전의 범용 Gemini 3.x Flash 모델은 이 기능을 지원하지만, 종료 날짜가 다가오거나 최신 모델로 자동 라우팅되므로 더 이상 사용하지 않는 것이 좋습니다.

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-4-argon
  • gemini-3.8-flash
  • gemini-3.5-flash-lite (이전 버전인 gemini-3.1-flash-lite)

이전의 범용 Gemini 3.x Flash 모델은 이 기능을 지원하지만, 종료 날짜가 다가오거나 최신 모델로 자동 라우팅되므로 더 이상 사용하지 않는 것이 좋습니다.

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 액세스에 관한 의견 보내기