feat:add rag awel operator view metadata. (#1174)

This commit is contained in:
Aries-ckt
2024-02-21 10:24:12 +08:00
committed by GitHub
parent c78bd22fda
commit 32e1554282
10 changed files with 527 additions and 6 deletions

View File

@@ -112,6 +112,7 @@ _OPERATOR_CATEGORY_DETAIL = {
"output_parser": _CategoryDetail("Output Parser", "Parse the output of LLM model"),
"common": _CategoryDetail("Common", "The common operator"),
"agent": _CategoryDetail("Agent", "The agent operator"),
"rag": _CategoryDetail("RAG", "The RAG operator"),
}
@@ -124,6 +125,7 @@ class OperatorCategory(str, Enum):
OUTPUT_PARSER = "output_parser"
COMMON = "common"
AGENT = "agent"
RAG = "rag"
def label(self) -> str:
"""Get the label of the category."""
@@ -163,6 +165,7 @@ _RESOURCE_CATEGORY_DETAIL = {
"common": _CategoryDetail("Common", "The common resource"),
"prompt": _CategoryDetail("Prompt", "The prompt resource"),
"agent": _CategoryDetail("Agent", "The agent resource"),
"rag": _CategoryDetail("RAG", "The resource"),
}
@@ -176,6 +179,7 @@ class ResourceCategory(str, Enum):
COMMON = "common"
PROMPT = "prompt"
AGENT = "agent"
RAG = "rag"
def label(self) -> str:
"""Get the label of the category."""

View File

@@ -1031,3 +1031,54 @@ class UserInputParsedOperator(MapOperator[CommonLLMHttpRequestBody, Dict[str, An
async def map(self, request_body: CommonLLMHttpRequestBody) -> Dict[str, Any]:
"""Map the request body to response body."""
return {self._key: request_body.messages}
class RequestedParsedOperator(MapOperator[CommonLLMHttpRequestBody, str]):
"""User input parsed operator."""
metadata = ViewMetadata(
label="Request Body Parsed To String Operator",
name="request_body_to_str__parsed_operator",
category=OperatorCategory.COMMON,
parameters=[
Parameter.build_from(
"Key",
"key",
str,
optional=True,
default="",
description="The key of the dict, link 'user_input'",
)
],
inputs=[
IOField.build_from(
"Request Body",
"request_body",
CommonLLMHttpRequestBody,
description="The request body of the API endpoint",
)
],
outputs=[
IOField.build_from(
"User Input String",
"user_input_str",
str,
description="The user input dict of the API endpoint",
)
],
description="User input parsed operator",
)
def __init__(self, key: str = "user_input", **kwargs):
"""Initialize a UserInputParsedOperator."""
self._key = key
super().__init__(**kwargs)
async def map(self, request_body: CommonLLMHttpRequestBody) -> str:
"""Map the request body to response body."""
dict_value = request_body.dict()
if not self._key or self._key not in dict_value:
raise ValueError(
f"Prefix key {self._key} is not a valid key of the request body"
)
return dict_value[self._key]