@aigne/example-workflow-concurrency 1.1.0-beta.12

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,100 @@
1
+ # Workflow Concurrency Demo
2
+
3
+ This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) to build a concurrency 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-concurrency # 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-concurrency
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 concurrency workflow:
52
+
53
+ ```typescript
54
+ import assert from "node:assert";
55
+ import { AIAgent, ChatModelOpenAI, ExecutionEngine, parallel } 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 featureExtractor = AIAgent.from({
65
+ instructions: `\
66
+ You are a product analyst. Extract and summarize the key features of the product.
67
+
68
+ Product description:
69
+ {{product}}`,
70
+ outputKey: "features",
71
+ });
72
+
73
+ const audienceAnalyzer = AIAgent.from({
74
+ instructions: `\
75
+ You are a market researcher. Identify the target audience for the product.
76
+
77
+ Product description:
78
+ {{product}}`,
79
+ outputKey: "audience",
80
+ });
81
+
82
+ const engine = new ExecutionEngine({ model });
83
+
84
+ const result = await engine.run(
85
+ { product: "AIGNE is a No-code Generative AI Apps Engine" },
86
+ parallel(featureExtractor, audienceAnalyzer),
87
+ );
88
+
89
+ console.log(result);
90
+
91
+ // Output:
92
+ // {
93
+ // features: "**Product Name:** AIGNE\n\n**Product Type:** No-code Generative AI Apps Engine\n\n...",
94
+ // audience: "**Small to Medium Enterprises (SMEs)**: \n - Businesses that may not have extensive IT resources or budget for app development but are looking to leverage AI to enhance their operations or customer engagement.\n\n...",
95
+ // }
96
+ ```
97
+
98
+ ## License
99
+
100
+ This project is licensed under the MIT License.
package/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env npx -y bun
2
+
3
+ import assert from "node:assert";
4
+ import {
5
+ AIAgent,
6
+ ChatModelOpenAI,
7
+ ExecutionEngine,
8
+ parallel,
9
+ runChatLoopInTerminal,
10
+ } from "@aigne/core-next";
11
+
12
+ const { OPENAI_API_KEY } = process.env;
13
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
14
+
15
+ const model = new ChatModelOpenAI({
16
+ apiKey: OPENAI_API_KEY,
17
+ });
18
+
19
+ const featureExtractor = AIAgent.from({
20
+ instructions: `\
21
+ You are a product analyst. Extract and summarize the key features of the product.
22
+
23
+ Product description:
24
+ {{product}}`,
25
+ outputKey: "features",
26
+ });
27
+
28
+ const audienceAnalyzer = AIAgent.from({
29
+ instructions: `\
30
+ You are a market researcher. Identify the target audience for the product.
31
+
32
+ Product description:
33
+ {{product}}`,
34
+ outputKey: "audience",
35
+ });
36
+
37
+ const engine = new ExecutionEngine({ model });
38
+
39
+ const userAgent = await engine.run(parallel(featureExtractor, audienceAnalyzer));
40
+
41
+ await runChatLoopInTerminal(userAgent, {
42
+ welcome: `Hello, I'm a product analyst and market researcher. I can help you with extracting features and identifying target audience.`,
43
+ defaultQuestion: "AIGNE is a No-code Generative AI Apps Engine",
44
+ inputKey: "product",
45
+ });
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@aigne/example-workflow-concurrency",
3
+ "version": "1.1.0-beta.12",
4
+ "description": "A demonstration of using AIGNE Framework to build a concurrency workflow",
5
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
+ "homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/workflow-concurrency",
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.12"
21
+ },
22
+ "scripts": {
23
+ "start": "npx -y bun run index.ts"
24
+ }
25
+ }
package/usages.ts ADDED
@@ -0,0 +1,42 @@
1
+ import assert from "node:assert";
2
+ import { AIAgent, ChatModelOpenAI, ExecutionEngine, parallel } 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 featureExtractor = AIAgent.from({
12
+ instructions: `\
13
+ You are a product analyst. Extract and summarize the key features of the product.
14
+
15
+ Product description:
16
+ {{product}}`,
17
+ outputKey: "features",
18
+ });
19
+
20
+ const audienceAnalyzer = AIAgent.from({
21
+ instructions: `\
22
+ You are a market researcher. Identify the target audience for the product.
23
+
24
+ Product description:
25
+ {{product}}`,
26
+ outputKey: "audience",
27
+ });
28
+
29
+ const engine = new ExecutionEngine({ model });
30
+
31
+ const result = await engine.run(
32
+ { product: "AIGNE is a No-code Generative AI Apps Engine" },
33
+ parallel(featureExtractor, audienceAnalyzer),
34
+ );
35
+
36
+ console.log(result);
37
+
38
+ // Output:
39
+ // {
40
+ // features: "**Product Name:** AIGNE\n\n**Product Type:** No-code Generative AI Apps Engine\n\n...",
41
+ // audience: "**Small to Medium Enterprises (SMEs)**: \n - Businesses that may not have extensive IT resources or budget for app development but are looking to leverage AI to enhance their operations or customer engagement.\n\n...",
42
+ // }