mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-05 22:02:38 +02:00
reflection for checking methods
This commit is contained in:
parent
3078362710
commit
dd82962937
4 changed files with 27 additions and 2 deletions
|
|
@ -53,6 +53,7 @@ class BaseFactory:
|
|||
|
||||
class RetrieverFactory(BaseFactory):
|
||||
def __init__(self):
|
||||
# Dynamically add configuration and corresponding instance implementation.
|
||||
creators = {
|
||||
FAISSRetrieverConfig: self._create_faiss_retriever,
|
||||
BM25RetrieverConfig: self._create_bm25_retriever,
|
||||
|
|
@ -88,6 +89,7 @@ class RetrieverFactory(BaseFactory):
|
|||
|
||||
class RankerFactory(BaseFactory):
|
||||
def __init__(self):
|
||||
# Dynamically add configuration and corresponding instance implementation.
|
||||
creators = {
|
||||
LLMRankerConfig: self._create_llm_ranker,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ from abc import abstractmethod
|
|||
from llama_index.retrievers import BaseRetriever
|
||||
from llama_index.schema import BaseNode, NodeWithScore, QueryType
|
||||
|
||||
from metagpt.utils.reflection import check_methods
|
||||
|
||||
|
||||
class RAGRetriever(BaseRetriever):
|
||||
"""Inherit from llama_index"""
|
||||
|
|
@ -23,8 +25,8 @@ class ModifiableRAGRetriever(RAGRetriever):
|
|||
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if any("add_nodes" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
if cls is ModifiableRAGRetriever:
|
||||
return check_methods(C, "add_nodes")
|
||||
return NotImplemented
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
|||
|
|
@ -25,5 +25,6 @@ class LLMRankerConfig(RankerConfig):
|
|||
...
|
||||
|
||||
|
||||
# If add new config, it is necessary to add the corresponding instance implementation in rag.factory
|
||||
RetrieverConfigType = Union[FAISSRetrieverConfig, BM25RetrieverConfig]
|
||||
RankerConfigType = LLMRankerConfig
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue