@aigne/example-workflow-reflection 1.1.0-beta.17 → 1.2.0
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.
- package/README.md +6 -5
- package/index.ts +9 -4
- package/package.json +5 -3
- package/usages.ts +6 -5
package/README.md
CHANGED
|
@@ -73,17 +73,17 @@ The following example demonstrates how to build a reflection workflow:
|
|
|
73
73
|
import assert from "node:assert";
|
|
74
74
|
import {
|
|
75
75
|
AIAgent,
|
|
76
|
-
|
|
76
|
+
OpenAIChatModel,
|
|
77
77
|
ExecutionEngine,
|
|
78
78
|
UserInputTopic,
|
|
79
79
|
UserOutputTopic,
|
|
80
|
-
} from "@aigne/core
|
|
80
|
+
} from "@aigne/core";
|
|
81
81
|
import { z } from "zod";
|
|
82
82
|
|
|
83
83
|
const { OPENAI_API_KEY } = process.env;
|
|
84
84
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
85
85
|
|
|
86
|
-
const model = new
|
|
86
|
+
const model = new OpenAIChatModel({
|
|
87
87
|
apiKey: OPENAI_API_KEY,
|
|
88
88
|
});
|
|
89
89
|
|
|
@@ -146,9 +146,10 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
149
|
+
engine.publish(UserInputTopic, "Write a function to find the sum of all even numbers in a list.");
|
|
149
150
|
|
|
150
|
-
const
|
|
151
|
-
console.log(
|
|
151
|
+
const { message } = await engine.subscribe(UserOutputTopic);
|
|
152
|
+
console.log(message);
|
|
152
153
|
// Output:
|
|
153
154
|
// {
|
|
154
155
|
// code: "def sum_of_even_numbers(numbers):\n \"\"\"Function to calculate the sum of all even numbers in a list.\"\"\"\n return sum(number for number in numbers if number % 2 == 0)",
|
package/index.ts
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
import assert from "node:assert";
|
|
4
4
|
import {
|
|
5
5
|
AIAgent,
|
|
6
|
-
ChatModelOpenAI,
|
|
7
6
|
ExecutionEngine,
|
|
7
|
+
OpenAIChatModel,
|
|
8
|
+
UserAgent,
|
|
8
9
|
UserInputTopic,
|
|
9
10
|
UserOutputTopic,
|
|
10
11
|
runChatLoopInTerminal,
|
|
11
|
-
} from "@aigne/core
|
|
12
|
+
} from "@aigne/core";
|
|
12
13
|
import { z } from "zod";
|
|
13
14
|
|
|
14
15
|
const { OPENAI_API_KEY } = process.env;
|
|
15
16
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
16
17
|
|
|
17
|
-
const model = new
|
|
18
|
+
const model = new OpenAIChatModel({
|
|
18
19
|
apiKey: OPENAI_API_KEY,
|
|
19
20
|
});
|
|
20
21
|
|
|
@@ -78,7 +79,11 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
78
79
|
|
|
79
80
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
80
81
|
|
|
81
|
-
const userAgent =
|
|
82
|
+
const userAgent = UserAgent.from({
|
|
83
|
+
context: engine,
|
|
84
|
+
publishTopic: UserInputTopic,
|
|
85
|
+
subscribeTopic: UserOutputTopic,
|
|
86
|
+
});
|
|
82
87
|
|
|
83
88
|
await runChatLoopInTerminal(userAgent, {
|
|
84
89
|
welcome: `Hello, I'm a coder with a reviewer. I can help you write code and get it reviewed.`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-reflection",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework to build a reflection workflow",
|
|
5
5
|
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
6
6
|
"homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/workflow-reflection",
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"openai": "^4.89.0",
|
|
19
20
|
"zod": "^3.24.2",
|
|
20
|
-
"@aigne/core
|
|
21
|
+
"@aigne/core": "^1.3.0"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
|
-
"start": "npx -y bun run index.ts"
|
|
24
|
+
"start": "npx -y bun run index.ts",
|
|
25
|
+
"lint": "tsc --noEmit"
|
|
24
26
|
}
|
|
25
27
|
}
|
package/usages.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import {
|
|
3
3
|
AIAgent,
|
|
4
|
-
ChatModelOpenAI,
|
|
5
4
|
ExecutionEngine,
|
|
5
|
+
OpenAIChatModel,
|
|
6
6
|
UserInputTopic,
|
|
7
7
|
UserOutputTopic,
|
|
8
|
-
} from "@aigne/core
|
|
8
|
+
} from "@aigne/core";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
|
|
11
11
|
const { OPENAI_API_KEY } = process.env;
|
|
12
12
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
13
13
|
|
|
14
|
-
const model = new
|
|
14
|
+
const model = new OpenAIChatModel({
|
|
15
15
|
apiKey: OPENAI_API_KEY,
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -74,9 +74,10 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
77
|
+
engine.publish(UserInputTopic, "Write a function to find the sum of all even numbers in a list.");
|
|
77
78
|
|
|
78
|
-
const
|
|
79
|
-
console.log(
|
|
79
|
+
const { message } = await engine.subscribe(UserOutputTopic);
|
|
80
|
+
console.log(message);
|
|
80
81
|
// Output:
|
|
81
82
|
// {
|
|
82
83
|
// code: "def sum_of_even_numbers(numbers):\n \"\"\"Function to calculate the sum of all even numbers in a list.\"\"\"\n return sum(number for number in numbers if number % 2 == 0)",
|