-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:add rag awel operator view metadata. (#1174)
- Loading branch information
Showing
10 changed files
with
527 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,92 @@ | ||
from typing import Any, List, Optional | ||
|
||
from dbgpt.core.awel import MapOperator | ||
from dbgpt.core.awel.flow import ( | ||
IOField, | ||
OperatorCategory, | ||
OptionValue, | ||
Parameter, | ||
ViewMetadata, | ||
) | ||
from dbgpt.core.awel.task.base import IN | ||
from dbgpt.rag.knowledge.base import Knowledge, KnowledgeType | ||
from dbgpt.rag.knowledge.factory import KnowledgeFactory | ||
|
||
|
||
class KnowledgeOperator(MapOperator[Any, Any]): | ||
"""Knowledge Operator.""" | ||
"""Knowledge Factory Operator.""" | ||
|
||
metadata = ViewMetadata( | ||
label="Knowledge Factory Operator", | ||
name="knowledge_operator", | ||
category=OperatorCategory.RAG, | ||
description="The knowledge operator.", | ||
inputs=[ | ||
IOField.build_from( | ||
"knowledge datasource", | ||
"knowledge datasource", | ||
dict, | ||
"knowledge datasource", | ||
) | ||
], | ||
outputs=[ | ||
IOField.build_from( | ||
"Knowledge", | ||
"Knowledge", | ||
Knowledge, | ||
description="Knowledge", | ||
) | ||
], | ||
parameters=[ | ||
Parameter.build_from( | ||
label="datasource", | ||
name="datasource", | ||
type=str, | ||
optional=True, | ||
default="DOCUMENT", | ||
description="datasource", | ||
), | ||
Parameter.build_from( | ||
label="knowledge_type", | ||
name="knowledge type", | ||
type=str, | ||
optional=True, | ||
options=[ | ||
OptionValue( | ||
label="DOCUMENT", | ||
name="DOCUMENT", | ||
value=KnowledgeType.DOCUMENT.name, | ||
), | ||
OptionValue(label="URL", name="URL", value=KnowledgeType.URL.name), | ||
OptionValue( | ||
label="TEXT", name="TEXT", value=KnowledgeType.TEXT.name | ||
), | ||
], | ||
default=KnowledgeType.DOCUMENT.name, | ||
description="knowledge type", | ||
), | ||
], | ||
documentation_url="https://github.com/openai/openai-python", | ||
) | ||
|
||
def __init__( | ||
self, knowledge_type: Optional[KnowledgeType] = KnowledgeType.DOCUMENT, **kwargs | ||
self, | ||
datasource: Optional[str] = None, | ||
knowledge_type: Optional[str] = KnowledgeType.DOCUMENT.name, | ||
**kwargs | ||
): | ||
"""Init the query rewrite operator. | ||
Args: | ||
knowledge_type: (Optional[KnowledgeType]) The knowledge type. | ||
""" | ||
super().__init__(**kwargs) | ||
self._knowledge_type = knowledge_type | ||
self._datasource = datasource | ||
self._knowledge_type = KnowledgeType.get_by_value(knowledge_type) | ||
|
||
async def map(self, datasource: IN) -> Knowledge: | ||
"""knowledge operator.""" | ||
if self._datasource: | ||
datasource = self._datasource | ||
return await self.blocking_func_to_async( | ||
KnowledgeFactory.create, datasource, self._knowledge_type | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.