Skip to content

Commit 02e8a01

Browse files
committed
llama_cpp server: document presence_penalty and frequency_penalty, mark as supported
1 parent d957422 commit 02e8a01

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

llama_cpp/server/app.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ def get_llama():
152152
+ "Repeat penalty is a hyperparameter used to penalize the repetition of token sequences during text generation. It helps prevent the model from generating repetitive or monotonous text. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient.",
153153
)
154154

155+
presence_penalty_field = Field(
156+
default=0.0,
157+
ge=-2.0,
158+
le=2.0,
159+
description="Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.",
160+
)
161+
162+
frequency_penalty_field = Field(
163+
default=0.0,
164+
ge=-2.0,
165+
le=2.0,
166+
description="Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
167+
)
155168

156169
class CreateCompletionRequest(BaseModel):
157170
prompt: Optional[str] = Field(
@@ -175,13 +188,13 @@ class CreateCompletionRequest(BaseModel):
175188
ge=0,
176189
description="The number of logprobs to generate. If None, no logprobs are generated.",
177190
)
191+
presence_penalty: Optional[float] = presence_penalty_field
192+
frequency_penalty: Optional[float] = frequency_penalty_field
178193

179194
# ignored or currently unsupported
180195
model: Optional[str] = model_field
181196
n: Optional[int] = 1
182197
logprobs: Optional[int] = Field(None)
183-
presence_penalty: Optional[float] = 0
184-
frequency_penalty: Optional[float] = 0
185198
best_of: Optional[int] = 1
186199
logit_bias: Optional[Dict[str, float]] = Field(None)
187200
user: Optional[str] = Field(None)
@@ -269,12 +282,12 @@ class CreateChatCompletionRequest(BaseModel):
269282
top_p: float = top_p_field
270283
stop: Optional[List[str]] = stop_field
271284
stream: bool = stream_field
285+
presence_penalty: Optional[float] = presence_penalty_field
286+
frequency_penalty: Optional[float] = frequency_penalty_field
272287

273288
# ignored or currently unsupported
274289
model: Optional[str] = model_field
275290
n: Optional[int] = 1
276-
presence_penalty: Optional[float] = 0
277-
frequency_penalty: Optional[float] = 0
278291
logit_bias: Optional[Dict[str, float]] = Field(None)
279292
user: Optional[str] = Field(None)
280293

0 commit comments

Comments
 (0)