mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
rename ConfigFactory to RAGConfigRegistry
This commit is contained in:
parent
e58cef6f18
commit
cb9543b2b9
5 changed files with 13 additions and 13 deletions
|
|
@ -29,7 +29,7 @@ class GenericFactory:
|
|||
raise ValueError(f"Creator not registered for key: {key}")
|
||||
|
||||
|
||||
class ConfigFactory(GenericFactory):
|
||||
class RAGConfigRegistry(GenericFactory):
|
||||
"""Designed to get objects based on object type."""
|
||||
|
||||
def get_instance(self, key: Any, **kwargs) -> Any:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from llama_index.core.embeddings import BaseEmbedding
|
|||
from llama_index.core.indices.base import BaseIndex
|
||||
from llama_index.vector_stores.faiss import FaissVectorStore
|
||||
|
||||
from metagpt.rag.factories.base import ConfigFactory
|
||||
from metagpt.rag.factories.base import RAGConfigRegistry
|
||||
from metagpt.rag.schema import (
|
||||
BaseIndexConfig,
|
||||
BM25IndexConfig,
|
||||
|
|
@ -16,7 +16,7 @@ from metagpt.rag.schema import (
|
|||
from metagpt.rag.vector_stores.chroma import ChromaVectorStore
|
||||
|
||||
|
||||
class RAGIndexFactory(ConfigFactory):
|
||||
class RAGIndexFactory(RAGConfigRegistry):
|
||||
def __init__(self):
|
||||
creators = {
|
||||
FAISSIndexConfig: self._create_faiss,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ from llama_index.core.llms import LLM
|
|||
from llama_index.core.postprocessor import LLMRerank
|
||||
from llama_index.core.postprocessor.types import BaseNodePostprocessor
|
||||
|
||||
from metagpt.rag.factories.base import ConfigFactory
|
||||
from metagpt.rag.factories.base import RAGConfigRegistry
|
||||
from metagpt.rag.schema import BaseRankerConfig, LLMRankerConfig
|
||||
|
||||
|
||||
class RankerFactory(ConfigFactory):
|
||||
class RankerFactory(RAGConfigRegistry):
|
||||
"""Modify creators for dynamically instance implementation."""
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from llama_index.core import StorageContext, VectorStoreIndex
|
|||
from llama_index.core.vector_stores.types import BasePydanticVectorStore
|
||||
from llama_index.vector_stores.faiss import FaissVectorStore
|
||||
|
||||
from metagpt.rag.factories.base import ConfigFactory
|
||||
from metagpt.rag.factories.base import RAGConfigRegistry
|
||||
from metagpt.rag.retrievers.base import RAGRetriever
|
||||
from metagpt.rag.retrievers.bm25_retriever import DynamicBM25Retriever
|
||||
from metagpt.rag.retrievers.chroma_retriever import ChromaRetriever
|
||||
|
|
@ -24,7 +24,7 @@ from metagpt.rag.schema import (
|
|||
from metagpt.rag.vector_stores.chroma import ChromaVectorStore
|
||||
|
||||
|
||||
class RetrieverFactory(ConfigFactory):
|
||||
class RetrieverFactory(RAGConfigRegistry):
|
||||
"""Modify creators for dynamically instance implementation."""
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.rag.factories.base import ConfigFactory, GenericFactory
|
||||
from metagpt.rag.factories.base import GenericFactory, RAGConfigRegistry
|
||||
|
||||
|
||||
class TestGenericFactory:
|
||||
|
|
@ -55,7 +55,7 @@ class DummyConfig:
|
|||
self.name = name
|
||||
|
||||
|
||||
class TestConfigFactory:
|
||||
class TestRAGConfigRegistry:
|
||||
@pytest.fixture
|
||||
def config_creators(self):
|
||||
return {
|
||||
|
|
@ -64,7 +64,7 @@ class TestConfigFactory:
|
|||
|
||||
@pytest.fixture
|
||||
def config_factory(self, config_creators):
|
||||
return ConfigFactory(creators=config_creators)
|
||||
return RAGConfigRegistry(creators=config_creators)
|
||||
|
||||
def test_get_instance_success(self, config_factory):
|
||||
# Test successful retrieval of an instance
|
||||
|
|
@ -85,18 +85,18 @@ class TestConfigFactory:
|
|||
def test_val_from_config_or_kwargs_priority(self):
|
||||
# Test that the value from the config object has priority over kwargs
|
||||
config = DummyConfig(name="ConfigName")
|
||||
result = ConfigFactory._val_from_config_or_kwargs("name", config, name="KwargsName")
|
||||
result = RAGConfigRegistry._val_from_config_or_kwargs("name", config, name="KwargsName")
|
||||
assert result == "ConfigName"
|
||||
|
||||
def test_val_from_config_or_kwargs_fallback_to_kwargs(self):
|
||||
# Test fallback to kwargs when config object does not have the value
|
||||
config = DummyConfig(name=None)
|
||||
result = ConfigFactory._val_from_config_or_kwargs("name", config, name="KwargsName")
|
||||
result = RAGConfigRegistry._val_from_config_or_kwargs("name", config, name="KwargsName")
|
||||
assert result == "KwargsName"
|
||||
|
||||
def test_val_from_config_or_kwargs_key_error(self):
|
||||
# Test KeyError when the key is not found in both config object and kwargs
|
||||
config = DummyConfig(name=None)
|
||||
with pytest.raises(KeyError) as exc_info:
|
||||
ConfigFactory._val_from_config_or_kwargs("missing_key", config)
|
||||
RAGConfigRegistry._val_from_config_or_kwargs("missing_key", config)
|
||||
assert "The key 'missing_key' is required but not provided" in str(exc_info.value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue