Skip to content

Commit d289bcf

Browse files
committed
chore: bump hatchet version and clarify readme examples
1 parent 0a36220 commit d289bcf

17 files changed

Lines changed: 171 additions & 97 deletions

File tree

fast-api-react/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,36 @@ This is an example project demonstrating how to use Hatchet with FastAPI.
66

77
Before running this project, make sure you have the following:
88

9-
1. Python 3.7 or higher installed on your machine.
9+
1. Python 3.10 or higher installed on your machine.
1010
2. Poetry package manager installed. You can install it by running `pip install poetry`, or by following instructions in the [Poetry Docs](https://python-poetry.org/docs/#installation)
1111
3. (Optional) If you would like to run the example frontend, Node which can be installed from the [node website](https://nodejs.org/en/download)
1212

1313
## Setup
1414

1515
1. Create a `.env` file in the `./backend` directory and set the required environment variables. This requires the `HATCHET_CLIENT_TOKEN` variable created in the [Getting Started README](../README.md). You will also need, a `OPENAI_API_KEY` which can be created on the [OpenAI Website](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key).
1616

17+
**If you're running Hatchet locally without TLS:**
18+
1719
```
1820
HATCHET_CLIENT_TLS_STRATEGY=none
1921
HATCHET_CLIENT_TOKEN="<token>"
2022
OPENAI_API_KEY="<openai-key>"
2123
```
2224

25+
**If you're using Hatchet Cloud:**
26+
27+
```
28+
HATCHET_CLIENT_TOKEN="<token>"
29+
OPENAI_API_KEY="<openai-key>"
30+
```
31+
2332
2. Open a terminal and navigate to the project backend directory (`/fast-api-react/backend`).
2433

2534
3. Run the following command to install the project dependencies:
2635

27-
```shell
28-
poetry install
29-
```
36+
```shell
37+
poetry install
38+
```
3039

3140
### Running the API
3241

fast-api-react/backend/poetry.lock

Lines changed: 35 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fast-api-react/backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ openai = "^1.11.0"
1818
beautifulsoup4 = "^4.12.3"
1919
requests = "^2.31.0"
2020
urllib3 = "2.2.1"
21-
hatchet-sdk = "0.20.0"
21+
hatchet-sdk = "^0.26.0"
2222

2323
[build-system]
2424
requires = ["poetry-core"]

fast-api-react/backend/src/api/main.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
from fastapi import FastAPI
23
from fastapi.middleware.cors import CORSMiddleware
34
from fastapi.responses import StreamingResponse
@@ -13,42 +14,42 @@
1314
load_dotenv()
1415

1516
app = FastAPI()
17+
1618
hatchet = Hatchet()
1719

1820

1921
origins = [
20-
"http://localhost:3001",
21-
"localhost:3001"
22+
"http://localhost:3000",
23+
"localhost:3000"
2224
]
2325

2426

2527
app.add_middleware(
2628
CORSMiddleware,
27-
allow_origins=["*"],
29+
allow_origins=origins,
2830
allow_credentials=True,
2931
allow_methods=["*"],
3032
allow_headers=["*"]
3133
)
3234

3335

3436
@app.post("/message")
35-
def message(data: MessageRequest):
37+
async def message(data: MessageRequest):
3638
''' This endpoint is called by the client to start a message generation workflow. '''
37-
messageId = hatchet.client.admin.run_workflow("BasicRagWorkflow", {
39+
workflowRun = await hatchet.client.admin.aio.run_workflow("BasicRagWorkflow", {
3840
"request": data.model_dump()
3941
})
4042

41-
# normally, we'd save the workflowRunId to a database and return a reference to the client
42-
# for this simple example, we just return the workflowRunId
43-
44-
return {"messageId": messageId}
43+
# normally, we'd save the workflow_run_id to a database and return a reference to the client
44+
# for this simple example, we just return the workflow_run_id
4545

46+
return {"messageId": workflowRun.workflow_run_id}
4647

47-
def event_stream_generator(workflowRunId):
48+
async def event_stream_generator(workflowRunId):
4849
''' This helper function is a generator that yields events from the Hatchet event stream. '''
49-
stream = hatchet.client.listener.stream(workflowRunId)
50+
workflowRun = hatchet.client.admin.get_workflow_run(workflowRunId)
5051

51-
for event in stream:
52+
async for event in workflowRun.stream():
5253
''' you can filter and transform event data here that will be sent to the client'''
5354
data = json.dumps({
5455
"type": event.type,
@@ -57,6 +58,15 @@ def event_stream_generator(workflowRunId):
5758
})
5859
yield "data: " + data + "\n\n"
5960

61+
result = await workflowRun.result()
62+
63+
data = json.dumps({
64+
"type": "result",
65+
"payload": result,
66+
"messageId": workflowRunId
67+
})
68+
69+
yield "data: " + data + "\n\n"
6070

6171
@app.get("/message/{messageId}")
6272
async def stream(messageId: str):

simple-examples/README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@ This is an example project demonstrating how to use Hatchet with Python.
66

77
Before running this project, make sure you have the following:
88

9-
1. Python 3.7 or higher installed on your machine.
9+
1. Python 3.10 or higher installed on your machine.
1010
2. Poetry package manager installed. You can install it by running `pip install poetry`, or by following instructions in the [Poetry Docs](https://python-poetry.org/docs/#installation)
1111

1212
## Setup
1313

1414
1. Create a `.env` file in the `./backend` directory and set the required environment variables. This requires the `HATCHET_CLIENT_TOKEN` variable created in the [Getting Started README](../README.md). If you would like to try the Generative AI examples in [./src/genai](./src/genai) You will also need, a `OPENAI_API_KEY` which can be created on the [OpenAI Website](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key).
1515

16+
**If you're running Hatchet locally without TLS:**
17+
1618
```
1719
HATCHET_CLIENT_TLS_STRATEGY=none
1820
HATCHET_CLIENT_TOKEN="<token>"
1921
OPENAI_API_KEY="<openai-key>" # (OPTIONAL) only required to run examples in [./src/genai](./src/genai)
2022
```
2123

24+
**If you're using Hatchet Cloud:**
25+
26+
```
27+
HATCHET_CLIENT_TOKEN="<token>"
28+
OPENAI_API_KEY="<openai-key>" # (OPTIONAL) only required to run examples in [./src/genai](./src/genai)
29+
```
30+
2231
2. Open a terminal and navigate to the project root directory (`/simple-examples`).
2332

2433
3. Run the following command to install the project dependencies:
2534

26-
```shell
27-
poetry install
28-
```
35+
```shell
36+
poetry install
37+
```
2938

3039
### Running the Hatchet Worker
3140

32-
In a separate terminal, start the the Hatchet worker by running the following command:
41+
Next, start the the Hatchet worker by running the following command:
3342

3443
```shell
3544
poetry run hatchet
@@ -50,10 +59,11 @@ The project contains example workflows in the [`./src`](./src) directory. These
5059
The project includes a variety of basic workflows to demonstrate Hatchet's core capabilities, each showcasing different features:
5160

5261
1. **[Simple Workflow](./src/simple/worker.py)**: Demonstrates a straightforward process flow, showcasing the basics of setting up a workflow in Hatchet.
53-
2. **[Concurrency Limit Workflow](./src/concurrency_limit/worker.py)**: Shows how to manage concurrency limits within workflows to ensure that only a certain number of instances run simultaneously.
54-
3. **[Directed Acyclic Graph (DAG) Workflow](./src/dag/worker.py)**: Illustrates setting up workflows with dependencies that form a Directed Acyclic Graph, demonstrating the advanced orchestration capabilities of Hatchet.
55-
4. **[Manual Trigger Workflow](./src/manual_trigger/worker.py)**: Explains how to initiate workflows manually, offering control over workflow execution triggers.
56-
5. **[Timeout Workflow](./src/timeout/worker.py)**: Demonstrates handling timeout scenarios within workflows, ensuring that long-running or stalled processes are appropriately managed.
62+
2. **[Async Workflow](./src/async_workflow/worker.py)**: An example of using `async def` together with `asyncio.sleep`.
63+
3. **[Concurrency Limit Workflow](./src/concurrency_limit/worker.py)**: Shows how to manage concurrency limits within workflows to ensure that only a certain number of instances run simultaneously.
64+
4. **[Directed Acyclic Graph (DAG) Workflow](./src/dag/worker.py)**: Illustrates setting up workflows with dependencies that form a Directed Acyclic Graph, demonstrating the advanced orchestration capabilities of Hatchet.
65+
5. **[Manual Trigger Workflow](./src/manual_trigger/worker.py)**: Explains how to initiate workflows manually, offering control over workflow execution triggers.
66+
6. **[Timeout Workflow](./src/timeout/worker.py)**: Demonstrates handling timeout scenarios within workflows, ensuring that long-running or stalled processes are appropriately managed.
5767

5868
#### Generative AI Workflows
5969

@@ -62,6 +72,6 @@ For more complex use cases, the project includes examples that integrate with Op
6272
1. **[Simple Response Generation](./src/genai/simple.py)**: A single-step workflow that makes a request to OpenAI, showcasing how to incorporate AI services into Hatchet workflows.
6373
2. **[Basic Retrieval Augmented Generation (BasicRag)](./src/genai/basicrag.py)**: A multi-step workflow that involves loading website content with Beautiful Soup, reasoning about the information, and generating a response with OpenAI, demonstrating the potential for complex, AI-driven processes.
6474

65-
### Exposing the workflows via a RestAPI
75+
### Exposing the workflows via FastAPI
6676

6777
For a more complete example of how you might use Hatchet as part of a deployed production service, check out the [FastAPI Example](../fast-api-react/README.md)

simple-examples/poetry.lock

Lines changed: 35 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simple-examples/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ python-dotenv = "^1.0.0"
1414
openai = "^1.12.0"
1515
beautifulsoup4 = "^4.12.3"
1616
requests = "^2.31.0"
17-
hatchet-sdk = "0.20.0"
17+
hatchet-sdk = "^0.26.0"
1818

1919
[build-system]
2020
requires = ["poetry-core"]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)