Skip to content

Commit

Permalink
feature(agent): Knowledge add retriever name&desc getter and stter (#…
Browse files Browse the repository at this point in the history
…2309)

Co-authored-by: cinjospeh <[email protected]>
  • Loading branch information
cinjoseph and cinjospeh authored Jan 23, 2025
1 parent e0081e6 commit 8bb2a15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dbgpt/agent/resource/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def name(self) -> str:
"""Return the resource name."""
return self._name

@property
def retriever_name(self) -> str:
"""Return the resource name."""
return ""

@property
def retriever_desc(self) -> str:
"""Return the retriever desc."""
return ""

@property
def retriever(self) -> "BaseRetriever":
"""Return the retriever."""
Expand Down
30 changes: 30 additions & 0 deletions dbgpt/serve/agent/resource/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ def __init__(self, name: str, space_name: str, context: Optional[dict] = None):
)
super().__init__(name, retriever=retriever)

knowledge_spaces = get_knowledge_spaces_info(id=space_name)
if knowledge_spaces is not None and len(knowledge_spaces) > 0:
self._retriever_name = knowledge_spaces[0].name
self._retriever_desc = knowledge_spaces[0].desc
else:
self._retriever_name = None
self._retriever_desc = None

@property
def retriever_name(self) -> str:
"""Return the resource name."""
return self._retriever_name

@property
def retriever_desc(self) -> str:
"""Return the retriever desc."""
return self._retriever_desc

@classmethod
def resource_parameters_class(
cls, **kwargs
Expand Down Expand Up @@ -102,3 +120,15 @@ class _DynamicKnowledgeSpaceLoadResourceParameters(
)

return _DynamicKnowledgeSpaceLoadResourceParameters


def get_knowledge_spaces_info(**kwargs):
from dbgpt.app.knowledge.request.request import KnowledgeSpaceRequest
from dbgpt.app.knowledge.service import KnowledgeService

knowledge_space_service = KnowledgeService()
knowledge_spaces = knowledge_space_service.get_knowledge_space(
KnowledgeSpaceRequest(**kwargs)
)

return knowledge_spaces

0 comments on commit 8bb2a15

Please sign in to comment.