Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cohere namespace change #247

Merged
merged 9 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions integrations/cohere/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/m
Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues"
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere"

[tool.hatch.build.targets.wheel]
packages = ["src/haystack_integrations"]

[tool.hatch.version]
source = "vcs"
tag-pattern = 'integrations\/cohere-v(?P<version>.*)'
Expand Down Expand Up @@ -70,7 +73,7 @@ dependencies = [
"ruff>=0.0.243",
]
[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:src/cohere_haystack tests}"
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
Expand Down Expand Up @@ -133,26 +136,23 @@ unfixable = [
]

[tool.ruff.isort]
known-first-party = ["cohere_haystack"]
known-first-party = ["src"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
ban-relative-imports = "parents"

[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]

[tool.coverage.run]
source_pkgs = ["cohere_haystack", "tests"]
source_pkgs = ["src", "tests"]
branch = true
parallel = true
omit = [
"src/cohere_haystack/__about__.py",
]

[tool.coverage.paths]
cohere_haystack = ["src/cohere_haystack", "*/cohere-haystack/src/cohere_haystack"]
tests = ["tests", "*/cohere-haystack/tests"]
cohere_haystack = ["src/haystack_integrations", "*/cohere/src/haystack_integrations"]
tests = ["tests", "*/cohere/tests"]

[tool.coverage.report]
exclude_lines = [
Expand All @@ -165,6 +165,7 @@ exclude_lines = [
module = [
"cohere.*",
"haystack.*",
"haystack_integrations.*",
"pytest.*",
"numpy.*",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
from .document_embedder import CohereDocumentEmbedder
from .text_embedder import CohereTextEmbedder

__all__ = ["CohereDocumentEmbedder", "CohereTextEmbedder"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import os
from typing import Any, Dict, List, Optional

from cohere import COHERE_API_URL, AsyncClient, Client
from haystack import Document, component, default_to_dict
from haystack_integrations.components.embedders.cohere.utils import get_async_response, get_response

from cohere_haystack.embedders.utils import get_async_response, get_response
from cohere import COHERE_API_URL, AsyncClient, Client


@component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import os
from typing import Any, Dict, List, Optional

from cohere import COHERE_API_URL, AsyncClient, Client
from haystack import component, default_to_dict
from haystack_integrations.components.embedders.cohere.utils import get_async_response, get_response

from cohere_haystack.embedders.utils import get_async_response, get_response
from cohere import COHERE_API_URL, AsyncClient, Client


@component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Dict, List, Tuple

from cohere import AsyncClient, Client, CohereError
from tqdm import tqdm

from cohere import AsyncClient, Client, CohereError


async def get_async_response(cohere_async_client: AsyncClient, texts: List[str], model_name, input_type, truncate):
all_embeddings: List[List[float]] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
from .generator import CohereGenerator

__all__ = ["CohereGenerator"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
from .chat_generator import CohereChatGenerator

__all__ = ["CohereChatGenerator"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import sys
from typing import Any, Callable, Dict, List, Optional, cast

from haystack import DeserializationError, component, default_from_dict, default_to_dict

from cohere import COHERE_API_URL, Client
from cohere.responses import Generations
from haystack import DeserializationError, component, default_from_dict, default_to_dict

logger = logging.getLogger(__name__)

Expand Down
13 changes: 6 additions & 7 deletions integrations/cohere/tests/test_cohere_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import pytest
from haystack.components.generators.utils import default_streaming_callback
from haystack.dataclasses import ChatMessage, ChatRole, StreamingChunk

from cohere_haystack.chat.chat_generator import CohereChatGenerator
from haystack_integrations.components.generators.cohere.chat import CohereChatGenerator

pytestmark = pytest.mark.chat_generators

Expand Down Expand Up @@ -88,7 +87,7 @@ def test_to_dict_default(self):
component = CohereChatGenerator(api_key="test-api-key")
data = component.to_dict()
assert data == {
"type": "cohere_haystack.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command",
"streaming_callback": None,
Expand All @@ -108,7 +107,7 @@ def test_to_dict_with_parameters(self):
)
data = component.to_dict()
assert data == {
"type": "cohere_haystack.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command-nightly",
"streaming_callback": "haystack.components.generators.utils.default_streaming_callback",
Expand All @@ -128,7 +127,7 @@ def test_to_dict_with_lambda_streaming_callback(self):
)
data = component.to_dict()
assert data == {
"type": "cohere_haystack.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command",
"api_base_url": "test-base-url",
Expand All @@ -141,7 +140,7 @@ def test_to_dict_with_lambda_streaming_callback(self):
def test_from_dict(self, monkeypatch):
monkeypatch.setenv("COHERE_API_KEY", "fake-api-key")
data = {
"type": "cohere_haystack.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command",
"api_base_url": "test-base-url",
Expand All @@ -159,7 +158,7 @@ def test_from_dict(self, monkeypatch):
def test_from_dict_fail_wo_env_var(self, monkeypatch):
monkeypatch.delenv("COHERE_API_KEY", raising=False)
data = {
"type": "cohere_haystack.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command",
"api_base_url": "test-base-url",
Expand Down
11 changes: 5 additions & 6 deletions integrations/cohere/tests/test_cohere_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import pytest
from cohere import COHERE_API_URL

from cohere_haystack.generator import CohereGenerator
from haystack_integrations.components.generators.cohere import CohereGenerator

pytestmark = pytest.mark.generators

Expand Down Expand Up @@ -48,7 +47,7 @@ def test_to_dict_default(self):
component = CohereGenerator(api_key="test-api-key")
data = component.to_dict()
assert data == {
"type": "cohere_haystack.generator.CohereGenerator",
"type": "haystack_integrations.components.generators.cohere.generator.CohereGenerator",
"init_parameters": {
"model": "command",
"streaming_callback": None,
Expand All @@ -67,7 +66,7 @@ def test_to_dict_with_parameters(self):
)
data = component.to_dict()
assert data == {
"type": "cohere_haystack.generator.CohereGenerator",
"type": "haystack_integrations.components.generators.cohere.generator.CohereGenerator",
"init_parameters": {
"model": "command-light",
"max_tokens": 10,
Expand All @@ -88,7 +87,7 @@ def test_to_dict_with_lambda_streaming_callback(self):
)
data = component.to_dict()
assert data == {
"type": "cohere_haystack.generator.CohereGenerator",
"type": "haystack_integrations.components.generators.cohere.generator.CohereGenerator",
"init_parameters": {
"model": "command",
"streaming_callback": "tests.test_cohere_generators.<lambda>",
Expand All @@ -101,7 +100,7 @@ def test_to_dict_with_lambda_streaming_callback(self):
def test_from_dict(self, monkeypatch):
monkeypatch.setenv("COHERE_API_KEY", "test-key")
data = {
"type": "cohere_haystack.generator.CohereGenerator",
"type": "haystack_integrations.components.generators.cohere.generator.CohereGenerator",
"init_parameters": {
"model": "command",
"max_tokens": 10,
Expand Down
7 changes: 3 additions & 4 deletions integrations/cohere/tests/test_document_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import pytest
from cohere import COHERE_API_URL
from haystack import Document

from cohere_haystack.embedders.document_embedder import CohereDocumentEmbedder
from haystack_integrations.components.embedders.cohere import CohereDocumentEmbedder

pytestmark = pytest.mark.embedders

Expand Down Expand Up @@ -60,7 +59,7 @@ def test_to_dict(self):
embedder_component = CohereDocumentEmbedder(api_key="test-api-key")
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "cohere_haystack.embedders.document_embedder.CohereDocumentEmbedder",
"type": "haystack_integrations.components.embedders.cohere.document_embedder.CohereDocumentEmbedder",
"init_parameters": {
"model": "embed-english-v2.0",
"input_type": "search_document",
Expand Down Expand Up @@ -93,7 +92,7 @@ def test_to_dict_with_custom_init_parameters(self):
)
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "cohere_haystack.embedders.document_embedder.CohereDocumentEmbedder",
"type": "haystack_integrations.components.embedders.cohere.document_embedder.CohereDocumentEmbedder",
"init_parameters": {
"model": "embed-multilingual-v2.0",
"input_type": "search_query",
Expand Down
7 changes: 3 additions & 4 deletions integrations/cohere/tests/test_text_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import pytest
from cohere import COHERE_API_URL

from cohere_haystack.embedders.text_embedder import CohereTextEmbedder
from haystack_integrations.components.embedders.cohere import CohereTextEmbedder

pytestmark = pytest.mark.embedders

Expand Down Expand Up @@ -57,7 +56,7 @@ def test_to_dict(self):
embedder_component = CohereTextEmbedder(api_key="test-api-key")
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "cohere_haystack.embedders.text_embedder.CohereTextEmbedder",
"type": "haystack_integrations.components.embedders.cohere.text_embedder.CohereTextEmbedder",
"init_parameters": {
"model": "embed-english-v2.0",
"input_type": "search_query",
Expand Down Expand Up @@ -85,7 +84,7 @@ def test_to_dict_with_custom_init_parameters(self):
)
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "cohere_haystack.embedders.text_embedder.CohereTextEmbedder",
"type": "haystack_integrations.components.embedders.cohere.text_embedder.CohereTextEmbedder",
"init_parameters": {
"model": "embed-multilingual-v2.0",
"input_type": "classification",
Expand Down