mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-10 21:39:33 +00:00
feat(awel): AWEL supports http trigger
This commit is contained in:
32
examples/awel/simple_dag_example.py
Normal file
32
examples/awel/simple_dag_example.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""AWEL: Simple dag example
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
curl -X GET http://127.0.0.1:5000/api/v1/awel/trigger/examples/hello\?name\=zhangsan
|
||||
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from pilot.awel import DAG, HttpTrigger, MapOperator
|
||||
|
||||
|
||||
class TriggerReqBody(BaseModel):
|
||||
name: str = Field(..., description="User name")
|
||||
age: int = Field(18, description="User age")
|
||||
|
||||
|
||||
class RequestHandleOperator(MapOperator[TriggerReqBody, str]):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
async def map(self, input_value: TriggerReqBody) -> str:
|
||||
print(f"Receive input value: {input_value}")
|
||||
return f"Hello, {input_value.name}, your age is {input_value.age}"
|
||||
|
||||
|
||||
with DAG("simple_dag_example") as dag:
|
||||
trigger = HttpTrigger("/examples/hello", request_body=TriggerReqBody)
|
||||
map_node = RequestHandleOperator()
|
||||
trigger >> map_node
|
Reference in New Issue
Block a user