From 1d22b0c697c1ffc011006910e5f6e83aa18a595a Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 6 Dec 2023 17:13:44 +0100 Subject: [PATCH 1/2] remove LazyImport from integrations --- .../embedders/gradient_document_embedder.py | 6 +----- .../gradient_haystack/embedders/gradient_text_embedder.py | 6 +----- .../gradient/src/gradient_haystack/generator/base.py | 6 +----- .../embedding_backend/instructor_backend.py | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py b/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py index 81a93ad2b..7c401a634 100644 --- a/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py +++ b/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py @@ -2,10 +2,7 @@ from typing import Any, Dict, List, Optional from haystack import Document, component, default_to_dict -from haystack.lazy_imports import LazyImport - -with LazyImport(message="Run 'pip install gradientai'") as gradientai_import: - from gradientai import Gradient +from gradientai import Gradient logger = logging.getLogger(__name__) @@ -49,7 +46,6 @@ def __init__( variable GRADIENT_WORKSPACE_ID. :param host: The Gradient host. By default it uses https://api.gradient.ai/. """ - gradientai_import.check() self._batch_size = batch_size self._host = host self._model_name = model_name diff --git a/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py b/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py index 53996b785..b3b1a1f34 100644 --- a/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py +++ b/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py @@ -1,10 +1,7 @@ from typing import Any, Dict, List, Optional from haystack import component, default_to_dict -from haystack.lazy_imports import LazyImport - -with LazyImport(message="Run 'pip install gradientai'") as gradientai_import: - from gradientai import Gradient +from gradientai import Gradient @component @@ -43,7 +40,6 @@ def __init__( variable GRADIENT_WORKSPACE_ID. :param host: The Gradient host. By default it uses https://api.gradient.ai/. """ - gradientai_import.check() self._host = host self._model_name = model_name diff --git a/integrations/gradient/src/gradient_haystack/generator/base.py b/integrations/gradient/src/gradient_haystack/generator/base.py index 536525377..ad6881f27 100644 --- a/integrations/gradient/src/gradient_haystack/generator/base.py +++ b/integrations/gradient/src/gradient_haystack/generator/base.py @@ -2,10 +2,8 @@ from typing import Any, Dict, List, Optional from haystack import component, default_to_dict -from haystack.lazy_imports import LazyImport +from gradientai import Gradient -with LazyImport(message="Run 'pip install gradientai'") as gradientai_import: - from gradientai import Gradient logger = logging.getLogger(__name__) @@ -57,8 +55,6 @@ def __init__( :param workspace_id: The Gradient workspace ID. If not provided it's read from the environment variable GRADIENT_WORKSPACE_ID. """ - gradientai_import.check() - self._access_token = access_token self._base_model_slug = base_model_slug self._host = host diff --git a/integrations/instructor-embedders/instructor_embedders/embedding_backend/instructor_backend.py b/integrations/instructor-embedders/instructor_embedders/embedding_backend/instructor_backend.py index 5be300dd3..efe35e9b7 100644 --- a/integrations/instructor-embedders/instructor_embedders/embedding_backend/instructor_backend.py +++ b/integrations/instructor-embedders/instructor_embedders/embedding_backend/instructor_backend.py @@ -3,10 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 from typing import ClassVar, Dict, List, Optional, Union -from haystack.lazy_imports import LazyImport - -with LazyImport(message="Run 'pip install InstructorEmbedding'") as instructor_embeddings_import: - from InstructorEmbedding import INSTRUCTOR +from InstructorEmbedding import INSTRUCTOR class _InstructorEmbeddingBackendFactory: @@ -40,7 +37,6 @@ class _InstructorEmbeddingBackend: def __init__( self, model_name_or_path: str, device: Optional[str] = None, use_auth_token: Union[bool, str, None] = None ): - instructor_embeddings_import.check() self.model = INSTRUCTOR(model_name_or_path=model_name_or_path, device=device, use_auth_token=use_auth_token) def embed(self, data: List[List[str]], **kwargs) -> List[List[float]]: From e1f93737c86f98dd9a7188402861a04b766009e6 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 6 Dec 2023 17:24:17 +0100 Subject: [PATCH 2/2] fix linter --- .../gradient_haystack/embedders/gradient_document_embedder.py | 2 +- .../src/gradient_haystack/embedders/gradient_text_embedder.py | 2 +- integrations/gradient/src/gradient_haystack/generator/base.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py b/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py index 7c401a634..a716b8cf2 100644 --- a/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py +++ b/integrations/gradient/src/gradient_haystack/embedders/gradient_document_embedder.py @@ -1,8 +1,8 @@ import logging from typing import Any, Dict, List, Optional -from haystack import Document, component, default_to_dict from gradientai import Gradient +from haystack import Document, component, default_to_dict logger = logging.getLogger(__name__) diff --git a/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py b/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py index b3b1a1f34..013d375ff 100644 --- a/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py +++ b/integrations/gradient/src/gradient_haystack/embedders/gradient_text_embedder.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from haystack import component, default_to_dict from gradientai import Gradient +from haystack import component, default_to_dict @component diff --git a/integrations/gradient/src/gradient_haystack/generator/base.py b/integrations/gradient/src/gradient_haystack/generator/base.py index ad6881f27..3adf0be01 100644 --- a/integrations/gradient/src/gradient_haystack/generator/base.py +++ b/integrations/gradient/src/gradient_haystack/generator/base.py @@ -1,9 +1,8 @@ import logging from typing import Any, Dict, List, Optional -from haystack import component, default_to_dict from gradientai import Gradient - +from haystack import component, default_to_dict logger = logging.getLogger(__name__)