fix: add frequency penalty for gpt-4o-mini (#3166)

This commit is contained in:
Charles Packer
2025-07-06 11:05:31 -07:00
committed by GitHub
parent 954675396f
commit 12c2b49461
3 changed files with 25 additions and 10 deletions

View File

@@ -216,6 +216,10 @@ class OpenAIClient(LLMClientBase):
# NOTE: the reasoners that don't support temperature require 1.0, not None
temperature=llm_config.temperature if supports_temperature_param(model) else 1.0,
)
if llm_config.frequency_penalty is not None:
data.frequency_penalty = llm_config.frequency_penalty
if tools and supports_parallel_tool_calling(model):
data.parallel_tool_calls = False

View File

@@ -77,6 +77,10 @@ class LLMConfig(BaseModel):
max_reasoning_tokens: int = Field(
0, description="Configurable thinking budget for extended thinking, only used if enable_reasoner is True. Minimum value is 1024."
)
frequency_penalty: Optional[float] = Field(
None, # Can also deafult to 0.0?
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. From OpenAI: Number between -2.0 and 2.0.",
)
# FIXME hack to silence pydantic protected namespace warning
model_config = ConfigDict(protected_namespaces=())

View File

@@ -324,18 +324,25 @@ class OpenAIProvider(Provider):
else:
handle = self.get_handle(model_name)
configs.append(
LLMConfig(
model=model_name,
model_endpoint_type="openai",
model_endpoint=self.base_url,
context_window=context_window_size,
handle=handle,
provider_name=self.name,
provider_category=self.provider_category,
)
llm_config = LLMConfig(
model=model_name,
model_endpoint_type="openai",
model_endpoint=self.base_url,
context_window=context_window_size,
handle=handle,
provider_name=self.name,
provider_category=self.provider_category,
)
# gpt-4o-mini has started to regress with pretty bad emoji spam loops
# this is to counteract that
if "gpt-4o-mini" in model_name:
llm_config.frequency_penalty = 1.0
if "gpt-4.1-mini" in model_name:
llm_config.frequency_penalty = 1.0
configs.append(llm_config)
# for OpenAI, sort in reverse order
if self.base_url == "https://api.openai.com/v1":
# alphnumeric sort