-
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.
- Loading branch information
Showing
16 changed files
with
548 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""AWEL: Simple rag example | ||
Example: | ||
.. code-block:: shell | ||
curl -X POST http://127.0.0.1:5000/api/v1/awel/trigger/examples/simple_rag \ | ||
-H "Content-Type: application/json" -d '{ | ||
"conv_uid": "36f0e992-8825-11ee-8638-0242ac150003", | ||
"model_name": "proxyllm", | ||
"chat_mode": "chat_knowledge", | ||
"user_input": "What is DB-GPT?", | ||
"select_param": "default" | ||
}' | ||
""" | ||
|
||
from pilot.awel import HttpTrigger, DAG, MapOperator | ||
from pilot.scene.operator._experimental import ( | ||
ChatContext, | ||
PromptManagerOperator, | ||
ChatHistoryStorageOperator, | ||
ChatHistoryOperator, | ||
EmbeddingEngingOperator, | ||
BaseChatOperator, | ||
) | ||
from pilot.scene.base import ChatScene | ||
from pilot.openapi.api_view_model import ConversationVo | ||
from pilot.model.base import ModelOutput | ||
from pilot.model.operator.model_operator import ModelOperator | ||
|
||
|
||
class RequestParseOperator(MapOperator[ConversationVo, ChatContext]): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
async def map(self, input_value: ConversationVo) -> ChatContext: | ||
return ChatContext( | ||
current_user_input=input_value.user_input, | ||
model_name=input_value.model_name, | ||
chat_session_id=input_value.conv_uid, | ||
select_param=input_value.select_param, | ||
chat_scene=ChatScene.ChatKnowledge, | ||
) | ||
|
||
|
||
with DAG("simple_rag_example") as dag: | ||
trigger_task = HttpTrigger( | ||
"/examples/simple_rag", methods="POST", request_body=ConversationVo | ||
) | ||
req_parse_task = RequestParseOperator() | ||
prompt_task = PromptManagerOperator() | ||
history_storage_task = ChatHistoryStorageOperator() | ||
history_task = ChatHistoryOperator() | ||
embedding_task = EmbeddingEngingOperator() | ||
chat_task = BaseChatOperator() | ||
model_task = ModelOperator() | ||
output_parser_task = MapOperator(lambda out: out.to_dict()["text"]) | ||
|
||
( | ||
trigger_task | ||
>> req_parse_task | ||
>> prompt_task | ||
>> history_storage_task | ||
>> history_task | ||
>> embedding_task | ||
>> chat_task | ||
>> model_task | ||
>> output_parser_task | ||
) |
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
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.