cohere-haystack 9.1.0__tar.gz → 9.2.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.
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/CHANGELOG.md +7 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/PKG-INFO +3 -2
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/pyproject.toml +1 -1
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/generators/cohere/chat/chat_generator.py +7 -3
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/generators/cohere/generator.py +7 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_chat_generator.py +54 -1
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/.gitignore +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/LICENSE.txt +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/README.md +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/examples/cohere_embedding.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/examples/cohere_generation.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/examples/cohere_ranker.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/pydoc/config_docusaurus.yml +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/__init__.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/document_embedder.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/document_image_embedder.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/embedding_types.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/text_embedder.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/cohere/utils.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/generators/cohere/__init__.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/generators/cohere/chat/__init__.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/rankers/cohere/__init__.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/rankers/cohere/ranker.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/src/haystack_integrations/components/rankers/py.typed +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/__init__.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/conftest.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_chat_generator_async.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_chat_generator_chunks.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_document_embedder.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_document_image_embedder.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_files/apple.jpg +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_files/sample_pdf_1.pdf +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_generator.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_ranker.py +0 -0
- {cohere_haystack-9.1.0 → cohere_haystack-9.2.0}/tests/test_text_embedder.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cohere-haystack
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.2.0
|
|
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
|
|
@@ -19,7 +19,8 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
|
19
19
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
20
|
Requires-Python: >=3.10
|
|
21
21
|
Requires-Dist: cohere>=5.17.0
|
|
22
|
-
Requires-Dist: haystack-ai>=2.
|
|
22
|
+
Requires-Dist: haystack-ai>=2.30.0
|
|
23
|
+
Requires-Dist: pydantic>=2.12.0
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
24
25
|
|
|
25
26
|
# cohere-haystack
|
|
@@ -23,7 +23,7 @@ classifiers = [
|
|
|
23
23
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
24
24
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
25
25
|
]
|
|
26
|
-
dependencies = ["haystack-ai>=2.
|
|
26
|
+
dependencies = ["haystack-ai>=2.30.0", "cohere>=5.17.0", "pydantic>=2.12.0"]
|
|
27
27
|
|
|
28
28
|
[project.urls]
|
|
29
29
|
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere#readme"
|
|
@@ -3,7 +3,7 @@ from collections.abc import AsyncIterator, Iterator
|
|
|
3
3
|
from typing import Any, ClassVar, Literal, get_args
|
|
4
4
|
|
|
5
5
|
from haystack import component, default_from_dict, default_to_dict, logging
|
|
6
|
-
from haystack.components.generators.utils import _convert_streaming_chunks_to_chat_message
|
|
6
|
+
from haystack.components.generators.utils import _convert_streaming_chunks_to_chat_message, _normalize_messages
|
|
7
7
|
from haystack.dataclasses import ChatMessage, ComponentInfo, ImageContent, TextContent, ToolCall
|
|
8
8
|
from haystack.dataclasses.streaming_chunk import (
|
|
9
9
|
AsyncStreamingCallbackT,
|
|
@@ -616,7 +616,7 @@ class CohereChatGenerator:
|
|
|
616
616
|
@component.output_types(replies=list[ChatMessage])
|
|
617
617
|
def run(
|
|
618
618
|
self,
|
|
619
|
-
messages: list[ChatMessage],
|
|
619
|
+
messages: list[ChatMessage] | str,
|
|
620
620
|
generation_kwargs: dict[str, Any] | None = None,
|
|
621
621
|
tools: ToolsType | None = None,
|
|
622
622
|
streaming_callback: StreamingCallbackT | None = None,
|
|
@@ -625,6 +625,7 @@ class CohereChatGenerator:
|
|
|
625
625
|
Invoke the chat endpoint based on the provided messages and generation parameters.
|
|
626
626
|
|
|
627
627
|
:param messages: list of `ChatMessage` instances representing the input messages.
|
|
628
|
+
If a string is provided, it is converted to a list containing a ChatMessage with user role.
|
|
628
629
|
:param generation_kwargs: additional keyword arguments for chat generation. These parameters will
|
|
629
630
|
potentially override the parameters passed in the __init__ method.
|
|
630
631
|
For more details on the parameters supported by the Cohere API, refer to the
|
|
@@ -637,6 +638,7 @@ class CohereChatGenerator:
|
|
|
637
638
|
:returns: A dictionary with the following keys:
|
|
638
639
|
- `replies`: a list of `ChatMessage` instances representing the generated responses.
|
|
639
640
|
"""
|
|
641
|
+
messages = _normalize_messages(messages)
|
|
640
642
|
|
|
641
643
|
# update generation kwargs by merging with the generation kwargs passed to the run method
|
|
642
644
|
generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
|
|
@@ -682,7 +684,7 @@ class CohereChatGenerator:
|
|
|
682
684
|
@component.output_types(replies=list[ChatMessage])
|
|
683
685
|
async def run_async(
|
|
684
686
|
self,
|
|
685
|
-
messages: list[ChatMessage],
|
|
687
|
+
messages: list[ChatMessage] | str,
|
|
686
688
|
generation_kwargs: dict[str, Any] | None = None,
|
|
687
689
|
tools: ToolsType | None = None,
|
|
688
690
|
streaming_callback: StreamingCallbackT | None = None,
|
|
@@ -691,6 +693,7 @@ class CohereChatGenerator:
|
|
|
691
693
|
Asynchronously invoke the chat endpoint based on the provided messages and generation parameters.
|
|
692
694
|
|
|
693
695
|
:param messages: list of `ChatMessage` instances representing the input messages.
|
|
696
|
+
If a string is provided, it is converted to a list containing a ChatMessage with user role.
|
|
694
697
|
:param generation_kwargs: additional keyword arguments for chat generation. These parameters will
|
|
695
698
|
potentially override the parameters passed in the __init__ method.
|
|
696
699
|
For more details on the parameters supported by the Cohere API, refer to the
|
|
@@ -701,6 +704,7 @@ class CohereChatGenerator:
|
|
|
701
704
|
:returns: A dictionary with the following keys:
|
|
702
705
|
- `replies`: a list of `ChatMessage` instances representing the generated responses.
|
|
703
706
|
"""
|
|
707
|
+
messages = _normalize_messages(messages)
|
|
704
708
|
|
|
705
709
|
# update generation kwargs by merging with the generation kwargs passed to the run method
|
|
706
710
|
generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import warnings
|
|
4
5
|
from collections.abc import Callable
|
|
5
6
|
from typing import Any, ClassVar
|
|
6
7
|
|
|
@@ -70,6 +71,12 @@ class CohereGenerator(CohereChatGenerator):
|
|
|
70
71
|
You can check them in model's documentation.
|
|
71
72
|
"""
|
|
72
73
|
|
|
74
|
+
warnings.warn(
|
|
75
|
+
"The `CohereGenerator` component is deprecated and will be removed in a future version. "
|
|
76
|
+
"Use `CohereChatGenerator` instead, which now also supports string inputs.",
|
|
77
|
+
FutureWarning,
|
|
78
|
+
stacklevel=2,
|
|
79
|
+
)
|
|
73
80
|
# from_dict deserialization, where `generation_kwargs` is in **kwargs
|
|
74
81
|
if "generation_kwargs" in kwargs:
|
|
75
82
|
generation_kwargs = kwargs.pop("generation_kwargs")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from unittest.mock import MagicMock
|
|
2
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
from cohere.core import ApiError
|
|
@@ -498,6 +498,59 @@ class TestCohereChatGenerator:
|
|
|
498
498
|
assert multimodal_msg["content"][0]["type"] == "text"
|
|
499
499
|
assert multimodal_msg["content"][1]["type"] == "image_url"
|
|
500
500
|
|
|
501
|
+
def test_run_with_string_input(self):
|
|
502
|
+
"""Test that a string input is converted to a user ChatMessage before sending to the API."""
|
|
503
|
+
generator = CohereChatGenerator(api_key=Secret.from_token("test-api-key"))
|
|
504
|
+
|
|
505
|
+
mock_response = MagicMock()
|
|
506
|
+
mock_response.message.content = [MagicMock()]
|
|
507
|
+
mock_response.message.content[0].text = "Paris"
|
|
508
|
+
mock_response.message.content[0].type = "text"
|
|
509
|
+
mock_response.message.tool_calls = None
|
|
510
|
+
mock_response.finish_reason = "COMPLETE"
|
|
511
|
+
mock_response.usage = None
|
|
512
|
+
|
|
513
|
+
generator.client.chat = MagicMock(return_value=mock_response)
|
|
514
|
+
|
|
515
|
+
result = generator.run("What's the capital of France?")
|
|
516
|
+
|
|
517
|
+
generator.client.chat.assert_called_once()
|
|
518
|
+
call_args = generator.client.chat.call_args
|
|
519
|
+
sent_messages = call_args[1]["messages"]
|
|
520
|
+
|
|
521
|
+
assert len(sent_messages) == 1
|
|
522
|
+
assert sent_messages[0]["role"] == "user"
|
|
523
|
+
assert isinstance(result["replies"], list)
|
|
524
|
+
assert len(result["replies"]) == 1
|
|
525
|
+
assert isinstance(result["replies"][0], ChatMessage)
|
|
526
|
+
|
|
527
|
+
@pytest.mark.asyncio
|
|
528
|
+
async def test_run_async_with_string_input(self):
|
|
529
|
+
"""Test that a string input is converted to a user ChatMessage before sending to the async API."""
|
|
530
|
+
generator = CohereChatGenerator(api_key=Secret.from_token("test-api-key"))
|
|
531
|
+
|
|
532
|
+
mock_response = MagicMock()
|
|
533
|
+
mock_response.message.content = [MagicMock()]
|
|
534
|
+
mock_response.message.content[0].text = "Paris"
|
|
535
|
+
mock_response.message.content[0].type = "text"
|
|
536
|
+
mock_response.message.tool_calls = None
|
|
537
|
+
mock_response.finish_reason = "COMPLETE"
|
|
538
|
+
mock_response.usage = None
|
|
539
|
+
|
|
540
|
+
generator.async_client.chat = AsyncMock(return_value=mock_response)
|
|
541
|
+
|
|
542
|
+
result = await generator.run_async("What's the capital of France?")
|
|
543
|
+
|
|
544
|
+
generator.async_client.chat.assert_called_once()
|
|
545
|
+
call_args = generator.async_client.chat.call_args
|
|
546
|
+
sent_messages = call_args[1]["messages"]
|
|
547
|
+
|
|
548
|
+
assert len(sent_messages) == 1
|
|
549
|
+
assert sent_messages[0]["role"] == "user"
|
|
550
|
+
assert isinstance(result["replies"], list)
|
|
551
|
+
assert len(result["replies"]) == 1
|
|
552
|
+
assert isinstance(result["replies"][0], ChatMessage)
|
|
553
|
+
|
|
501
554
|
|
|
502
555
|
@pytest.mark.skipif(
|
|
503
556
|
not os.environ.get("COHERE_API_KEY", None) and not os.environ.get("CO_API_KEY", None),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|