@aigne/example-workflow-sequential 1.1.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ # Change the name of this file to .env.local and fill in the following values
2
+
3
+ DEBUG=aigne:mcp
4
+
5
+ OPENAI_API_KEY="" # Your OpenAI API key
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Workflow Router Demo
2
+
3
+ This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) to build a sequential workflow.
4
+
5
+ ## Prerequisites
6
+
7
+ - [Node.js](https://nodejs.org) and npm installed on your machine
8
+ - [OpenAI API key](https://platform.openai.com/api-keys) used to interact with OpenAI API
9
+ - [Pnpm](https://pnpm.io) [Optional] if you want to run the example from source code
10
+
11
+ ## Try without Installation
12
+
13
+ ```bash
14
+ export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # setup your OpenAI API key
15
+
16
+ npx -y @aigne/example-workflow-sequential # run the example
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ ### Clone the Repository
22
+
23
+ ```bash
24
+ git clone https://github.com/AIGNE-io/aigne-framework
25
+ ```
26
+
27
+ ### Install Dependencies
28
+
29
+ ```bash
30
+ cd aigne-framework/examples/workflow-sequential
31
+
32
+ pnpm install
33
+ ```
34
+
35
+ ### Setup Environment Variables
36
+
37
+ Setup your OpenAI API key in the `.env.local` file:
38
+
39
+ ```bash
40
+ OPENAI_API_KEY="" # setup your OpenAI API key here
41
+ ```
42
+
43
+ ### Run the Example
44
+
45
+ ```bash
46
+ pnpm start
47
+ ```
48
+
49
+ ## Example
50
+
51
+ The following example demonstrates how to build a sequential workflow:
52
+
53
+ ```typescript
54
+ import assert from "node:assert";
55
+ import { AIAgent, ChatModelOpenAI, ExecutionEngine } from "@aigne/core-next";
56
+
57
+ const { OPENAI_API_KEY } = process.env;
58
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
59
+
60
+ const model = new ChatModelOpenAI({
61
+ apiKey: OPENAI_API_KEY,
62
+ });
63
+
64
+ const conceptExtractor = AIAgent.from({
65
+ instructions: `\
66
+ You are a marketing analyst. Give a product description, identity:
67
+ - Key features
68
+ - Target audience
69
+ - Unique selling points
70
+
71
+ Product description:
72
+ {{product}}`,
73
+ outputKey: "concept",
74
+ });
75
+
76
+ const writer = AIAgent.from({
77
+ instructions: `\
78
+ You are a marketing copywriter. Given a block of text describing features, audience, and USPs,
79
+ compose a compelling marketing copy (like a newsletter section) that highlights these points.
80
+ Output should be short (around 150 words), output just the copy as a single text block.
81
+
82
+ Below is the info about the product:
83
+ {{concept}}`,
84
+ outputKey: "draft",
85
+ });
86
+
87
+ const formatProof = AIAgent.from({
88
+ instructions: `\
89
+ You are an editor. Given the draft copy, correct grammar, improve clarity, ensure consistent tone,
90
+ give format and make it polished. Output the final improved copy as a single text block.
91
+
92
+ Draft copy:
93
+ {{draft}}`,
94
+ outputKey: "content",
95
+ });
96
+
97
+ const engine = new ExecutionEngine({ model });
98
+
99
+ const result = await engine.run(
100
+ { product: "AIGNE is a No-code Generative AI Apps Engine" },
101
+ conceptExtractor,
102
+ writer,
103
+ formatProof,
104
+ );
105
+
106
+ console.log(result);
107
+
108
+ // Output:
109
+ // {
110
+ // concept: "**Product Description: AIGNE - No-code Generative AI Apps Engine**\n\nAIGNE is a cutting-edge No-code Generative AI Apps Engine designed to empower users to seamlessly create ...",
111
+ // draft: "Unlock the power of creation with AIGNE, the revolutionary No-code Generative AI Apps Engine! Whether you're a small business looking to streamline operations, an entrepreneur ...",
112
+ // content: "Unlock the power of creation with AIGNE, the revolutionary No-Code Generative AI Apps Engine! Whether you are a small business aiming to streamline operations, an entrepreneur ...",
113
+ // }
114
+
115
+ ```
116
+
117
+ ## License
118
+
119
+ This project is licensed under the MIT License.
package/index.ts ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env npx -y bun
2
+
3
+ import assert from "node:assert";
4
+ import { AIAgent, ChatModelOpenAI, ExecutionEngine, runChatLoopInTerminal } from "@aigne/core-next";
5
+
6
+ const { OPENAI_API_KEY } = process.env;
7
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
8
+
9
+ const model = new ChatModelOpenAI({
10
+ apiKey: OPENAI_API_KEY,
11
+ });
12
+
13
+ const conceptExtractor = AIAgent.from({
14
+ instructions: `\
15
+ You are a marketing analyst. Give a product description, identity:
16
+ - Key features
17
+ - Target audience
18
+ - Unique selling points
19
+
20
+ Product description:
21
+ {{product}}`,
22
+ outputKey: "concept",
23
+ });
24
+
25
+ const writer = AIAgent.from({
26
+ instructions: `\
27
+ You are a marketing copywriter. Given a block of text describing features, audience, and USPs,
28
+ compose a compelling marketing copy (like a newsletter section) that highlights these points.
29
+ Output should be short (around 150 words), output just the copy as a single text block.
30
+
31
+ Below is the info about the product:
32
+ {{concept}}`,
33
+ outputKey: "draft",
34
+ });
35
+
36
+ const formatProof = AIAgent.from({
37
+ instructions: `\
38
+ You are an editor. Given the draft copy, correct grammar, improve clarity, ensure consistent tone,
39
+ give format and make it polished. Output the final improved copy as a single text block.
40
+
41
+ Draft copy:
42
+ {{draft}}`,
43
+ outputKey: "content",
44
+ });
45
+
46
+ const engine = new ExecutionEngine({ model });
47
+
48
+ const userAgent = await engine.run(conceptExtractor, writer, formatProof);
49
+
50
+ await runChatLoopInTerminal(userAgent, {
51
+ welcome: `Hello, I'm a marketing assistant. I can help you with product descriptions, marketing copy, and editing.`,
52
+ defaultQuestion: "AIGNE is a No-code Generative AI Apps Engine",
53
+ inputKey: "product",
54
+ });
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@aigne/example-workflow-sequential",
3
+ "version": "1.1.0-beta.11",
4
+ "description": "A demonstration of using AIGNE Framework to build a sequential workflow",
5
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
+ "homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/workflow-sequential",
7
+ "license": "ISC",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/AIGNE-io/aigne-framework"
11
+ },
12
+ "bin": "index.ts",
13
+ "files": [
14
+ ".env.local.example",
15
+ "*.ts",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {
19
+ "zod": "^3.24.2",
20
+ "@aigne/core-next": "^1.1.0-beta.11"
21
+ },
22
+ "scripts": {
23
+ "start": "npx -y bun run index.ts"
24
+ }
25
+ }
package/usages.ts ADDED
@@ -0,0 +1,60 @@
1
+ import assert from "node:assert";
2
+ import { AIAgent, ChatModelOpenAI, ExecutionEngine } from "@aigne/core-next";
3
+
4
+ const { OPENAI_API_KEY } = process.env;
5
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
6
+
7
+ const model = new ChatModelOpenAI({
8
+ apiKey: OPENAI_API_KEY,
9
+ });
10
+
11
+ const conceptExtractor = AIAgent.from({
12
+ instructions: `\
13
+ You are a marketing analyst. Give a product description, identity:
14
+ - Key features
15
+ - Target audience
16
+ - Unique selling points
17
+
18
+ Product description:
19
+ {{product}}`,
20
+ outputKey: "concept",
21
+ });
22
+
23
+ const writer = AIAgent.from({
24
+ instructions: `\
25
+ You are a marketing copywriter. Given a block of text describing features, audience, and USPs,
26
+ compose a compelling marketing copy (like a newsletter section) that highlights these points.
27
+ Output should be short (around 150 words), output just the copy as a single text block.
28
+
29
+ Below is the info about the product:
30
+ {{concept}}`,
31
+ outputKey: "draft",
32
+ });
33
+
34
+ const formatProof = AIAgent.from({
35
+ instructions: `\
36
+ You are an editor. Given the draft copy, correct grammar, improve clarity, ensure consistent tone,
37
+ give format and make it polished. Output the final improved copy as a single text block.
38
+
39
+ Draft copy:
40
+ {{draft}}`,
41
+ outputKey: "content",
42
+ });
43
+
44
+ const engine = new ExecutionEngine({ model });
45
+
46
+ const result = await engine.run(
47
+ { product: "AIGNE is a No-code Generative AI Apps Engine" },
48
+ conceptExtractor,
49
+ writer,
50
+ formatProof,
51
+ );
52
+
53
+ console.log(result);
54
+
55
+ // Output:
56
+ // {
57
+ // concept: "**Product Description: AIGNE - No-code Generative AI Apps Engine**\n\nAIGNE is a cutting-edge No-code Generative AI Apps Engine designed to empower users to seamlessly create ...",
58
+ // draft: "Unlock the power of creation with AIGNE, the revolutionary No-code Generative AI Apps Engine! Whether you're a small business looking to streamline operations, an entrepreneur ...",
59
+ // content: "Unlock the power of creation with AIGNE, the revolutionary No-Code Generative AI Apps Engine! Whether you are a small business aiming to streamline operations, an entrepreneur ...",
60
+ // }