cohere-haystack 10.1.0__tar.gz → 11.0.1__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 (39) hide show
  1. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/CHANGELOG.md +20 -0
  2. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/PKG-INFO +4 -3
  3. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/pyproject.toml +9 -3
  4. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/document_embedder.py +1 -3
  5. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/document_image_embedder.py +1 -2
  6. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/text_embedder.py +1 -3
  7. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/generators/cohere/chat/chat_generator.py +13 -21
  8. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/rankers/cohere/ranker.py +1 -2
  9. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_chat_generator.py +66 -21
  10. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/.gitignore +0 -0
  11. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/LICENSE.txt +0 -0
  12. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/README.md +0 -0
  13. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/examples/cohere_embedding.py +0 -0
  14. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/examples/cohere_generation.py +0 -0
  15. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/examples/cohere_ranker.py +0 -0
  16. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/pydoc/config_docusaurus.yml +0 -0
  17. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/__init__.py +0 -0
  18. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/embedding_types.py +0 -0
  19. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/cohere/utils.py +0 -0
  20. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/embedders/py.typed +0 -0
  21. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/generators/cohere/__init__.py +0 -0
  22. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/generators/cohere/chat/__init__.py +0 -0
  23. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/generators/py.typed +0 -0
  24. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/rankers/cohere/__init__.py +0 -0
  25. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/components/rankers/py.typed +0 -0
  26. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/utils/cohere/__init__.py +0 -0
  27. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/utils/cohere/api_base_url.py +0 -0
  28. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/src/haystack_integrations/utils/py.typed +0 -0
  29. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/__init__.py +0 -0
  30. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/conftest.py +0 -0
  31. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_api_base_url.py +0 -0
  32. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_chat_generator_async.py +0 -0
  33. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_chat_generator_chunks.py +0 -0
  34. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_document_embedder.py +0 -0
  35. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_document_image_embedder.py +0 -0
  36. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_files/apple.jpg +0 -0
  37. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_files/sample_pdf_1.pdf +0 -0
  38. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_ranker.py +0 -0
  39. {cohere_haystack-10.1.0 → cohere_haystack-11.0.1}/tests/test_text_embedder.py +0 -0
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/cohere-v11.0.0] - 2026-10-16
4
+
5
+ ### 🧪 Testing
6
+
7
+ - Test compatible integrations with Python 3.15; update pyproject (#4104)
8
+
9
+ ### 🧹 Chores
10
+
11
+ - Drop redundant deserialize_secrets_inplace calls in integrations requiring haystack-ai>=2.23 (#4058)
12
+ - Replace ToolInvoker with Agent in tests, examples and docstrings (#4108)
13
+ - [**breaking**] Drop Python 3.10 support (#4105)
14
+
15
+
16
+ ## [integrations/cohere-v10.1.0] - 2026-09-28
17
+
18
+ ### 🚀 Features
19
+
20
+ - *(cohere)* Add utility for API base URL validation (#4015)
21
+
22
+
3
23
  ## [integrations/cohere-v10.0.1] - 2026-09-10
4
24
 
5
25
  ### 🐛 Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cohere-haystack
3
- Version: 10.1.0
3
+ Version: 11.0.1
4
4
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere#readme
5
5
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
6
6
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere
@@ -10,17 +10,18 @@ License-File: LICENSE.txt
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Programming Language :: Python
13
- Classifier: Programming Language :: Python :: 3.10
14
13
  Classifier: Programming Language :: Python :: 3.11
15
14
  Classifier: Programming Language :: Python :: 3.12
16
15
  Classifier: Programming Language :: Python :: 3.13
17
16
  Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
- Requires-Python: >=3.10
20
+ Requires-Python: >=3.11
21
21
  Requires-Dist: cohere>=5.17.0
22
22
  Requires-Dist: haystack-ai>=3.0.0
23
23
  Requires-Dist: pydantic>=2.12.0
24
+ Requires-Dist: pydantic>=2.14.0; python_version >= '3.15'
24
25
  Description-Content-Type: text/markdown
25
26
 
26
27
  # cohere-haystack
@@ -7,7 +7,7 @@ name = "cohere-haystack"
7
7
  dynamic = ["version"]
8
8
  description = ''
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
10
+ requires-python = ">=3.11"
11
11
  license = "Apache-2.0"
12
12
  keywords = []
13
13
  authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
@@ -15,15 +15,21 @@ classifiers = [
15
15
  "License :: OSI Approved :: Apache Software License",
16
16
  "Development Status :: 4 - Beta",
17
17
  "Programming Language :: Python",
18
- "Programming Language :: Python :: 3.10",
19
18
  "Programming Language :: Python :: 3.11",
20
19
  "Programming Language :: Python :: 3.12",
21
20
  "Programming Language :: Python :: 3.13",
22
21
  "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
23
23
  "Programming Language :: Python :: Implementation :: CPython",
24
24
  "Programming Language :: Python :: Implementation :: PyPy",
25
25
  ]
26
- dependencies = ["haystack-ai>=3.0.0", "cohere>=5.17.0", "pydantic>=2.12.0"]
26
+ dependencies = [
27
+ "haystack-ai>=3.0.0",
28
+ "cohere>=5.17.0",
29
+ "pydantic>=2.12.0",
30
+ # pydantic 2.14.0 is the first release whose pydantic-core has Python 3.15 wheels.
31
+ "pydantic>=2.14.0; python_version >= '3.15'",
32
+ ]
27
33
 
28
34
  [project.urls]
29
35
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere#readme"
@@ -5,7 +5,7 @@ from dataclasses import replace
5
5
  from typing import Any, ClassVar
6
6
 
7
7
  from haystack import Document, component, default_from_dict, default_to_dict
8
- from haystack.utils import Secret, deserialize_secrets_inplace
8
+ from haystack.utils import Secret
9
9
 
10
10
  from cohere import AsyncClientV2, ClientV2
11
11
  from haystack_integrations.utils.cohere import validate_api_base_url
@@ -159,8 +159,6 @@ class CohereDocumentEmbedder:
159
159
  # drop legacy use_async_client parameter
160
160
  init_params.pop("use_async_client", None)
161
161
 
162
- deserialize_secrets_inplace(init_params, ["api_key"])
163
-
164
162
  # Convert embedding_type string to EmbeddingTypes enum value
165
163
  init_params["embedding_type"] = EmbeddingTypes.from_str(init_params["embedding_type"])
166
164
 
@@ -13,7 +13,7 @@ from haystack.components.converters.image.image_utils import (
13
13
  _PDFPageInfo,
14
14
  )
15
15
  from haystack.dataclasses import ByteStream
16
- from haystack.utils.auth import Secret, deserialize_secrets_inplace
16
+ from haystack.utils.auth import Secret
17
17
  from tqdm import tqdm
18
18
 
19
19
  from cohere import AsyncClientV2, ClientV2
@@ -188,7 +188,6 @@ class CohereDocumentImageEmbedder:
188
188
  Deserialized component.
189
189
  """
190
190
  init_params = data["init_parameters"]
191
- deserialize_secrets_inplace(init_params, keys=["api_key"])
192
191
  init_params["embedding_type"] = EmbeddingTypes.from_str(init_params["embedding_type"])
193
192
 
194
193
  return default_from_dict(cls, data)
@@ -4,7 +4,7 @@
4
4
  from typing import Any, ClassVar
5
5
 
6
6
  from haystack import component, default_from_dict, default_to_dict
7
- from haystack.utils import Secret, deserialize_secrets_inplace
7
+ from haystack.utils import Secret
8
8
 
9
9
  from cohere import AsyncClientV2, ClientV2
10
10
  from haystack_integrations.utils.cohere import validate_api_base_url
@@ -146,8 +146,6 @@ class CohereTextEmbedder:
146
146
  # drop legacy use_async_client parameter
147
147
  init_params.pop("use_async_client", None)
148
148
 
149
- deserialize_secrets_inplace(init_params, ["api_key"])
150
-
151
149
  # Convert embedding_type string to EmbeddingTypes enum value
152
150
  init_params["embedding_type"] = EmbeddingTypes.from_str(init_params["embedding_type"])
153
151
 
@@ -460,13 +460,11 @@ class CohereChatGenerator:
460
460
 
461
461
  ### Advanced example
462
462
 
463
- CohereChatGenerator can be integrated into pipelines and supports Haystack's tooling
464
- architecture, enabling tools to be invoked seamlessly across various generators.
463
+ CohereChatGenerator supports Haystack's tooling architecture, so it can drive tool calls in an `Agent`.
465
464
 
466
465
  ```python
467
- from haystack import Pipeline
466
+ from haystack.components.agents import Agent
468
467
  from haystack.dataclasses import ChatMessage
469
- from haystack.components.tools import ToolInvoker
470
468
  from haystack.tools import Tool
471
469
  from haystack_integrations.components.generators.cohere import CohereChatGenerator
472
470
 
@@ -490,20 +488,12 @@ class CohereChatGenerator:
490
488
  function=weather,
491
489
  )
492
490
 
493
- # Create and set up the pipeline
494
- pipeline = Pipeline()
495
- pipeline.add_component("generator", CohereChatGenerator(tools=[weather_tool]))
496
- pipeline.add_component("tool_invoker", ToolInvoker(tools=[weather_tool]))
497
- pipeline.connect("generator", "tool_invoker")
491
+ # The Agent calls the tool and feeds the result back to the model
492
+ agent = Agent(chat_generator=CohereChatGenerator(), tools=[weather_tool])
493
+ result = agent.run(messages=[ChatMessage.from_user("What's the weather like in Paris?")])
498
494
 
499
- # Run the pipeline with a weather query
500
- results = pipeline.run(
501
- data={"generator": {"messages": [ChatMessage.from_user("What's the weather like in Paris?")]}}
502
- )
503
-
504
- # The tool result will be available in the pipeline output
505
- print(results["tool_invoker"]["tool_messages"][0].tool_call_result.result)
506
- # Output: "The weather in Paris is sunny and 32°C"
495
+ print(result["last_message"].text)
496
+ # Output: "The weather in Paris is sunny and 32°C."
507
497
  ```
508
498
  """
509
499
 
@@ -674,7 +664,8 @@ class CohereChatGenerator:
674
664
  For more details on the parameters supported by the Cohere API, refer to the
675
665
  Cohere [documentation](https://docs.cohere.com/reference/chat).
676
666
  :param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
677
- If set, it will override the `tools` parameter set during component initialization.
667
+ If set, it will override the `tools` parameter set during component initialization. Pass an empty
668
+ list to disable tools for this call.
678
669
  :param streaming_callback: A callback function that is called when a new token is received from the stream.
679
670
  The callback function accepts StreamingChunk as an argument.
680
671
 
@@ -689,7 +680,7 @@ class CohereChatGenerator:
689
680
  generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
690
681
 
691
682
  # Handle tools
692
- tools = tools or self.tools
683
+ tools = tools if tools is not None else self.tools
693
684
  flattened_tools = flatten_tools_or_toolsets(tools)
694
685
  if flattened_tools:
695
686
  _check_duplicate_tool_names(flattened_tools)
@@ -745,7 +736,8 @@ class CohereChatGenerator:
745
736
  For more details on the parameters supported by the Cohere API, refer to the
746
737
  Cohere [documentation](https://docs.cohere.com/reference/chat).
747
738
  :param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
748
- If set, it will override the `tools` parameter set during component initialization.
739
+ If set, it will override the `tools` parameter set during component initialization. Pass an empty
740
+ list to disable tools for this call.
749
741
  :param streaming_callback: A callback function that is called when a new token is received from the stream.
750
742
  :returns: A dictionary with the following keys:
751
743
  - `replies`: a list of `ChatMessage` instances representing the generated responses.
@@ -758,7 +750,7 @@ class CohereChatGenerator:
758
750
  generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
759
751
 
760
752
  # Handle tools
761
- tools = tools or self.tools
753
+ tools = tools if tools is not None else self.tools
762
754
  flattened_tools = flatten_tools_or_toolsets(tools)
763
755
  if flattened_tools:
764
756
  _check_duplicate_tool_names(flattened_tools)
@@ -2,7 +2,7 @@ from dataclasses import replace
2
2
  from typing import Any
3
3
 
4
4
  from haystack import Document, component, default_from_dict, default_to_dict, logging
5
- from haystack.utils import Secret, deserialize_secrets_inplace
5
+ from haystack.utils import Secret
6
6
 
7
7
  from cohere import AsyncClientV2, ClientV2
8
8
  from haystack_integrations.utils.cohere import validate_api_base_url
@@ -123,7 +123,6 @@ class CohereRanker:
123
123
  # was serialized with the old version
124
124
  data["init_parameters"].pop("max_chunks_per_doc", None)
125
125
 
126
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
127
126
  return default_from_dict(cls, data)
128
127
 
129
128
  def _prepare_cohere_input_docs(self, documents: list[Document], top_k: int | None = None) -> tuple[list[str], int]:
@@ -4,12 +4,8 @@ from unittest.mock import AsyncMock, MagicMock, patch
4
4
  import pytest
5
5
  from cohere.core import ApiError
6
6
  from haystack import Pipeline
7
+ from haystack.components.agents import Agent
7
8
  from haystack.components.generators.utils import print_streaming_chunk
8
-
9
- try:
10
- from haystack.components.tools import ToolInvoker
11
- except ImportError: # ToolInvoker was removed in Haystack 3.0
12
- ToolInvoker = None
13
9
  from haystack.dataclasses import ChatMessage, ChatRole, ImageContent, ToolCall
14
10
  from haystack.dataclasses.streaming_chunk import StreamingChunk
15
11
  from haystack.tools import Tool, Toolset
@@ -619,6 +615,65 @@ class TestRun:
619
615
  assert kwargs["max_tokens"] == 100
620
616
  assert kwargs["temperature"] == 0.9
621
617
 
618
+ @patch("haystack_integrations.components.generators.cohere.chat.chat_generator.ClientV2")
619
+ def test_run_with_empty_tools_override(self, mock_client_cls):
620
+ weather_tool = Tool(
621
+ name="weather",
622
+ description="Get the weather in a city",
623
+ parameters={"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
624
+ function=weather,
625
+ )
626
+ generator = CohereChatGenerator(api_key=Secret.from_token("test-api-key"), tools=[weather_tool])
627
+
628
+ mock_response = MagicMock()
629
+ mock_response.message.content = [MagicMock()]
630
+ mock_response.message.content[0].text = "Paris"
631
+ mock_response.message.content[0].type = "text"
632
+ mock_response.message.tool_calls = None
633
+ mock_response.finish_reason = "COMPLETE"
634
+ mock_response.usage = None
635
+
636
+ client = mock_client_cls.return_value
637
+ client.chat.return_value = mock_response
638
+
639
+ generator.run([ChatMessage.from_user("Hello")])
640
+ _, kwargs = client.chat.call_args
641
+ assert len(kwargs["tools"]) == 1
642
+
643
+ generator.run([ChatMessage.from_user("Hello")], tools=[])
644
+ _, kwargs = client.chat.call_args
645
+ assert "tools" not in kwargs
646
+
647
+ @pytest.mark.asyncio
648
+ @patch("haystack_integrations.components.generators.cohere.chat.chat_generator.AsyncClientV2")
649
+ async def test_run_async_with_empty_tools_override(self, mock_client_cls):
650
+ weather_tool = Tool(
651
+ name="weather",
652
+ description="Get the weather in a city",
653
+ parameters={"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
654
+ function=weather,
655
+ )
656
+ generator = CohereChatGenerator(api_key=Secret.from_token("test-api-key"), tools=[weather_tool])
657
+
658
+ mock_response = MagicMock()
659
+ mock_response.message.content = [MagicMock()]
660
+ mock_response.message.content[0].text = "Paris"
661
+ mock_response.message.content[0].type = "text"
662
+ mock_response.message.tool_calls = None
663
+ mock_response.finish_reason = "COMPLETE"
664
+ mock_response.usage = None
665
+
666
+ client = mock_client_cls.return_value
667
+ client.chat = AsyncMock(return_value=mock_response)
668
+
669
+ await generator.run_async([ChatMessage.from_user("Hello")])
670
+ _, kwargs = client.chat.call_args
671
+ assert len(kwargs["tools"]) == 1
672
+
673
+ await generator.run_async([ChatMessage.from_user("Hello")], tools=[])
674
+ _, kwargs = client.chat.call_args
675
+ assert "tools" not in kwargs
676
+
622
677
 
623
678
  @pytest.mark.skipif(
624
679
  not os.environ.get("COHERE_API_KEY", None) and not os.environ.get("CO_API_KEY", None),
@@ -810,10 +865,9 @@ class TestCohereChatGeneratorInference:
810
865
  assert len(final_message.text) > 0
811
866
  assert "paris" in final_message.text.lower()
812
867
 
813
- @pytest.mark.skipif(ToolInvoker is None, reason="ToolInvoker is not available in the installed haystack-ai version")
814
- def test_pipeline_with_cohere_chat_generator(self):
868
+ def test_agent_with_cohere_chat_generator(self):
815
869
  """
816
- Test that the CohereChatGenerator component can be used in a pipeline
870
+ Test that the CohereChatGenerator component can drive tool calls in an Agent
817
871
  """
818
872
  weather_tool = Tool(
819
873
  name="weather",
@@ -831,20 +885,11 @@ class TestCohereChatGeneratorInference:
831
885
  function=weather,
832
886
  )
833
887
 
834
- pipeline = Pipeline()
835
- pipeline.add_component("generator", CohereChatGenerator(model="command-r7b-12-2024", tools=[weather_tool]))
836
- pipeline.add_component("tool_invoker", ToolInvoker(tools=[weather_tool]))
837
-
838
- pipeline.connect("generator", "tool_invoker")
888
+ agent = Agent(chat_generator=CohereChatGenerator(model="command-r7b-12-2024"), tools=[weather_tool])
889
+ result = agent.run(messages=[ChatMessage.from_user("What's the weather like in Paris?")])
839
890
 
840
- results = pipeline.run(
841
- data={"generator": {"messages": [ChatMessage.from_user("What's the weather like in Paris?")]}}
842
- )
843
-
844
- assert (
845
- "The weather in Paris is sunny and 32°C"
846
- == results["tool_invoker"]["tool_messages"][0].tool_call_result.result
847
- )
891
+ tool_results = [msg.tool_call_result.result for msg in result["messages"] if msg.tool_call_result]
892
+ assert "The weather in Paris is sunny and 32°C" in tool_results
848
893
 
849
894
  def test_live_run_multimodal(self):
850
895
  generator = CohereChatGenerator(