-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from restackio/quickstartEndpoints
Quickstart with endpoint
- Loading branch information
Showing
17 changed files
with
121 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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,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. | ||
|
||
 | ||
|
||
### 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) |
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
5 changes: 3 additions & 2 deletions
5
get_started/schedule_workflow.py → quickstart/schedule_workflow.py
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
File renamed without changes.
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,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) |
File renamed without changes.
8 changes: 6 additions & 2 deletions
8
get_started/src/functions/function.py → quickstart/src/functions/function.py
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 |
---|---|---|
@@ -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.
File renamed without changes.
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,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 | ||
|
||
|