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

@@ -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]