-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generalize creating objects from config
- Loading branch information
1 parent
9ea3ace
commit 9d831b3
Showing
29 changed files
with
257 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
packages/ragbits-core/src/ragbits/core/embeddings/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,4 @@ | ||
import sys | ||
|
||
from ragbits.core.utils.config_handling import get_cls_from_config | ||
|
||
from .base import Embeddings, EmbeddingType | ||
from .noop import NoopEmbeddings | ||
|
||
__all__ = ["EmbeddingType", "Embeddings", "NoopEmbeddings"] | ||
|
||
module = sys.modules[__name__] | ||
|
||
|
||
def get_embeddings(embedder_config: dict) -> Embeddings: | ||
""" | ||
Initializes and returns an Embeddings object based on the provided embedder configuration. | ||
Args: | ||
embedder_config : A dictionary containing configuration details for the embedder. | ||
Returns: | ||
An instance of the specified Embeddings class, initialized with the provided config | ||
(if any) or default arguments. | ||
""" | ||
embeddings_type = embedder_config["type"] | ||
config = embedder_config.get("config", {}) | ||
|
||
embbedings = get_cls_from_config(embeddings_type, module) | ||
return embbedings(**config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,3 @@ | ||
import sys | ||
|
||
from ragbits.core.utils.config_handling import get_cls_from_config | ||
|
||
from .base import LLM | ||
|
||
__all__ = ["LLM"] | ||
|
||
module = sys.modules[__name__] | ||
|
||
|
||
def get_llm(config: dict) -> LLM: | ||
""" | ||
Initializes and returns an LLM object based on the provided configuration. | ||
Args: | ||
config : A dictionary containing configuration details for the LLM. | ||
Returns: | ||
An instance of the specified LLM class, initialized with the provided config | ||
(if any) or default arguments. | ||
Raises: | ||
KeyError: If the configuration dictionary does not contain a "type" key. | ||
ValueError: If the LLM class is not a subclass of LLM. | ||
""" | ||
llm_type = config["type"] | ||
llm_config = config.get("config", {}) | ||
default_options = llm_config.pop("default_options", None) | ||
llm_cls = get_cls_from_config(llm_type, module) | ||
|
||
if not issubclass(llm_cls, LLM): | ||
raise ValueError(f"Invalid LLM class: {llm_cls}") | ||
|
||
# We need to infer the options class from the LLM class. | ||
# pylint: disable=protected-access | ||
options = llm_cls._options_cls(**default_options) if default_options else None # type: ignore | ||
|
||
return llm_cls(**llm_config, default_options=options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
packages/ragbits-core/src/ragbits/core/metadata_stores/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,4 @@ | ||
import sys | ||
|
||
from ragbits.core.utils.config_handling import get_cls_from_config | ||
|
||
from .base import MetadataStore | ||
from .in_memory import InMemoryMetadataStore | ||
|
||
__all__ = ["InMemoryMetadataStore", "MetadataStore"] | ||
|
||
module = sys.modules[__name__] | ||
|
||
|
||
def get_metadata_store(metadata_store_config: dict | None) -> MetadataStore | None: | ||
""" | ||
Initializes and returns a MetadataStore object based on the provided configuration. | ||
Args: | ||
metadata_store_config: A dictionary containing configuration details for the MetadataStore. | ||
Returns: | ||
An instance of the specified MetadataStore class, initialized with the provided config | ||
(if any) or default arguments. | ||
""" | ||
if metadata_store_config is None: | ||
return None | ||
|
||
metadata_store_class = get_cls_from_config(metadata_store_config["type"], module) | ||
config = metadata_store_config.get("config", {}) | ||
|
||
return metadata_store_class(**config) |
8 changes: 7 additions & 1 deletion
8
packages/ragbits-core/src/ragbits/core/metadata_stores/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.