This commit is contained in:
clean99 2026-10-29 13:31:39 +08:00 • committed by GitHub
commit a80d85e76a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 4 deletions

View file

@ -164,8 +164,8 @@ class OllamaChatConfig(BaseConfig):
optional_params["top_p"] = value
if param == "frequency_penalty":
optional_params["repeat_penalty"] = value
if param == "stop":
optional_params["stop"] = value
if param == "stop" and value != "":
optional_params["stop"] = [value] if isinstance(value, str) else value
if param == "response_format" and isinstance(value, dict) and value.get("type") == "json_object":
optional_params["format"] = "json"
if param == "response_format" and isinstance(value, dict) and value.get("type") == "json_schema":

View file

@ -246,8 +246,8 @@ class OllamaConfig(BaseConfig):
optional_params["top_p"] = value
elif param == "frequency_penalty":
optional_params["frequency_penalty"] = value
elif param == "stop":
optional_params["stop"] = value
elif param == "stop" and value != "":
optional_params["stop"] = [value] if isinstance(value, str) else value
elif param == "reasoning_effort" and value is not None:
if model.startswith("gpt-oss"):
optional_params["think"] = value

View file

@ -27,6 +27,26 @@ from litellm.types.utils import Choices, EmbeddingResponse, Message, ModelRespon
from unittest import mock
@pytest.mark.parametrize(
"stop, expected",
[
("END", ["END"]),
("", None),
(["END", "STOP"], ["END", "STOP"]),
([""], [""]),
([], []),
],
)
def test_stop_is_sent_as_an_array(stop: str | list[str], expected: list[str] | None) -> None:
optional_params: Final = get_optional_params(
model="test-model", custom_llm_provider="ollama_chat", stop=stop
)
if expected is None:
assert "stop" not in optional_params
else:
assert optional_params["stop"] == expected
class TestEvent(BaseModel):
name: str
value: int

View file

@ -19,6 +19,26 @@ from litellm.llms.ollama.completion.transformation import (
from litellm.types.utils import Message, ModelResponse, ModelResponseStream
@pytest.mark.parametrize(
"stop, expected",
[
("END", ["END"]),
("", None),
(["END", "STOP"], ["END", "STOP"]),
([""], [""]),
([], []),
],
)
def test_stop_is_sent_as_an_array(stop: str | list[str], expected: list[str] | None) -> None:
optional_params: Final = litellm.utils.get_optional_params(
model="test-model", custom_llm_provider="ollama", stop=stop
)
if expected is None:
assert "stop" not in optional_params
else:
assert optional_params["stop"] == expected
class TestOllamaConfig:
def test_transform_response_standard(self):
# Initialize config