@@ -58,6 +58,34 @@ public struct GenerationConfig {
58
58
/// (unbounded).
59
59
public let maxOutputTokens : Int ?
60
60
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
+
61
89
/// A set of up to 5 `String`s that will stop output generation. If
62
90
/// specified, the API will stop at the first appearance of a stop sequence.
63
91
/// The stop sequence will not be included as part of the response.
@@ -88,11 +116,14 @@ public struct GenerationConfig {
88
116
/// - Parameter topK: See ``topK``
89
117
/// - Parameter candidateCount: See ``candidateCount``
90
118
/// - Parameter maxOutputTokens: See ``maxOutputTokens``
119
+ /// - Parameter presencePenalty: See ``presencePenalty``
120
+ /// - Parameter frequencyPenalty: See ``frequencyPenalty``
91
121
/// - Parameter stopSequences: See ``stopSequences``
92
122
/// - Parameter responseMIMEType: See ``responseMIMEType``
93
123
/// - Parameter responseSchema: See ``responseSchema``
94
124
public init ( temperature: Float ? = nil , topP: Float ? = nil , topK: Int ? = nil ,
95
125
candidateCount: Int ? = nil , maxOutputTokens: Int ? = nil ,
126
+ presencePenalty: Float ? = nil , frequencyPenalty: Float ? = nil ,
96
127
stopSequences: [ String ] ? = nil , responseMIMEType: String ? = nil ,
97
128
responseSchema: Schema ? = nil ) {
98
129
// Explicit init because otherwise if we re-arrange the above variables it changes the API
@@ -102,6 +133,8 @@ public struct GenerationConfig {
102
133
self . topK = topK
103
134
self . candidateCount = candidateCount
104
135
self . maxOutputTokens = maxOutputTokens
136
+ self . presencePenalty = presencePenalty
137
+ self . frequencyPenalty = frequencyPenalty
105
138
self . stopSequences = stopSequences
106
139
self . responseMIMEType = responseMIMEType
107
140
self . responseSchema = responseSchema
0 commit comments