Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FirebaseAI/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This directory contains the main source code for the FirebaseAI library.
- **`GenerateContentError.swift`**: Defines the public `GenerateContentError` enum, representing errors that can occur when generating content.
- **`GenerateContentRequest.swift`**: Defines the `GenerateContentRequest` struct, 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 the `GenerationConfig` struct for configuring model parameters (e.g., temperature, topP).
- **`GenerationConfig.swift`**: Defines the `GenerationConfig` struct for configuring model parameters (e.g., maxOutputTokens).
- **`GenerativeAIRequest.swift`**: Defines the `GenerativeAIRequest` protocol 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 the `GenerativeModel` class, representing a remote multimodal model. It provides methods for generating content and starting chats.
Expand Down
5 changes: 5 additions & 0 deletions FirebaseAI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased
- [changed] Deprecated model tuning parameters (`temperature`, `topP`, `topK`, `candidateCount`,
`presencePenalty`, and `frequencyPenalty`) in `GenerationConfig` and `LiveGenerationConfig` as
they are unsupported in Gemini 3.x and later models.

# 12.19.0
- [feature] **Public Preview**: Added `GeminiLanguageModel`, allowing Gemini
models to be used with Apple's Foundation Models framework. See the
Expand Down
137 changes: 79 additions & 58 deletions FirebaseAI/Sources/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,67 +73,9 @@ public struct GenerationConfig: Sendable, Equatable {
/// for more details.
///
/// - Parameters:
/// - temperature:Controls the randomness of the language model's output. Higher values (for
/// example, 1.0) make the text more random and creative, while lower values (for example,
/// 0.1) make it more focused and deterministic.
///
/// > Note: A temperature of 0 means that the highest probability tokens are always selected.
/// > In this case, responses for a given prompt are mostly deterministic, but a small amount
/// > of variation is still possible.
///
/// > Important: The range of supported temperature values depends on the model; see the
/// > [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#temperature)
/// > for more details.
/// - topP: Controls diversity of generated text. Higher values (e.g., 0.9) produce more diverse
/// text, while lower values (e.g., 0.5) make the output more focused.
///
/// The supported range is 0.0 to 1.0.
///
/// > Important: The default `topP` value depends on the model; see the
/// > [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#top-p)
/// > for more details.
/// - topK: Limits the number of highest probability words the model considers when generating
/// text. For example, a topK of 40 means only the 40 most likely words are considered for the
/// next token. A higher value increases diversity, while a lower value makes the output more
/// deterministic.
///
/// The supported range is 1 to 40.
///
/// > Important: Support for `topK` and the default value depends on the model; see the
/// [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#top-k)
/// for more details.
/// - candidateCount: The number of response variations to return; defaults to 1 if not set.
/// Support for multiple candidates depends on the model; see the
/// [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)
/// for more details.
/// - maxOutputTokens: Maximum number of tokens that can be generated in the response.
/// See the configure model parameters [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#max-output-tokens)
/// for more details.
/// - presencePenalty: Controls the likelihood of repeating the same words or phrases already
/// generated in the text. Higher values increase the penalty of repetition, resulting in more
/// diverse output.
///
/// > Note: While both `presencePenalty` and `frequencyPenalty` discourage repetition,
/// > `presencePenalty` applies the same penalty regardless of how many times the word/phrase
/// > has already appeared, whereas `frequencyPenalty` increases the penalty for *each*
/// > repetition of a word/phrase.
///
/// > Important: The range of supported `presencePenalty` values depends on the model; see the
/// > [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)
/// > for more details
/// - frequencyPenalty: Controls the likelihood of repeating words or phrases, with the penalty
/// increasing for each repetition. Higher values increase the penalty of repetition,
/// resulting in more diverse output.
///
/// > Note: While both `frequencyPenalty` and `presencePenalty` discourage repetition,
/// > `frequencyPenalty` increases the penalty for *each* repetition of a word/phrase, whereas
/// > `presencePenalty` applies the same penalty regardless of how many times the word/phrase
/// > has already appeared.
///
/// > Important: The range of supported `frequencyPenalty` values depends on the model; see
/// > the
/// > [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)
/// > for more details
/// - stopSequences: A set of up to 5 `String`s that will stop output generation. If specified,
/// the API will stop at the first appearance of a stop sequence. The stop sequence will not
/// be included as part of the response. See the
Expand Down Expand Up @@ -174,6 +116,11 @@ public struct GenerationConfig: Sendable, Equatable {
/// > that it is not subject to any SLA or deprecation policy and could change in
/// > backwards-incompatible ways.
/// - imageConfig: Configuration options for generating images.
@available(
*,
deprecated,
message: "candidateCount, temperature, topP, topK, presencePenalty, and frequencyPenalty are unsupported in Gemini 3.x and later models."
)
public init(temperature: Float? = nil, topP: Float? = nil, topK: Int? = nil,
candidateCount: Int? = nil, maxOutputTokens: Int? = nil,
presencePenalty: Float? = nil, frequencyPenalty: Float? = nil,
Expand All @@ -200,6 +147,80 @@ public struct GenerationConfig: Sendable, Equatable {
self.speechConfig = speechConfig?.speechConfig
}

/// Creates a new `GenerationConfig` value without deprecated tuning parameters.
///
/// See the
/// [Configure model parameters](https://firebase.google.com/docs/vertex-ai/model-parameters)
/// guide and the
/// [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)
/// for more details.
///
/// - Parameters:
/// - maxOutputTokens: Maximum number of tokens that can be generated in the response.
/// See the configure model parameters [documentation](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=ios#max-output-tokens)
/// for more details.
/// - stopSequences: A set of up to 5 `String`s that will stop output generation. If specified,
/// the API will stop at the first appearance of a stop sequence. The stop sequence will not
/// be included as part of the response. See the
/// [Cloud documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig)
/// for more details.
/// - responseMIMEType: Output response MIME type of the generated candidate text.
///
/// Supported MIME types:
/// - `text/plain`: Text output; the default behavior if unspecified.
/// - `application/json`: JSON response in the candidates.
/// - `text/x.enum`: For classification tasks, output an enum value as defined in the
/// `responseSchema`.
/// - responseSchema: Output schema of the generated candidate text. If set, a compatible
/// `responseMIMEType` must also be set.
///
/// Compatible MIME types:
/// - `application/json`: Schema for JSON response.
///
/// Refer to the
/// [Generate structured
/// output](https://firebase.google.com/docs/vertex-ai/structured-output?platform=ios) guide
/// for more details.
/// - responseModalities: The data types (modalities) that may be returned in model responses.
///
/// See the [multimodal
/// responses](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal-response-generation)
/// documentation for more details.
///
/// > Warning: Specifying response modalities is a **Public Preview** feature, which means
/// > that it is not subject to any SLA or deprecation policy and could change in
/// > backwards-incompatible ways.
/// - thinkingConfig: Configuration for controlling the "thinking" behavior of compatible Gemini
/// models; see ``ThinkingConfig`` for more details.
/// - speechConfig: Configuration for controlling the voice of the model during conversation;
/// see ``SpeechConfig`` for more details.
///
/// > Warning: Specifying a speech configuration is a **Public Preview** feature, which means
/// > that it is not subject to any SLA or deprecation policy and could change in
/// > backwards-incompatible ways.
/// - imageConfig: Configuration options for generating images.
public init(maxOutputTokens: Int? = nil,
stopSequences: [String]? = nil, responseMIMEType: String? = nil,
responseSchema: Schema? = nil, responseModalities: [ResponseModality]? = nil,
thinkingConfig: ThinkingConfig? = nil, imageConfig: ImageConfig? = nil,
speechConfig: SpeechConfig? = nil) {
Comment thread
paulb777 marked this conversation as resolved.
temperature = nil
topP = nil
topK = nil
candidateCount = nil
self.maxOutputTokens = maxOutputTokens
presencePenalty = nil
frequencyPenalty = nil
self.stopSequences = stopSequences
self.responseMIMEType = responseMIMEType
self.responseSchema = responseSchema
responseJSONSchema = nil
self.responseModalities = responseModalities
self.thinkingConfig = thinkingConfig
self.imageConfig = imageConfig
self.speechConfig = speechConfig?.speechConfig
Comment thread
paulb777 marked this conversation as resolved.
}

init(temperature: Float? = nil, topP: Float? = nil, topK: Int? = nil, candidateCount: Int? = nil,
maxOutputTokens: Int? = nil, presencePenalty: Float? = nil, frequencyPenalty: Float? = nil,
stopSequences: [String]? = nil, responseMIMEType: String, responseJSONSchema: JSONObject,
Expand Down
Loading
Loading