Skip to content

Commit

Permalink
Add cohere suffix dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje committed Jan 19, 2024
1 parent e935a1c commit 0c23ff6
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/haystack-core-integrations.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

275 changes: 275 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +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.utils import get_async_response, get_response
from haystack_integrations.components.embedders.cohere.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,9 +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.utils import get_async_response, get_response
from haystack_integrations.components.embedders.cohere.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
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
12 changes: 6 additions & 6 deletions integrations/cohere/tests/test_cohere_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from haystack.components.generators.utils import default_streaming_callback
from haystack.dataclasses import ChatMessage, ChatRole, StreamingChunk
from haystack_integrations.components.generators.chat import CohereChatGenerator
from haystack_integrations.components.generators.cohere.chat import CohereChatGenerator

pytestmark = pytest.mark.chat_generators

Expand Down Expand Up @@ -87,7 +87,7 @@ def test_to_dict_default(self):
component = CohereChatGenerator(api_key="test-api-key")
data = component.to_dict()
assert data == {
"type": "haystack_integrations.components.generators.chat.chat_generator.CohereChatGenerator",
"type": "haystack_integrations.components.generators.cohere.chat.chat_generator.CohereChatGenerator",
"init_parameters": {
"model": "command",
"streaming_callback": None,
Expand All @@ -107,7 +107,7 @@ def test_to_dict_with_parameters(self):
)
data = component.to_dict()
assert data == {
"type": "haystack_integrations.components.generators.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 @@ -127,7 +127,7 @@ def test_to_dict_with_lambda_streaming_callback(self):
)
data = component.to_dict()
assert data == {
"type": "haystack_integrations.components.generators.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 @@ -140,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": "haystack_integrations.components.generators.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 @@ -158,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": "haystack_integrations.components.generators.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
10 changes: 5 additions & 5 deletions integrations/cohere/tests/test_cohere_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from cohere import COHERE_API_URL
from haystack_integrations.components.generators import CohereGenerator
from haystack_integrations.components.generators.cohere import CohereGenerator

pytestmark = pytest.mark.generators

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

pytestmark = pytest.mark.embedders

Expand Down Expand Up @@ -59,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": "haystack_integrations.components.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 @@ -92,7 +92,7 @@ def test_to_dict_with_custom_init_parameters(self):
)
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "haystack_integrations.components.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
6 changes: 3 additions & 3 deletions integrations/cohere/tests/test_text_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from cohere import COHERE_API_URL
from haystack_integrations.components.embedders import CohereTextEmbedder
from haystack_integrations.components.embedders.cohere import CohereTextEmbedder

pytestmark = pytest.mark.embedders

Expand Down Expand Up @@ -56,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": "haystack_integrations.components.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 @@ -84,7 +84,7 @@ def test_to_dict_with_custom_init_parameters(self):
)
component_dict = embedder_component.to_dict()
assert component_dict == {
"type": "haystack_integrations.components.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

0 comments on commit 0c23ff6

Please sign in to comment.