Skip to content

Commit df5e938

Browse files
committed
Swaps hello and goodbye
1 parent 64a8b9c commit df5e938

File tree

8 files changed

+67
-125
lines changed

8 files changed

+67
-125
lines changed

.github/workflows/npm-publish.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

examples/get-started/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "Restack get started example",
55
"scripts": {
6-
"dev": "tsx --watch src/services.ts",
6+
"dev": "tsx watch --include src src/services.ts",
77
"build": "tsc --build",
88
"schedule-workflow": "tsx scheduleWorkflow.ts",
99
"restack-up": "tsx restackUp.ts",

examples/get-started/readme.md

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,43 @@
1-
# Requirements
1+
# Restack Get Started
22

3-
- Node 20 or higher
4-
- pnpm or other package manager
3+
A sample repository, which demonstrates working with Restack Framework and optional Restack OpenAI integration.
54

6-
## Install Restack Studio
5+
For a full Typescript documentation refer to <https://docs.restack.io/libraries/typescript/reference>
76

8-
To install the Restack Studio, you can use Docker.
7+
## Requirements
98

10-
```bash
11-
docker run -d --pull always --name studio -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/restack:main
12-
```
13-
14-
## Start services
9+
- **Node 20+**, **pnpm** (or other package manager)
1510

16-
Where all your code is defined, including workflow steps.
17-
18-
add OPENAI_API_KEY in .env
11+
## Install dependencies and start services
1912

2013
```bash
2114
pnpm i
22-
2315
pnpm dev
2416
```
2517

26-
Your code will be running and syncing with Restack engine to execute workflows or functions.
27-
28-
## Schedule a workflow
18+
This will start Node.js app with two Restack Services. Your code will be running and syncing with Restack engine to execute workflows or functions.
2919

30-
In another shell:
20+
## Start Restack Studio
3121

32-
pnpm schedule
22+
To start the Restack Studio, you can use Docker.
3323

34-
Will schedule to start example workflow immediately.
24+
```bash
25+
docker run -d --pull always --name studio -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/restack:main
26+
```
3527

36-
## Architecture
28+
## Schedule a demo workflow
3729

38-
```mermaid
39-
flowchart TD
40-
C[fa:fa-bolt scheduleWorkflow client] -->|registers workflow with schedule| E{Restack Engine}
41-
E --> |queries results| C
42-
E -->|pulls queue with input| P1[fa:fa-ship restack pod]
43-
E -->|orchestrates with rate limit| P2[fa:fa-ship openai pod]
44-
P1 -->|runs| W[fa:fa-th-list example workflow]
45-
P1 -->|runs| Go[fa:fa-code goodbye function]
46-
P2 -->|runs| Gr[fa:fa-code greet function]
47-
P1 -->|sends status + output | E
48-
P2 -->|sends status output | E
30+
```bash
31+
pnpm schedule-workflow
4932
```
5033

51-
## Deploy on Restack
34+
This will trigger a demo Workflow - a greeting, which is a simple function and goodbye, which uses [@restackio/integration-openai](https://www.npmjs.com/package/@restackio/integrations-openai).
35+
36+
## Deploy on Restack Cloud
5237

38+
``` bash
5339
pnpm restack-up
40+
```
5441

5542
To deploy the application on Restack, you can use the provided `restackUp.ts` script. This script utilizes the Restack Cloud SDK to define and deploy your application stack. It sets up the necessary environment variables and configures the application for deployment.
5643

examples/get-started/src/functions/goodbye.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface Input {
2+
name: string;
3+
}
4+
5+
interface Output {
6+
message: string;
7+
}
8+
9+
export async function hello(input: Input): Promise<Output> {
10+
return { message: `Hello, ${input.name}!` };
11+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./goodbye";
1+
export * from "./hello";

examples/get-started/src/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { goodbye } from "./functions";
1+
import { hello } from "./functions";
22
import { openaiService } from "@restackio/integrations-openai";
33
import { client } from "./client";
44

@@ -9,7 +9,7 @@ async function services() {
99
// Start service with current workflows and functions
1010
client.startService({
1111
workflowsPath,
12-
functions: { goodbye },
12+
functions: { hello },
1313
}),
1414
// Start the openai service
1515
openaiService({ client }),

examples/get-started/src/workflows/hello.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,47 @@ import * as functions from "../functions";
88
interface Input {
99
name: string;
1010
}
11+
const GoodbyeMessageSchema = z.object({
12+
message: z.string().describe("The goodbye message."),
13+
});
1114

12-
export async function helloWorkflow({ name }: Input) {
13-
const userContent = `Greet this person: ${name}. In 4 words or less.`;
15+
const goodbyeJsonSchema = {
16+
name: "goodbye",
17+
schema: zodToJsonSchema(GoodbyeMessageSchema),
18+
};
1419

15-
const MessageSchema = z.object({
16-
message: z.string().describe("The greeting message."),
20+
export async function helloWorkflow({ name }: Input) {
21+
// Step 1: Create hello message with simple function
22+
const { message: greetMessage } = await step<typeof functions>({}).hello({
23+
name,
1724
});
1825

19-
const jsonSchema = {
20-
name: "greet",
21-
schema: zodToJsonSchema(MessageSchema),
22-
};
23-
24-
// Step 1 create greeting message with openai
25-
const openaiOutput = await step<typeof openaiFunctions>({
26-
taskQueue: openaiTaskQueue,
27-
}).openaiChatCompletionsBase({
28-
userContent,
29-
jsonSchema,
30-
});
26+
log.info("Hello", { greetMessage });
3127

32-
const greetMessage = openaiOutput.result.choices[0].message.content ?? "";
33-
const greetCost = openaiOutput.cost;
28+
// Step 2: Create goodbye message with our OpenAI integration (requires OPENAI_API_KEY in .env)
29+
let goodbyeMessage;
30+
try {
31+
const userContent = `Say goodbye to this person: ${name}. In 4 words or less.`;
3432

35-
log.info("greeted", { greetMessage });
33+
const openaiOutput = await step<typeof openaiFunctions>({
34+
taskQueue: openaiTaskQueue,
35+
}).openaiChatCompletionsBase({
36+
userContent,
37+
jsonSchema: goodbyeJsonSchema,
38+
});
3639

37-
// Step 2 create goodbye message with simple function
38-
const { message: goodbyeMessage } = await step<typeof functions>({}).goodbye({
39-
name,
40-
});
40+
goodbyeMessage = openaiOutput.result.choices[0].message.content ?? "";
4141

42-
log.info("goodbye", { goodbyeMessage });
42+
log.info("Goodbye", { goodbyeMessage });
43+
} catch (error: any) {
44+
if (error.failure.cause.message.includes("API key is required")) {
45+
log.warn("Provide an OpenAI API key to use the OpenAI integration", {
46+
error,
47+
});
48+
}
49+
}
4350

4451
return {
45-
messages: [greetMessage, goodbyeMessage],
46-
cost: greetCost,
52+
messages: { greetMessage, goodbyeMessage },
4753
};
4854
}

0 commit comments

Comments
 (0)