mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
Add function calling (tool calling) support to GeminiLanguageModel
conforming to Apple's FoundationModels framework.
* Add .toolCalling capability to GeminiLanguageModel.
* Translate FoundationModels ToolDefinition into Gemini Tool and
FunctionDeclaration using OpenAPI parametersJsonSchema.
* Map GenerationOptions.ToolCallingMode (.allowed, .required,
.disallowed) to Gemini FunctionCallingConfig.Mode.
* Stream function calls in GeminiLanguageModelExecutor, forwarding
JSON-encoded arguments or empty fallback "{}" into channel actions.
* Translate Transcript tool calls and tool outputs into Gemini Content
parts, preserving thought signatures from reasoning models and
flushing buffered reasoning thoughts cleanly.
* Unpack structured tool responses and wrap scalar text tool outputs
under the result field.
* Support parameterless tools with empty arguments across request
schema translation, model response handling, and transcript history.
* Add unit tests across GeminiLanguageModel, GeminiRequestTranslator,
and GeminiTranscriptTranslator.
* Add end-to-end integration tests covering single-turn, sequential,
parallel, disallowed, parameterless, and reasoning tool calling
across all supported backends.
2.5 KiB
2.5 KiB
GeminiLanguageModel Tests
Unit and integration test suites validating GeminiLanguageModel protocol
conformance, streaming response generation, transcript translation, error
mapping, and backend integration.
Quick Start
# Run all unit tests (fast, ~0.04s, skips integration tests)
swift test --skip Integration
# Run all tests in this target (including integration tests)
swift test --filter GeminiLanguageModelTests
Test Suites
| Suite / File | Scope | Strategy |
|---|---|---|
GeminiLanguageModelTests.swift |
Protocol conformance, single/multi-turn responses, streaming, tool calling | Unit (MockHTTPURLProtocol) |
GenerationSchema+GeminiTests.swift |
JSON Schema encoding and property ordering conversion | Unit (pure transformation) |
GeminiRequestTranslatorTests.swift |
Request, generation config, tool declarations, and tool mode mapping | Unit (pure transformation) |
GeminiTranscriptTranslatorTests.swift |
Apple Transcript <-> Gemini payload mapping (tools, reasoning, prompts) |
Unit (pure transformation) |
GeminiErrorMapperTests.swift |
HTTP and API error mapping to LanguageModelError |
Unit (exhaustive mapping) |
IntegrationTestingBackendTests.swift |
Endpoint resolution and credential discovery | Unit / Infrastructure |
IntegrationTests/ |
End-to-end Gemini and Firebase AI Logic integration tests | Integration (see IntegrationTests/README.md) |
Testing Architecture
This target separates tests into two distinct tiers:
-
Unit Tests (Default):
- Use
MockHTTPURLProtocolfor deterministic, zero-network, sub-second execution. - Run cleanly in offline, CI, and local development environments without any credentials or background daemons.
- Use
-
Integration Tests (
IntegrationTests/):- Tagged with
.tags(.integration)and gated by.requireIntegrationTestingBackend. - Exercise endpoints on Google Cloud and Firebase using configured credentials.
- Isolated in the
IntegrationTests/subfolder so unit test runs are never slowed down by network timeouts or external dependencies.
- Tagged with
Tip
For details on configuring credentials and parameterizing integration tests, see the Integration Tests Guide.