Skip to content

Commit

Permalink
Make options_cls classvar public
Browse files Browse the repository at this point in the history
  • Loading branch information
akonarski-ds committed Dec 18, 2024
1 parent be3b2d2 commit cc29cd1
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/ragbits-core/src/ragbits/core/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ragbits-core/src/ragbits/core/embeddings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ragbits-core/src/ragbits/core/embeddings/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
8 changes: 4 additions & 4 deletions packages/ragbits-core/src/ragbits/core/llms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ragbits-core/src/ragbits/core/llms/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ragbits-core/src/ragbits/core/llms/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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:
Expand All @@ -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)
4 changes: 2 additions & 2 deletions packages/ragbits-core/src/ragbits/core/vector_stores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class QdrantVectorStore(VectorStore):
Vector store implementation using [Qdrant](https://qdrant.tech).
"""

_options_cls = VectorStoreOptions
options_cls = VectorStoreOptions

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cc29cd1

Please sign in to comment.