@@ -58,6 +58,34 @@ public struct GenerationConfig {
5858 /// (unbounded).
5959 public let maxOutputTokens : Int ?
6060
61+ /// Controls the likelihood of repeating the same words or phrases already generated in the text.
62+ ///
63+ /// Higher values increase the penalty of repetition, resulting in more diverse output. The
64+ /// maximum value for `presencePenalty` is up to, but not including, `2.0`; the minimum value is
65+ /// `-2.0`.
66+ ///
67+ /// > Note: While both `presencePenalty` and ``frequencyPenalty`` discourage repetition,
68+ /// > `presencePenalty` applies the same penalty regardless of how many times the word/phrase has
69+ /// > already appeared, whereas `frequencyPenalty` increases the penalty for *each* repetition of
70+ /// > a word/phrase.
71+ ///
72+ /// > Important: Supported by `gemini-1.5-pro-002` and` gemini-1.5-flash-002` only.
73+ public let presencePenalty : Float ?
74+
75+ /// Controls the likelihood of repeating words, with the penalty increasing for each repetition.
76+ ///
77+ /// Higher values increase the penalty of repetition, resulting in more diverse output. The
78+ /// maximum value for `frequencyPenalty` is up to, but not including, `2.0`; the minimum value is
79+ /// `-2.0`.
80+ ///
81+ /// > Note: While both `frequencyPenalty` and ``presencePenalty`` discourage repetition,
82+ /// > `frequencyPenalty` increases the penalty for *each* repetition of a word/phrase, whereas
83+ /// > `presencePenalty` applies the same penalty regardless of how many times the word/phrase has
84+ /// > already appeared.
85+ ///
86+ /// > Important: Supported by `gemini-1.5-pro-002` and` gemini-1.5-flash-002` only.
87+ public let frequencyPenalty : Float ?
88+
6189 /// A set of up to 5 `String`s that will stop output generation. If
6290 /// specified, the API will stop at the first appearance of a stop sequence.
6391 /// The stop sequence will not be included as part of the response.
@@ -88,11 +116,14 @@ public struct GenerationConfig {
88116 /// - Parameter topK: See ``topK``
89117 /// - Parameter candidateCount: See ``candidateCount``
90118 /// - Parameter maxOutputTokens: See ``maxOutputTokens``
119+ /// - Parameter presencePenalty: See ``presencePenalty``
120+ /// - Parameter frequencyPenalty: See ``frequencyPenalty``
91121 /// - Parameter stopSequences: See ``stopSequences``
92122 /// - Parameter responseMIMEType: See ``responseMIMEType``
93123 /// - Parameter responseSchema: See ``responseSchema``
94124 public init ( temperature: Float ? = nil , topP: Float ? = nil , topK: Int ? = nil ,
95125 candidateCount: Int ? = nil , maxOutputTokens: Int ? = nil ,
126+ presencePenalty: Float ? = nil , frequencyPenalty: Float ? = nil ,
96127 stopSequences: [ String ] ? = nil , responseMIMEType: String ? = nil ,
97128 responseSchema: Schema ? = nil ) {
98129 // Explicit init because otherwise if we re-arrange the above variables it changes the API
@@ -102,6 +133,8 @@ public struct GenerationConfig {
102133 self . topK = topK
103134 self . candidateCount = candidateCount
104135 self . maxOutputTokens = maxOutputTokens
136+ self . presencePenalty = presencePenalty
137+ self . frequencyPenalty = frequencyPenalty
105138 self . stopSequences = stopSequences
106139 self . responseMIMEType = responseMIMEType
107140 self . responseSchema = responseSchema
0 commit comments