This commit is contained in:
Devauntae Norman 2026-11-03 20:18:31 -05:00 • committed by GitHub
commit d5bb072ccc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 1 deletions

View file

@ -140,6 +140,7 @@ class OllamaChatConfig(BaseConfig):
"temperature",
"seed",
"frequency_penalty",
"presence_penalty",
"stop",
"tools",
"tool_choice",
@ -172,8 +173,13 @@ class OllamaChatConfig(BaseConfig):
optional_params["seed"] = value
if param == "top_p":
optional_params["top_p"] = value
# Ollama exposes OpenAI's additive penalties under the same names.
# `repeat_penalty` is a different, multiplicative setting (1.0 = off),
# so forwarding an OpenAI value of 0 to it would invert the penalty.
if param == "frequency_penalty":
optional_params["repeat_penalty"] = value
optional_params["frequency_penalty"] = value
if param == "presence_penalty":
optional_params["presence_penalty"] = value
if param == "stop":
optional_params["stop"] = value
if param == "response_format" and isinstance(value, dict) and value.get("type") == "json_object":

View file

@ -221,6 +221,7 @@ class OllamaConfig(BaseConfig):
"temperature",
"seed",
"frequency_penalty",
"presence_penalty",
"stop",
"response_format",
"max_completion_tokens",
@ -247,6 +248,8 @@ class OllamaConfig(BaseConfig):
optional_params["top_p"] = value
elif param == "frequency_penalty":
optional_params["frequency_penalty"] = value
elif param == "presence_penalty":
optional_params["presence_penalty"] = value
elif param == "stop":
optional_params["stop"] = value
elif param == "reasoning_effort" and value is not None:

View file

@ -1309,3 +1309,43 @@ def test_reasoning_effort_with_a_matching_think_value_does_not_warn(
assert result["think"] is think
assert _warnings_naming(caplog, "reasoning_effort") == ()
class TestOllamaChatPenaltyParams:
"""OpenAI's penalties are additive (0 = off); Ollama's `repeat_penalty` is multiplicative (1.0 = off)."""
def test_frequency_penalty_is_forwarded_under_its_own_name(self):
optional_params = get_optional_params(
model="ollama_chat/test-model",
frequency_penalty=0,
custom_llm_provider="ollama_chat",
)
assert optional_params["frequency_penalty"] == 0
assert "repeat_penalty" not in optional_params
def test_presence_penalty_is_forwarded(self):
optional_params = get_optional_params(
model="ollama_chat/test-model",
presence_penalty=0.5,
custom_llm_provider="ollama_chat",
)
assert optional_params["presence_penalty"] == 0.5
def test_presence_penalty_is_a_supported_param(self):
supported = OllamaChatConfig().get_supported_openai_params("test-model")
assert "presence_penalty" in supported
assert "frequency_penalty" in supported
def test_explicit_repeat_penalty_is_passed_through(self):
optional_params = get_optional_params(
model="ollama_chat/test-model",
frequency_penalty=0.2,
repeat_penalty=1.3,
custom_llm_provider="ollama_chat",
)
assert optional_params["repeat_penalty"] == 1.3
assert optional_params["frequency_penalty"] == 0.2

View file

@ -1100,3 +1100,15 @@ def test_reasoning_effort_ollama_honors_does_not_warn(
assert result["think"] == think
assert _reasoning_effort_warnings(caplog) == ()
def test_map_openai_params_forwards_presence_penalty() -> None:
config = OllamaConfig()
assert "presence_penalty" in config.get_supported_openai_params("test-model")
assert config.map_openai_params(
non_default_params={"presence_penalty": 0.5},
optional_params={},
model="test-model",
drop_params=False,
) == {"presence_penalty": 0.5}