Skip to content

Commit

Permalink
add RAGConfig to regulate rag config input
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiTao-Li committed May 22, 2024
1 parent 0257667 commit 63648fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/agentscope/agents/rag_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from agentscope.message import Msg
from agentscope.rag import Knowledge


CHECKING_PROMPT = """
Is the retrieved content relevant to the query?
Retrieved content: {}
Expand All @@ -22,6 +21,29 @@
"""


class RAGConfig(dict):
"""a class to regulate the RAG configuration."""

def __init__(self, knowledge_id: list[str], **kwargs: Any):
"""
RAG configuration must have knowledge_id as a list of strings.
Args:
knowledge_id (list[str]): the list of knowledge ids
"""
super().__init__()
self.knowledge_id = knowledge_id
self.update(kwargs)

def __getattr__(self, key: Any) -> Any:
try:
return self[key]
except KeyError as e:
raise AttributeError(f"no attribute '{key}'") from e

def __setattr__(self, key: Any, value: Any) -> None:
self[key] = value


class LlamaIndexAgent(AgentBase):
"""
A LlamaIndex agent build on LlamaIndex.
Expand All @@ -34,7 +56,7 @@ def __init__(
model_config_name: str,
knowledge_list: list[Knowledge] = None,
memory_config: Optional[dict] = None,
rag_config: Optional[dict] = None,
rag_config: Optional[RAGConfig] = None,
**kwargs: Any,
) -> None:
"""
Expand Down Expand Up @@ -70,7 +92,7 @@ def __init__(
self.knowledge_list = knowledge_list or []
self.retriever_list = []
self.description = kwargs.get("description", "")
self.rag_config = rag_config or {}
self.rag_config = rag_config or RAGConfig([])

def reply(self, x: dict = None) -> dict:
"""
Expand Down
1 change: 1 addition & 0 deletions src/agentscope/rag/knowledge_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def equip(self, agent: AgentBase, duplicate: bool = False) -> None:
agent (AgentBase): the agent to be equipped with knowledge
if it has "rag_config"
duplicate (bool): whether to deepcopy the knowledge object
TODO: to accommodate with distributed setting
"""
if hasattr(agent, "rag_config") and "knowledge_id" in agent.rag_config:
if not hasattr(agent, "knowledge_list"):
Expand Down

0 comments on commit 63648fc

Please sign in to comment.