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 7 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 @@ -7,8 +7,7 @@

from cohere import COHERE_API_URL, AsyncClient, Client
from haystack import Document, component, default_to_dict

from cohere_haystack.embedders.utils import get_async_response, get_response
from haystack_integrations.components.embedders.utils import get_async_response, get_response


@component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from cohere import COHERE_API_URL, AsyncClient, Client
from haystack import component, default_to_dict

from cohere_haystack.embedders.utils import get_async_response, get_response
from haystack_integrations.components.embedders.utils import get_async_response, get_response


@component
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"]
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.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.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.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.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.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.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 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.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.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.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.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 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.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.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 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.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.text_embedder.CohereTextEmbedder",
"init_parameters": {
"model": "embed-multilingual-v2.0",
"input_type": "classification",
Expand Down