From cc29cd118cc7974ac50a1580e5185f6389485176 Mon Sep 17 00:00:00 2001 From: Alan Konarski Date: Wed, 18 Dec 2024 14:45:22 +0100 Subject: [PATCH] Make options_cls classvar public --- packages/ragbits-core/src/ragbits/core/embeddings/base.py | 2 +- .../ragbits-core/src/ragbits/core/embeddings/litellm.py | 2 +- .../ragbits-core/src/ragbits/core/embeddings/local.py | 2 +- packages/ragbits-core/src/ragbits/core/embeddings/noop.py | 2 +- .../src/ragbits/core/embeddings/vertex_multimodal.py | 2 +- packages/ragbits-core/src/ragbits/core/llms/base.py | 8 ++++---- packages/ragbits-core/src/ragbits/core/llms/litellm.py | 2 +- packages/ragbits-core/src/ragbits/core/llms/local.py | 2 +- .../src/ragbits/core/utils/config_handling.py | 6 +++--- .../ragbits-core/src/ragbits/core/vector_stores/base.py | 4 ++-- .../ragbits-core/src/ragbits/core/vector_stores/chroma.py | 2 +- .../src/ragbits/core/vector_stores/in_memory.py | 2 +- .../ragbits-core/src/ragbits/core/vector_stores/qdrant.py | 2 +- .../ragbits/document_search/retrieval/rerankers/base.py | 2 +- .../document_search/retrieval/rerankers/litellm.py | 2 +- .../ragbits/document_search/retrieval/rerankers/noop.py | 2 +- .../ragbits-document-search/tests/unit/test_rerankers.py | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/ragbits-core/src/ragbits/core/embeddings/base.py b/packages/ragbits-core/src/ragbits/core/embeddings/base.py index 7c41e3677..7e855d967 100644 --- a/packages/ragbits-core/src/ragbits/core/embeddings/base.py +++ b/packages/ragbits-core/src/ragbits/core/embeddings/base.py @@ -29,7 +29,7 @@ class Embeddings(ConfigurableComponent[EmbeddingsClientOptions], ABC): Abstract client for communication with embedding models. """ - _options_cls: type[EmbeddingsClientOptions] + options_cls: type[EmbeddingsClientOptions] default_module: ClassVar = embeddings configuration_key: ClassVar = "embedder" diff --git a/packages/ragbits-core/src/ragbits/core/embeddings/litellm.py b/packages/ragbits-core/src/ragbits/core/embeddings/litellm.py index 38b1cb0e9..d008d3e63 100644 --- a/packages/ragbits-core/src/ragbits/core/embeddings/litellm.py +++ b/packages/ragbits-core/src/ragbits/core/embeddings/litellm.py @@ -29,7 +29,7 @@ class LiteLLMEmbeddings(Embeddings[LiteLLMEmbeddingsOptions]): Client for creating text embeddings using LiteLLM API. """ - _options_cls = LiteLLMEmbeddingsOptions + options_cls = LiteLLMEmbeddingsOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/embeddings/local.py b/packages/ragbits-core/src/ragbits/core/embeddings/local.py index 02076c3db..435eeeb4b 100644 --- a/packages/ragbits-core/src/ragbits/core/embeddings/local.py +++ b/packages/ragbits-core/src/ragbits/core/embeddings/local.py @@ -26,7 +26,7 @@ class LocalEmbeddings(Embeddings[LocalEmbeddingsOptions]): Class for interaction with any encoder available in HuggingFace. """ - _options_cls = LocalEmbeddingsOptions + options_cls = LocalEmbeddingsOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/embeddings/noop.py b/packages/ragbits-core/src/ragbits/core/embeddings/noop.py index 47ade9a82..bfd33de7e 100644 --- a/packages/ragbits-core/src/ragbits/core/embeddings/noop.py +++ b/packages/ragbits-core/src/ragbits/core/embeddings/noop.py @@ -12,7 +12,7 @@ class NoopEmbeddings(Embeddings): or as a placeholder when an actual embedding model is not required. """ - _options_cls = Options + options_cls = Options @traceable async def embed_text(self, data: list[str], options: EmbeddingsClientOptions | None = None) -> list[list[float]]: # noqa: PLR6301 diff --git a/packages/ragbits-core/src/ragbits/core/embeddings/vertex_multimodal.py b/packages/ragbits-core/src/ragbits/core/embeddings/vertex_multimodal.py index 1fcf3a162..2d84bc007 100644 --- a/packages/ragbits-core/src/ragbits/core/embeddings/vertex_multimodal.py +++ b/packages/ragbits-core/src/ragbits/core/embeddings/vertex_multimodal.py @@ -24,7 +24,7 @@ class VertexAIMultimodelEmbeddings(Embeddings): Client for creating text embeddings using LiteLLM API. """ - _options_cls = Options + options_cls = Options VERTEX_AI_PREFIX = "vertex_ai/" def __init__( diff --git a/packages/ragbits-core/src/ragbits/core/llms/base.py b/packages/ragbits-core/src/ragbits/core/llms/base.py index 62b51f4e2..fc7fcd847 100644 --- a/packages/ragbits-core/src/ragbits/core/llms/base.py +++ b/packages/ragbits-core/src/ragbits/core/llms/base.py @@ -26,7 +26,7 @@ class LLM(ConfigurableComponent[LLMClientOptions], ABC): Abstract class for interaction with Large Language Model. """ - _options_cls: type[LLMClientOptions] + options_cls: type[LLMClientOptions] default_module: ClassVar = llms configuration_key: ClassVar = "llm" @@ -39,14 +39,14 @@ def __init__(self, model_name: str, default_options: LLMClientOptions | None = N default_options: Default options to be used. Raises: - TypeError: If the subclass is missing the '_options_cls' attribute. + TypeError: If the subclass is missing the 'options_cls' attribute. """ super().__init__(default_options=default_options) self.model_name = model_name def __init_subclass__(cls) -> None: - if not hasattr(cls, "_options_cls"): - raise TypeError(f"Class {cls.__name__} is missing the '_options_cls' attribute") + if not hasattr(cls, "options_cls"): + raise TypeError(f"Class {cls.__name__} is missing the 'options_cls' attribute") @cached_property @abstractmethod diff --git a/packages/ragbits-core/src/ragbits/core/llms/litellm.py b/packages/ragbits-core/src/ragbits/core/llms/litellm.py index 13c1ebe7f..0714bb923 100644 --- a/packages/ragbits-core/src/ragbits/core/llms/litellm.py +++ b/packages/ragbits-core/src/ragbits/core/llms/litellm.py @@ -15,7 +15,7 @@ class LiteLLM(LLM[LiteLLMOptions]): Class for interaction with any LLM supported by LiteLLM API. """ - _options_cls = LiteLLMOptions + options_cls = LiteLLMOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/llms/local.py b/packages/ragbits-core/src/ragbits/core/llms/local.py index 0d4699063..42d23979d 100644 --- a/packages/ragbits-core/src/ragbits/core/llms/local.py +++ b/packages/ragbits-core/src/ragbits/core/llms/local.py @@ -18,7 +18,7 @@ class LocalLLM(LLM[LocalLLMOptions]): Class for interaction with any LLM available in HuggingFace. """ - _options_cls = LocalLLMOptions + options_cls = LocalLLMOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/utils/config_handling.py b/packages/ragbits-core/src/ragbits/core/utils/config_handling.py index 2ca7c7ad3..ef2d3c500 100644 --- a/packages/ragbits-core/src/ragbits/core/utils/config_handling.py +++ b/packages/ragbits-core/src/ragbits/core/utils/config_handling.py @@ -177,7 +177,7 @@ class ConfigurableComponent(Generic[OptionsTypeVar], WithConstructionConfig): Base class for components with configurable options. """ - _options_cls: type[OptionsTypeVar] + options_cls: type[OptionsTypeVar] def __init__(self, default_options: OptionsTypeVar | None = None) -> None: """ @@ -186,7 +186,7 @@ def __init__(self, default_options: OptionsTypeVar | None = None) -> None: Args: default_options: The default options for the component. """ - self.default_options = default_options or self._options_cls() + self.default_options = default_options or self.options_cls() @classmethod def from_config(cls, config: dict[str, Any]) -> ConfigurableComponent: @@ -200,5 +200,5 @@ def from_config(cls, config: dict[str, Any]) -> ConfigurableComponent: An instance of the class initialized with the provided configuration. """ default_options = config.pop("default_options", None) - options = cls._options_cls(**default_options) if default_options else None + options = cls.options_cls(**default_options) if default_options else None return cls(**config, default_options=options) diff --git a/packages/ragbits-core/src/ragbits/core/vector_stores/base.py b/packages/ragbits-core/src/ragbits/core/vector_stores/base.py index 628e5e274..8069508ec 100644 --- a/packages/ragbits-core/src/ragbits/core/vector_stores/base.py +++ b/packages/ragbits-core/src/ragbits/core/vector_stores/base.py @@ -40,7 +40,7 @@ class VectorStore(ConfigurableComponent[VectorStoreOptionsType], ABC): A class with an implementation of Vector Store, allowing to store and retrieve vectors by similarity function. """ - _options_cls: type[VectorStoreOptionsType] + options_cls: type[VectorStoreOptionsType] default_module: ClassVar = vector_stores configuration_key: ClassVar = "vector_store" @@ -75,7 +75,7 @@ def from_config(cls, config: dict) -> Self: InvalidConfigError: The metadata_store class can't be found or is not the correct type. """ default_options = config.pop("default_options", None) - options = cls._options_cls(**default_options) if default_options else None + options = cls.options_cls(**default_options) if default_options else None store_config = config.pop("metadata_store", None) store = ( diff --git a/packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py b/packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py index f1b15bab9..f5906dde5 100644 --- a/packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py +++ b/packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py @@ -16,7 +16,7 @@ class ChromaVectorStore(VectorStore): Vector store implementation using [Chroma](https://docs.trychroma.com). """ - _options_cls = VectorStoreOptions + options_cls = VectorStoreOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py b/packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py index 26245ca13..16cdaa977 100644 --- a/packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py +++ b/packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py @@ -13,7 +13,7 @@ class InMemoryVectorStore(VectorStore): A simple in-memory implementation of Vector Store, storing vectors in memory. """ - _options_cls = VectorStoreOptions + options_cls = VectorStoreOptions def __init__( self, diff --git a/packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py b/packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py index efdfe4b93..77efb9b74 100644 --- a/packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py +++ b/packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py @@ -17,7 +17,7 @@ class QdrantVectorStore(VectorStore): Vector store implementation using [Qdrant](https://qdrant.tech). """ - _options_cls = VectorStoreOptions + options_cls = VectorStoreOptions def __init__( self, diff --git a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/base.py b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/base.py index 8b25e8233..560f304c2 100644 --- a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/base.py +++ b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/base.py @@ -26,7 +26,7 @@ class Reranker(ConfigurableComponent[RerankerOptionsType], ABC): """ default_module: ClassVar = rerankers - _options_cls: type[RerankerOptionsType] + options_cls: type[RerankerOptionsType] configuration_key: ClassVar = "reranker" @abstractmethod diff --git a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.py b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.py index 205b56716..8fcb69b6a 100644 --- a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.py +++ b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.py @@ -12,7 +12,7 @@ class LiteLLMReranker(Reranker[RerankerOptions]): A [LiteLLM](https://docs.litellm.ai/docs/rerank) reranker for providers such as Cohere, Together AI, Azure AI. """ - _options_cls = RerankerOptions + options_cls = RerankerOptions def __init__(self, model: str, default_options: RerankerOptions | None = None) -> None: """ diff --git a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/noop.py b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/noop.py index 2d0062dbd..f0e8cd9d3 100644 --- a/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/noop.py +++ b/packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/noop.py @@ -10,7 +10,7 @@ class NoopReranker(Reranker[RerankerOptions]): A no-op reranker that does not change the order of the elements. """ - _options_cls = RerankerOptions + options_cls = RerankerOptions @traceable async def rerank( # noqa: PLR6301 diff --git a/packages/ragbits-document-search/tests/unit/test_rerankers.py b/packages/ragbits-document-search/tests/unit/test_rerankers.py index 525494ba8..ff127e768 100644 --- a/packages/ragbits-document-search/tests/unit/test_rerankers.py +++ b/packages/ragbits-document-search/tests/unit/test_rerankers.py @@ -15,7 +15,7 @@ class CustomReranker(Reranker): Custom implementation of Reranker for testing. """ - _options_cls = RerankerOptions + options_cls = RerankerOptions async def rerank( # noqa: PLR6301 self, elements: Sequence[Element], query: str, options: RerankerOptions | None = None