mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-09 22:36:01 +05:45
10 KiB
10 KiB
FirebaseAI Codebase Map
This file provides a consolidated overview of the FirebaseAI directory structure and its contents, intended to help AI agents navigate and understand the codebase efficiently.
Sources/
This directory contains the main source code for the FirebaseAI library.
Files in Sources/
AILog.swift: Defines an internalAILogenum for logging within the Firebase AI SDK. It includes aMessageCodeenum for various log messages and helper functions for logging at different levels (error, warning, notice, info, debug).Chat.swift: Defines theChatclass, which represents a back-and-forth chat with aGenerativeModel. It manages the chat history and provides methods for sending messages.Constants.swift: Defines aConstantsenum containing constants for the Firebase AI SDK, such as the base error domain.Errors.swift: Defines various error-related structs and enums used for parsing and representing errors from the backend, such asErrorStatusandRPCStatus.FirebaseAI.swift: The primary entry point for using the Firebase AI SDK. It provides factory methods for creatingGenerativeModelandLiveGenerativeModelinstances.FirebaseInfo.swift: Encapsulates Firebase-related information used by the SDK, such as project ID, API key, App Check, and Auth interop instances.GenAIURLSession.swift: Provides aGenAIURLSessionenum with a defaultURLSessioninstance for the SDK to use.GenerateContentError.swift: Defines the publicGenerateContentErrorenum, representing errors that can occur when generating content.GenerateContentRequest.swift: Defines theGenerateContentRequeststruct, representing a request to generate content from the model.GenerateContentResponse.swift: Represents the model's response to a generate content request, including usage metadata, candidates, and prompt feedback.GenerationConfig.swift: Defines theGenerationConfigstruct for configuring model parameters (e.g., maxOutputTokens).GenerativeAIRequest.swift: Defines theGenerativeAIRequestprotocol for requests sent to the generative AI backend.GenerativeAIService.swift: Responsible for making requests to the generative AI backend, handling authentication, URL construction, and response parsing.GenerativeModel.swift: Defines theGenerativeModelclass, representing a remote multimodal model. It provides methods for generating content and starting chats.History.swift: A thread-safe class for managing chat history, used by theChatclass.JSONValue.swift: Defines theJSONValueenum andJSONObjecttypealias for representing JSON values.ModalityTokenCount.swift: Represents token counting information for a single modality.ModelContent.swift: Represents the content of a message to or from the model (can contain multipleParts).PartsRepresentable.swift: Protocol implemented by types that can be converted into an array ofParts.PartsRepresentable+Image.swift: ExtendsUIImage,NSImage, etc., to conform toPartsRepresentable.Safety.swift: Structs and enums related to safety settings and ratings (e.g.,HarmCategory).TemplateChat.swift: Chat session that uses a prompt template.TemplateGenerateContentRequest.swift: Request for generating content from a template.TemplateGenerativeModel.swift: Model for generating content from a prompt template.TemplateInput.swift: Defines theTemplateInputenum for representing different types of input to a template.Tool.swift: Structs and enums related to tools and function calling (e.g.,FunctionDeclaration).
Sources/Protocols/
This directory contains Swift protocols used throughout the FirebaseAI library.
Internal Protocols
CodableProtoEnum.swift: Provides helper protocols for encoding and decoding protobuf enums (ProtoEnum,DecodableProtoEnum,EncodableProtoEnum).
Sources/Types/
Data types used in the FirebaseAI library.
Public Types
Backend.swift: Used to configure the backend API (Agent Platform Gemini API or Gemini Developer API).ImageConfig.swift: Defines theImageConfigstruct, used for configuring generated image properties like aspect ratio and size.Part.swift: Defines thePartprotocol and conforming structs (Text, InlineData, FunctionCall, etc.).ResponseModality.swift: Represents types of data a model can produce (text, image, audio).Schema.swift: Allows definition of input and output data types for function calling.ThinkingConfig.swift: Controls the "thinking" behavior of compatible Gemini models.URLContextMetadata.swift: Metadata related to theGenerativeModel.Tool.urlContext()tool.URLMetadata.swift: Metadata for a single URL retrieved by theGenerativeModel.Tool.urlContext()tool.
Sources/Types/Public/Tools/
GoogleMaps.swift: Tool that allows the model to ground responses in data from Google Maps.CodeExecution.swift: Tool that allows the model to execute code (currently an empty marker struct).TemplateTool.swift: Tool that a model may use when generating responses with server prompt templates (function declarations and Grounding with Google Maps).TemplateToolConfig.swift: Tool configuration options for tools used with server prompt templates.
Sources/Types/Public/Live/
AudioTranscriptionConfig.swift: Used to enable and configure audio transcriptions for Gemini Live.LiveAudioTranscription.swift: Represents text transcription of audio during live interaction.LiveGenerationConfig.swift: Configuration options for live content generation.LiveGenerativeModel.swift: Multimodal model supporting bidirectional streaming.LiveServerContent.swift: Incremental server update generated by the model.LiveServerGoingAwayNotice.swift: Notification from the server that it will disconnect soon.LiveServerMessage.swift: Represents an update from the server (content, tool call, etc.).LiveServerToolCall.swift: Request from server for client to execute function calls.LiveServerToolCallCancellation.swift: Notification to cancel a previous function call.LiveServerVoiceActivity.swift: Notification that the server detected the start or end of user speech (VoiceActivityType), surfaced viaLiveServerContent.voiceActivity.LiveSession.swift: Represents a live WebSocket session with methods to send real-time data.LiveSessionErrors.swift: Public error structs related to live sessions.SpeechConfig.swift: Controls the voice of the model during conversation.
Internal Types
ProtoDuration.swift: Represents a signed, fixed-length span of time (mappings togoogle.protobuf.duration).InternalPart.swift: Defines internal representations for various part types (InlineData,FileData, etc.).DataType.swift: Enum for OpenAPI data types used in schemas.APIConfig.swift: Configures the generative AI backend API used by the SDK.AppCheck.swift: Internal helper extension for fetching App Check tokens.ProtoDate.swift: Represents a whole or partial calendar date (mappings togoogle.type.Date).
Sources/Types/Internal/Tools/
URLContext.swift: Empty struct serving to enable the URL context tool.TemplateFunction.swift: Wire representation of a function declaration for server prompt templates, using JSON Schema for its input and output schemas.TemplateTool+Internal.swift: Converts the publicTemplateToolinto its encodable wire representation.
Sources/Types/Internal/Requests/
CountTokensRequest.swift: Request structure for thecountTokensAPI endpoint.
Sources/Types/Internal/Live/
AsyncWebSocket.swift: Async/await wrapper aroundURLSessionWebSocketTask.BidiGenerateContentClientContent.swift: Incremental update delivered from the client.BidiGenerateContentClientMessage.swift: Messages a client can send in a bidirectional stream.BidiGenerateContentRealtimeInput.swift: User input sent in real time (audio, video, etc.).BidiGenerateContentServerContent.swift: Incremental server update.BidiGenerateContentServerMessage.swift: Response message from server.BidiGenerateContentSetup.swift: First message sent by client to configure stream.BidiGenerateContentSetupComplete.swift: Sent by server to indicate setup is complete.BidiGenerateContentToolCall.swift: Request from server for function calls.BidiGenerateContentToolCallCancellation.swift: Notification to cancel a tool call.BidiGenerateContentToolResponse.swift: Client response to a tool call.BidiGenerateContentTranscription.swift: Transcribed text from audio input.BidiGenerationConfig.swift: Config for live content generation.BidiSpeechConfig.swift: Speech generation configuration.BidiVoiceActivity.swift: Voice activity detected in the audio stream (start or end of user speech).GoAway.swift: Notification from server that it will disconnect soon.LiveSessionService.swift: Actor managing connection and communication for aLiveSession.VoiceConfig.swift: Configuration for the speaker's voice.
Sources/Types/Internal/Errors/
BackendError.swift: Captures detailed error information from the backend service.EmptyContentError.swift: Specific error for when a candidate has no content and no finish reason.
Sources/Extensions/
Contains extensions to Firebase AI types and external model types.
Sources/Extensions/Public/
FirebaseAI+GeminiLanguageModel.swift: Adds thegeminiLanguageModel(name:)factory method toFirebaseAIfor integrating with Apple's Foundation Models framework.
Sources/Extensions/Internal/
FirebaseInfo+Headers.swift: Provides request header generation for Firebase AI and Gemini Language Model requests.GeminiLanguageModel+Firebase.swift: ExtendsGeminiLanguageModelwith an initializer configured using aFirebaseAIinstance.JSONSerialization+prettyString.swift: Adds a helper method toJSONSerializationfor pretty-printing JSON data.