feat(core): user should be able to configure default types of default… #288
128 tests run, 114 passed, 8 skipped, 6 failed.
Annotations
Check failure on line 16 in packages/ragbits-core/tests/unit/llms/factory/test_get_default_llm.py
github-actions / JUnit Test Report
test_get_default_llm
ValueError: Default LLM of type LLMType.TEXT is not defined in pyproject.toml config.
Raw output
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f210b29a920>
def test_get_default_llm(monkeypatch: pytest.MonkeyPatch) -> None:
"""
Test the get_llm_from_factory function.
"""
monkeypatch.setattr(
core_config, "default_llm_factories", {"text": "factory.test_get_llm_from_factory.mock_llm_factory"}
)
> llm = get_default_llm()
packages/ragbits-core/tests/unit/llms/factory/test_get_default_llm.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
llm_type = <LLMType.TEXT: 'text'>
def get_default_llm(llm_type: LLMType = LLMType.TEXT) -> LLM:
"""
Get an instance of the default LLM using the factory function
specified in the configuration.
Args:
llm_type: type of the LLM to get, defaults to text
Returns:
LLM: An instance of the default LLM.
Raises:
ValueError: If the default LLM factory is not set or expected llm type is not defined in config
"""
if llm_type not in core_config.default_llm_factories:
> raise ValueError(f"Default LLM of type {llm_type} is not defined in pyproject.toml config.")
E ValueError: Default LLM of type LLMType.TEXT is not defined in pyproject.toml config.
packages/ragbits-core/src/ragbits/core/llms/factory.py:50: ValueError
Check failure on line 22 in packages/ragbits-core/tests/unit/llms/factory/test_has_default_llm.py
github-actions / JUnit Test Report
test_has_default_llm.test_has_default_llm_false
assert False is True
+ where False = has_default_llm()
Raw output
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f203e2138b0>
def test_has_default_llm_false(monkeypatch: pytest.MonkeyPatch) -> None:
"""
Test the has_default_llm function when the default LLM factory is set.
"""
monkeypatch.setattr(core_config, "default_llm_factories", {"text": "my_project.llms.get_llm"})
> assert has_default_llm() is True
E assert False is True
E + where False = has_default_llm()
packages/ragbits-core/tests/unit/llms/factory/test_has_default_llm.py:22: AssertionError
Check failure on line 29 in packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py
github-actions / JUnit Test Report
test_get_instace.test_get_config_instance
KeyError: 'default_llm_factories'
Raw output
def test_get_config_instance():
"""Test getting Pydantic model instance from pyproject.toml file."""
> config = get_config_instance(
HappyProjectConfig,
subproject="happy-project",
current_dir=projects_dir / "happy_project",
)
packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py:29:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <class 'test_get_instace.HappyProjectConfig'>
subproject = 'happy-project'
current_dir = PosixPath('/home/runner/work/ragbits/ragbits/packages/ragbits-core/tests/unit/utils/pyproject/testprojects/happy_project')
def get_config_instance(
model: type[ConfigModelT], subproject: str | None = None, current_dir: Path | None = None
) -> ConfigModelT:
"""
Creates an instance of pydantic model loaded with the configuration from pyproject.toml.
Args:
model (Type[BaseModel]): The pydantic model to instantiate.
subproject (str, optional): The subproject to get the configuration for, defaults to giving entire
ragbits configuration.
current_dir (Path, optional): The directory to start searching for the pyproject.toml file. Defaults to the
current working directory
Returns:
ConfigModelT: The model instance loaded with the configuration
"""
current_dir = current_dir or Path.cwd()
config = get_ragbits_config(current_dir)
if subproject:
config = config.get(subproject, {})
> config["default_llm_factories"] = {_resolve_enum_member(k): v for k, v in config["default_llm_factories"].items()}
E KeyError: 'default_llm_factories'
packages/ragbits-core/src/ragbits/core/utils/_pyproject.py:86: KeyError
Check failure on line 40 in packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py
github-actions / JUnit Test Report
test_get_instace.test_get_config_instance_additional_fields
KeyError: 'default_llm_factories'
Raw output
def test_get_config_instance_additional_fields():
"""Test that unknown fields are ignored."""
> config = get_config_instance(
PartialHappyProjectConfig,
subproject="happy-project",
current_dir=projects_dir / "happy_project",
)
packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <class 'test_get_instace.PartialHappyProjectConfig'>
subproject = 'happy-project'
current_dir = PosixPath('/home/runner/work/ragbits/ragbits/packages/ragbits-core/tests/unit/utils/pyproject/testprojects/happy_project')
def get_config_instance(
model: type[ConfigModelT], subproject: str | None = None, current_dir: Path | None = None
) -> ConfigModelT:
"""
Creates an instance of pydantic model loaded with the configuration from pyproject.toml.
Args:
model (Type[BaseModel]): The pydantic model to instantiate.
subproject (str, optional): The subproject to get the configuration for, defaults to giving entire
ragbits configuration.
current_dir (Path, optional): The directory to start searching for the pyproject.toml file. Defaults to the
current working directory
Returns:
ConfigModelT: The model instance loaded with the configuration
"""
current_dir = current_dir or Path.cwd()
config = get_ragbits_config(current_dir)
if subproject:
config = config.get(subproject, {})
> config["default_llm_factories"] = {_resolve_enum_member(k): v for k, v in config["default_llm_factories"].items()}
E KeyError: 'default_llm_factories'
packages/ragbits-core/src/ragbits/core/utils/_pyproject.py:86: KeyError
Check failure on line 51 in packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py
github-actions / JUnit Test Report
test_get_instace.test_get_config_instance_optional_fields
KeyError: 'default_llm_factories'
Raw output
def test_get_config_instance_optional_fields():
"""Test that optional fields are filled with default values if not present in the file."""
> config = get_config_instance(
OptionalHappyProjectConfig,
subproject="happy-project",
current_dir=projects_dir / "happy_project",
)
packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py:51:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <class 'test_get_instace.OptionalHappyProjectConfig'>
subproject = 'happy-project'
current_dir = PosixPath('/home/runner/work/ragbits/ragbits/packages/ragbits-core/tests/unit/utils/pyproject/testprojects/happy_project')
def get_config_instance(
model: type[ConfigModelT], subproject: str | None = None, current_dir: Path | None = None
) -> ConfigModelT:
"""
Creates an instance of pydantic model loaded with the configuration from pyproject.toml.
Args:
model (Type[BaseModel]): The pydantic model to instantiate.
subproject (str, optional): The subproject to get the configuration for, defaults to giving entire
ragbits configuration.
current_dir (Path, optional): The directory to start searching for the pyproject.toml file. Defaults to the
current working directory
Returns:
ConfigModelT: The model instance loaded with the configuration
"""
current_dir = current_dir or Path.cwd()
config = get_ragbits_config(current_dir)
if subproject:
config = config.get(subproject, {})
> config["default_llm_factories"] = {_resolve_enum_member(k): v for k, v in config["default_llm_factories"].items()}
E KeyError: 'default_llm_factories'
packages/ragbits-core/src/ragbits/core/utils/_pyproject.py:86: KeyError
Check failure on line 62 in packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py
github-actions / JUnit Test Report
test_get_instace.test_get_config_instance_no_file
KeyError: 'default_llm_factories'
Raw output
def test_get_config_instance_no_file():
"""Test getting config when the pyproject.toml file is not found (wich no required fields)."""
> config = get_config_instance(
OptionalHappyProjectConfig,
subproject="happy-project",
current_dir=Path("/"),
)
packages/ragbits-core/tests/unit/utils/pyproject/test_get_instace.py:62:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <class 'test_get_instace.OptionalHappyProjectConfig'>
subproject = 'happy-project', current_dir = PosixPath('/')
def get_config_instance(
model: type[ConfigModelT], subproject: str | None = None, current_dir: Path | None = None
) -> ConfigModelT:
"""
Creates an instance of pydantic model loaded with the configuration from pyproject.toml.
Args:
model (Type[BaseModel]): The pydantic model to instantiate.
subproject (str, optional): The subproject to get the configuration for, defaults to giving entire
ragbits configuration.
current_dir (Path, optional): The directory to start searching for the pyproject.toml file. Defaults to the
current working directory
Returns:
ConfigModelT: The model instance loaded with the configuration
"""
current_dir = current_dir or Path.cwd()
config = get_ragbits_config(current_dir)
if subproject:
config = config.get(subproject, {})
> config["default_llm_factories"] = {_resolve_enum_member(k): v for k, v in config["default_llm_factories"].items()}
E KeyError: 'default_llm_factories'
packages/ragbits-core/src/ragbits/core/utils/_pyproject.py:86: KeyError