The easiest way to create an automation is to use the create command.

blocks create hello_world

This will create a new automation in the .blocks directory with the following structure:

.blocks/
    hello_world/
        main.py
        requirements.txt

Below are two example automations you can copy to get started. The first one is a simple hello world, and the second one is a more complex automation that leverages the litellm library to summarize a pull request in a single sentence.

from blocks import task, on, repo

@task(name="hello-world")
@on("github.pull_request")
def hello_world(event):
    pull_request_number = event.get("pull_request").get("number")
    # Comment 'Hello, World!' on the pull request
    repo.comment_on_pull_request(pull_request_number, "Hello, World!")

For the second automation, we’ve added the litellm library as a dependency to requirements.txt. To use gpt-4o, litellm expects an environment variable called OPENAI_API_KEY. You would need to get your own OpenAI API key and add it to your Environment Variables.