@aigne/example-workflow-reflection 1.1.0 → 1.2.1
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 -10
- package/index.ts +9 -10
- package/package.json +5 -3
- package/usages.ts +6 -10
package/README.md
CHANGED
|
@@ -71,19 +71,14 @@ The following example demonstrates how to build a reflection workflow:
|
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
73
|
import assert from "node:assert";
|
|
74
|
-
import {
|
|
75
|
-
|
|
76
|
-
ChatModelOpenAI,
|
|
77
|
-
ExecutionEngine,
|
|
78
|
-
UserInputTopic,
|
|
79
|
-
UserOutputTopic,
|
|
80
|
-
} from "@aigne/core-next";
|
|
74
|
+
import { AIAgent, ExecutionEngine, UserInputTopic, UserOutputTopic } from "@aigne/core";
|
|
75
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
81
76
|
import { z } from "zod";
|
|
82
77
|
|
|
83
78
|
const { OPENAI_API_KEY } = process.env;
|
|
84
79
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
85
80
|
|
|
86
|
-
const model = new
|
|
81
|
+
const model = new OpenAIChatModel({
|
|
87
82
|
apiKey: OPENAI_API_KEY,
|
|
88
83
|
});
|
|
89
84
|
|
|
@@ -146,9 +141,10 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
146
141
|
});
|
|
147
142
|
|
|
148
143
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
144
|
+
engine.publish(UserInputTopic, "Write a function to find the sum of all even numbers in a list.");
|
|
149
145
|
|
|
150
|
-
const
|
|
151
|
-
console.log(
|
|
146
|
+
const { message } = await engine.subscribe(UserOutputTopic);
|
|
147
|
+
console.log(message);
|
|
152
148
|
// Output:
|
|
153
149
|
// {
|
|
154
150
|
// 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
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env npx -y bun
|
|
2
2
|
|
|
3
3
|
import assert from "node:assert";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ExecutionEngine,
|
|
8
|
-
UserInputTopic,
|
|
9
|
-
UserOutputTopic,
|
|
10
|
-
runChatLoopInTerminal,
|
|
11
|
-
} from "@aigne/core-next";
|
|
4
|
+
import { AIAgent, ExecutionEngine, UserAgent, UserInputTopic, UserOutputTopic } from "@aigne/core";
|
|
5
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
6
|
+
import { runChatLoopInTerminal } from "@aigne/core/utils/run-chat-loop.js";
|
|
12
7
|
import { z } from "zod";
|
|
13
8
|
|
|
14
9
|
const { OPENAI_API_KEY } = process.env;
|
|
15
10
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
16
11
|
|
|
17
|
-
const model = new
|
|
12
|
+
const model = new OpenAIChatModel({
|
|
18
13
|
apiKey: OPENAI_API_KEY,
|
|
19
14
|
});
|
|
20
15
|
|
|
@@ -78,7 +73,11 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
78
73
|
|
|
79
74
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
80
75
|
|
|
81
|
-
const userAgent =
|
|
76
|
+
const userAgent = UserAgent.from({
|
|
77
|
+
context: engine,
|
|
78
|
+
publishTopic: UserInputTopic,
|
|
79
|
+
subscribeTopic: UserOutputTopic,
|
|
80
|
+
});
|
|
82
81
|
|
|
83
82
|
await runChatLoopInTerminal(userAgent, {
|
|
84
83
|
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.1
|
|
3
|
+
"version": "1.2.1",
|
|
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.1",
|
|
19
20
|
"zod": "^3.24.2",
|
|
20
|
-
"@aigne/core
|
|
21
|
+
"@aigne/core": "^1.5.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,12 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ChatModelOpenAI,
|
|
5
|
-
ExecutionEngine,
|
|
6
|
-
UserInputTopic,
|
|
7
|
-
UserOutputTopic,
|
|
8
|
-
} from "@aigne/core-next";
|
|
2
|
+
import { AIAgent, ExecutionEngine, UserInputTopic, UserOutputTopic } from "@aigne/core";
|
|
3
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
9
4
|
import { z } from "zod";
|
|
10
5
|
|
|
11
6
|
const { OPENAI_API_KEY } = process.env;
|
|
12
7
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
13
8
|
|
|
14
|
-
const model = new
|
|
9
|
+
const model = new OpenAIChatModel({
|
|
15
10
|
apiKey: OPENAI_API_KEY,
|
|
16
11
|
});
|
|
17
12
|
|
|
@@ -74,9 +69,10 @@ Please review the code. If previous feedback was provided, see if it was address
|
|
|
74
69
|
});
|
|
75
70
|
|
|
76
71
|
const engine = new ExecutionEngine({ model, agents: [coder, reviewer] });
|
|
72
|
+
engine.publish(UserInputTopic, "Write a function to find the sum of all even numbers in a list.");
|
|
77
73
|
|
|
78
|
-
const
|
|
79
|
-
console.log(
|
|
74
|
+
const { message } = await engine.subscribe(UserOutputTopic);
|
|
75
|
+
console.log(message);
|
|
80
76
|
// Output:
|
|
81
77
|
// {
|
|
82
78
|
// 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)",
|