Skip to content

Commit fb93ae2

Browse files
authored
fix: serialize OllamaChatGenerator think parameter (#3455)
Co-authored-by: ly-wang19 <ly-wang19@users.noreply.github.com>
1 parent dc5819d commit fb93ae2

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

integrations/ollama/src/haystack_integrations/components/generators/ollama/chat/chat_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def to_dict(self) -> dict[str, Any]:
341341
streaming_callback=callback_name,
342342
tools=serialize_tools_or_toolset(self.tools),
343343
response_format=self.response_format,
344+
think=self.think,
344345
)
345346

346347
@classmethod

integrations/ollama/tests/test_chat_generator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,24 @@ def test_to_dict(self):
848848
"type": "object",
849849
"properties": {"name": {"type": "string"}, "age": {"type": "number"}},
850850
},
851+
"think": False,
851852
},
852853
}
853854

854855
assert data == expected_dict
855856

857+
def test_to_dict_and_from_dict_preserves_think(self):
858+
"""`think` enables a model's reasoning output and must survive a
859+
to_dict/from_dict round-trip; otherwise a reloaded generator silently
860+
falls back to think=False (reasoning disabled)."""
861+
component = OllamaChatGenerator(model="gpt-oss", think="high")
862+
863+
data = component.to_dict()
864+
assert data["init_parameters"]["think"] == "high"
865+
866+
restored = OllamaChatGenerator.from_dict(data)
867+
assert restored.think == "high"
868+
856869
def test_from_dict(self):
857870
tool = Tool(
858871
name="name",

0 commit comments

Comments
 (0)