Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions get_started/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions get_started/src/client.py

This file was deleted.

15 changes: 0 additions & 15 deletions get_started/src/workflows/workflow.py

This file was deleted.

File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Restack AI - Quickstart

This repository contains a quickstart for Restack.
It demonstrates how to set up a basic workflow and functions.

## Prerequisites

- Docker (for running Restack)
- Python 3.10 or higher

## Start Restack

To start the Restack, use the following Docker command:

```bash
docker run -d --pull always --name restack -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/restack:main
```

## Install dependencies and start services

```bash
poetry env use 3.10
```

```bash
poetry shell
```

```bash
poetry install
```

```bash
poetry env info # Optional: copy the interpreter path to use in your IDE (e.g. Cursor, VSCode, etc.)
```

```bash
poetry run dev
```

## Run workflows

### from UI

You can run workflows from the UI by clicking the "Run" button.

![Run workflows from UI](./screenshot-quickstart.png)

### from API

You can run workflows from the API by using the generated endpoint:

`POST http://localhost:6233/api/workflows/GreetingWorkflow`

### from any client

You can run workflows with any client connected to Restack, for example:

```bash
poetry run schedule
```

executes `schedule_workflow.py` which will connect to Restack and execute the `GreetingWorkflow` workflow.

## Deploy on Restack Cloud

To deploy the application on Restack, you can create an account at [https://console.restack.io](https://console.restack.io)
10 changes: 4 additions & 6 deletions get_started/pyproject.toml → quickstart/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Project metadata
[tool.poetry]
name = "get_started"
name = "quickstart"
version = "0.0.1"
description = "A simple example to get started with the restack-ai SDK"
description = "A quickstart for Restack"
authors = [
"Restack Team <service@restack.io>",
]
Expand All @@ -11,13 +11,11 @@ packages = [{include = "src"}]

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
restack-ai = "^0.0.48"
watchfiles = "^1.0.0"

[tool.poetry.dev-dependencies]
pytest = "6.2" # Optional: Add if you want to include tests in your example
pydantic = "^2.10.4"

# Build system configuration
restack-ai = "^0.0.52"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from restack_ai import Restack
from restack_ai.restack import ScheduleSpec, ScheduleCalendarSpec, ScheduleRange

from src.workflows.workflow import GreetingWorkflowInput
async def main():

client = Restack()
Expand All @@ -11,6 +11,7 @@ async def main():
await client.schedule_workflow(
workflow_name="GreetingWorkflow",
workflow_id=workflow_id,
input=GreetingWorkflowInput(name="Bob"),
schedule=ScheduleSpec(
calendars=[ScheduleCalendarSpec(
day_of_week=[ScheduleRange(start=1)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from restack_ai import Restack
from restack_ai.restack import ScheduleSpec, ScheduleIntervalSpec
from datetime import timedelta

from src.workflows.workflow import GreetingWorkflowInput
async def main():

client = Restack()
Expand All @@ -12,6 +12,7 @@ async def main():
await client.schedule_workflow(
workflow_name="GreetingWorkflow",
workflow_id=workflow_id,
input=GreetingWorkflowInput(name="Bob"),
schedule=ScheduleSpec(
intervals=[ScheduleIntervalSpec(
every=timedelta(minutes=10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import asyncio
import time
from restack_ai import Restack

from src.workflows.workflow import GreetingWorkflowInput
async def main():

client = Restack()

workflow_id = f"{int(time.time() * 1000)}-GreetingWorkflow"
run_id = await client.schedule_workflow(
workflow_name="GreetingWorkflow",
workflow_id=workflow_id
workflow_id=workflow_id,
input=GreetingWorkflowInput(name="Bob")
)

await client.get_workflow_result(
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions quickstart/src/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from restack_ai import Restack
from restack_ai.restack import CloudConnectionOptions
from dotenv import load_dotenv
# Load environment variables from a .env file
load_dotenv()


engine_id = os.getenv("RESTACK_ENGINE_ID")
address = os.getenv("RESTACK_ENGINE_ADDRESS")
api_key = os.getenv("RESTACK_ENGINE_API_KEY")

connection_options = CloudConnectionOptions(
engine_id=engine_id,
address=address,
api_key=api_key,
)
client = Restack(connection_options)
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from restack_ai.function import function, log
from pydantic import BaseModel

class WelcomeInput(BaseModel):
name: str

@function.defn()
async def welcome(input: str) -> str:
async def welcome(input: WelcomeInput) -> str:
try:
log.info("welcome function started", input=input)
return f"Hello, {input}!"
return f"Hello, {input.name}!"
except Exception as e:
log.error("welcome function failed", error=e)
raise e
File renamed without changes.
19 changes: 19 additions & 0 deletions quickstart/src/workflows/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from datetime import timedelta
from pydantic import BaseModel, Field
from restack_ai.workflow import workflow, import_functions, log
with import_functions():
from src.functions.function import welcome, WelcomeInput

class GreetingWorkflowInput(BaseModel):
name: str = Field(default='Bob')

@workflow.defn()
class GreetingWorkflow:
@workflow.run
async def run(self, input: GreetingWorkflowInput):
log.info("GreetingWorkflow started")
result = await workflow.step(welcome, input=WelcomeInput(name=input.name), start_to_close_timeout=timedelta(seconds=120))
log.info("GreetingWorkflow completed", result=result)
return result