ollama-haystack 2.3.0__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/CHANGELOG.md +7 -0
  2. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/PKG-INFO +3 -2
  3. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/pyproject.toml +2 -6
  4. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/generators/ollama/chat/chat_generator.py +55 -1
  5. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/tests/test_chat_generator.py +31 -4
  6. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/.gitignore +0 -0
  7. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/LICENSE.txt +0 -0
  8. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/README.md +0 -0
  9. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/examples/chat_generator_example.py +0 -0
  10. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/examples/embedders_example.py +0 -0
  11. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/examples/generator_example.py +0 -0
  12. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/pydoc/config.yml +0 -0
  13. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/embedders/ollama/__init__.py +0 -0
  14. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/embedders/ollama/document_embedder.py +0 -0
  15. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/embedders/ollama/text_embedder.py +0 -0
  16. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/generators/ollama/__init__.py +0 -0
  17. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/generators/ollama/chat/__init__.py +0 -0
  18. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/src/haystack_integrations/components/generators/ollama/generator.py +0 -0
  19. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/tests/__init__.py +0 -0
  20. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/tests/test_document_embedder.py +0 -0
  21. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/tests/test_generator.py +0 -0
  22. {ollama_haystack-2.3.0 → ollama_haystack-2.4.0}/tests/test_text_embedder.py +0 -0
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/ollama-v2.3.0] - 2025-01-29
4
+
5
+ ### 🚀 Features
6
+
7
+ - Add `response_format` param to `OllamaChatGenerator` (#1326)
8
+
9
+
3
10
  ## [integrations/ollama-v2.2.0] - 2025-01-16
4
11
 
5
12
  ### 🚀 Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ollama-haystack
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: An integration between the Ollama LLM framework and Haystack
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/ollama#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -15,9 +15,10 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
18
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
20
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
- Requires-Python: >=3.8
21
+ Requires-Python: >=3.9
21
22
  Requires-Dist: haystack-ai
22
23
  Requires-Dist: ollama>=0.4.0
23
24
  Requires-Dist: pydantic
@@ -7,7 +7,7 @@ name = "ollama-haystack"
7
7
  dynamic = ["version"]
8
8
  description = 'An integration between the Ollama LLM framework and Haystack'
9
9
  readme = "README.md"
10
- requires-python = ">=3.8"
10
+ requires-python = ">=3.9"
11
11
  license = "Apache-2.0"
12
12
  keywords = []
13
13
  authors = [
@@ -23,6 +23,7 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.10",
24
24
  "Programming Language :: Python :: 3.11",
25
25
  "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
26
27
  "Programming Language :: Python :: Implementation :: CPython",
27
28
  "Programming Language :: Python :: Implementation :: PyPy",
28
29
  ]
@@ -51,7 +52,6 @@ dependencies = [
51
52
  "pytest",
52
53
  "pytest-rerunfailures",
53
54
  "haystack-pydoc-tools",
54
- "jsonschema", # needed for Tool
55
55
  ]
56
56
  [tool.hatch.envs.default.scripts]
57
57
  test = "pytest {args:tests}"
@@ -62,10 +62,6 @@ cov = ["test-cov", "cov-report"]
62
62
  cov-retry = ["test-cov-retry", "cov-report"]
63
63
  docs = ["pydoc-markdown pydoc/config.yml"]
64
64
 
65
- [[tool.hatch.envs.all.matrix]]
66
- python = ["3.9", "3.10", "3.11", "3.12"]
67
-
68
-
69
65
  [tool.hatch.envs.lint]
70
66
  installer = "uv"
71
67
  detached = true
@@ -41,6 +41,60 @@ def _convert_chatmessage_to_ollama_format(message: ChatMessage) -> Dict[str, Any
41
41
  return ollama_msg
42
42
 
43
43
 
44
+ def _convert_ollama_meta_to_openai_format(intput_response_dict: Dict) -> Dict:
45
+ """
46
+ Internal function to convert Ollama metadata to OpenAI format.
47
+
48
+ All fields that are not part of the OpenAI metadata are left unchanged in the returned dict.
49
+
50
+ Example Ollama metadata:
51
+ {
52
+ 'model': 'phi4:14b-q4_K_M',
53
+ 'created_at': '2025-03-09T18:38:33.004185821Z',
54
+ 'done': True,
55
+ 'done_reason': 'stop',
56
+ 'total_duration': 86627206961,
57
+ 'load_duration': 23585622554,
58
+ 'prompt_eval_count': 26,
59
+ 'prompt_eval_duration': 3426000000,
60
+ 'eval_count': 298,
61
+ 'eval_duration': 4799921000
62
+ }
63
+
64
+ Example OpenAI metadata:
65
+ {
66
+ 'model': 'phi4:14b-q4_K_M',
67
+ 'finish_reason': 'stop',
68
+ 'usage': {
69
+ 'completion_tokens': 298,
70
+ 'prompt_tokens': 26,
71
+ 'total_tokens': 324,
72
+ }
73
+ 'completion_start_time': '2025-03-09T18:38:33.004185821Z',
74
+ 'done': True,
75
+ 'total_duration': 86627206961,
76
+ 'load_duration': 23585622554,
77
+ 'prompt_eval_duration': 3426000000,
78
+ 'eval_duration': 4799921000,
79
+ }
80
+ """
81
+ meta = {key: value for key, value in intput_response_dict.items() if key != "message"}
82
+
83
+ if "done_reason" in meta:
84
+ meta["finish_reason"] = meta.pop("done_reason")
85
+ if "created_at" in meta:
86
+ meta["completion_start_time"] = meta.pop("created_at")
87
+ if "eval_count" in meta and "prompt_eval_count" in meta:
88
+ eval_count = meta.pop("eval_count")
89
+ prompt_eval_count = meta.pop("prompt_eval_count")
90
+ meta["usage"] = {
91
+ "completion_tokens": eval_count,
92
+ "prompt_tokens": prompt_eval_count,
93
+ "total_tokens": eval_count + prompt_eval_count,
94
+ }
95
+ return meta
96
+
97
+
44
98
  def _convert_ollama_response_to_chatmessage(ollama_response: "ChatResponse") -> ChatMessage:
45
99
  """
46
100
  Converts the non-streaming response from the Ollama API to a ChatMessage with assistant role.
@@ -60,7 +114,7 @@ def _convert_ollama_response_to_chatmessage(ollama_response: "ChatResponse") ->
60
114
 
61
115
  message = ChatMessage.from_assistant(text=text, tool_calls=tool_calls)
62
116
 
63
- message.meta.update({key: value for key, value in response_dict.items() if key != "message"})
117
+ message._meta = _convert_ollama_meta_to_openai_format(response_dict)
64
118
  return message
65
119
 
66
120
 
@@ -97,13 +97,12 @@ def test_convert_chatmessage_to_ollama_invalid():
97
97
 
98
98
 
99
99
  def test_convert_ollama_response_to_chatmessage():
100
- model = "some_model"
101
-
102
100
  ollama_response = ChatResponse(
103
- model=model,
101
+ model="some_model",
104
102
  created_at="2023-12-12T14:13:43.416799Z",
105
103
  message={"role": "assistant", "content": "Hello! How are you today?"},
106
104
  done=True,
105
+ done_reason="stop",
107
106
  total_duration=5191566416,
108
107
  load_duration=2154458,
109
108
  prompt_eval_count=26,
@@ -117,6 +116,22 @@ def test_convert_ollama_response_to_chatmessage():
117
116
  assert observed.role == "assistant"
118
117
  assert observed.text == "Hello! How are you today?"
119
118
 
119
+ assert observed.meta == {
120
+ "finish_reason": "stop",
121
+ "usage": {
122
+ "completion_tokens": 298,
123
+ "prompt_tokens": 26,
124
+ "total_tokens": 324,
125
+ },
126
+ "completion_start_time": "2023-12-12T14:13:43.416799Z",
127
+ "load_duration": 2154458,
128
+ "total_duration": 5191566416,
129
+ "eval_duration": 4799921000,
130
+ "prompt_eval_duration": 383809000,
131
+ "done": True,
132
+ "model": "some_model",
133
+ }
134
+
120
135
 
121
136
  def test_convert_ollama_response_to_chatmessage_with_tools():
122
137
  model = "some_model"
@@ -215,7 +230,8 @@ class TestOllamaChatGenerator:
215
230
  response_format={"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "number"}}},
216
231
  )
217
232
  data = component.to_dict()
218
- assert data == {
233
+
234
+ expected_dict = {
219
235
  "type": "haystack_integrations.components.generators.ollama.chat.chat_generator.OllamaChatGenerator",
220
236
  "init_parameters": {
221
237
  "timeout": 120,
@@ -249,6 +265,17 @@ class TestOllamaChatGenerator:
249
265
  },
250
266
  }
251
267
 
268
+ # add outputs_to_string, inputs_from_state and outputs_to_state tool parameters for compatibility with
269
+ # haystack-ai>=2.12.0
270
+ if hasattr(tool, "outputs_to_string"):
271
+ expected_dict["init_parameters"]["tools"][0]["data"]["outputs_to_string"] = tool.outputs_to_string
272
+ if hasattr(tool, "inputs_from_state"):
273
+ expected_dict["init_parameters"]["tools"][0]["data"]["inputs_from_state"] = tool.inputs_from_state
274
+ if hasattr(tool, "outputs_to_state"):
275
+ expected_dict["init_parameters"]["tools"][0]["data"]["outputs_to_state"] = tool.outputs_to_state
276
+
277
+ assert data == expected_dict
278
+
252
279
  def test_from_dict(self):
253
280
  tool = Tool(
254
281
  name="name",