1.3 Custom Operator
Your First Custom Operator
It is easy to create a custom operator in AWEL. In this section, we will create a custom operator that prints the "Hello, world!" message.
In most cases, you just need to inherit basic operators and override the corresponding methods.
Create a new file named hello_world_custom_operator.py in the awel_tutorial
directory and add the following code:
import asyncio
from dbgpt.core.awel import DAG, MapOperator
class HelloWorldOperator(MapOperator[str, None]):
async def map(self, x: str) -> None:
print(f"Hello, {x}!")
with DAG("awel_hello_world") as dag:
task = HelloWorldOperator()
asyncio.run(task.call(call_data="world"))
And run the following command to execute the code:
poetry run python awel_tutorial/hello_world_custom_operator.py
And you will see "Hello, world!" printed to the console.
Hello, world!