@aigne/example-workflow-code-execution 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 +5 -4
- package/index.ts +7 -10
- package/package.json +5 -3
- package/usage.ts +5 -6
package/README.md
CHANGED
|
@@ -90,13 +90,14 @@ The following example demonstrates how to build a code-execution workflow:
|
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
92
|
import assert from "node:assert";
|
|
93
|
-
import { AIAgent,
|
|
93
|
+
import { AIAgent, ExecutionEngine, FunctionAgent } from "@aigne/core";
|
|
94
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
94
95
|
import { z } from "zod";
|
|
95
96
|
|
|
96
97
|
const { OPENAI_API_KEY } = process.env;
|
|
97
98
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
98
99
|
|
|
99
|
-
const model = new
|
|
100
|
+
const model = new OpenAIChatModel({
|
|
100
101
|
apiKey: OPENAI_API_KEY,
|
|
101
102
|
});
|
|
102
103
|
|
|
@@ -125,11 +126,11 @@ Work with the sandbox to execute your code.
|
|
|
125
126
|
|
|
126
127
|
const engine = new ExecutionEngine({ model });
|
|
127
128
|
|
|
128
|
-
const result = await engine.
|
|
129
|
+
const result = await engine.call(coder, "10! = ?");
|
|
129
130
|
console.log(result);
|
|
130
131
|
// Output:
|
|
131
132
|
// {
|
|
132
|
-
//
|
|
133
|
+
// $message: "The value of \\(10!\\) (10 factorial) is 3,628,800.",
|
|
133
134
|
// }
|
|
134
135
|
```
|
|
135
136
|
|
package/index.ts
CHANGED
|
@@ -1,19 +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
|
-
FunctionAgent,
|
|
9
|
-
runChatLoopInTerminal,
|
|
10
|
-
} from "@aigne/core-next";
|
|
4
|
+
import { AIAgent, ExecutionEngine, FunctionAgent } 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";
|
|
11
7
|
import { z } from "zod";
|
|
12
8
|
|
|
13
9
|
const { OPENAI_API_KEY } = process.env;
|
|
14
10
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
15
11
|
|
|
16
|
-
const model = new
|
|
12
|
+
const model = new OpenAIChatModel({
|
|
17
13
|
apiKey: OPENAI_API_KEY,
|
|
18
14
|
});
|
|
19
15
|
|
|
@@ -38,13 +34,14 @@ You are a proficient coder. You write code to solve problems.
|
|
|
38
34
|
Work with the sandbox to execute your code.
|
|
39
35
|
`,
|
|
40
36
|
tools: [sandbox],
|
|
37
|
+
memory: true,
|
|
41
38
|
});
|
|
42
39
|
|
|
43
40
|
const engine = new ExecutionEngine({ model });
|
|
44
41
|
|
|
45
|
-
const
|
|
42
|
+
const user = engine.call(coder);
|
|
46
43
|
|
|
47
|
-
await runChatLoopInTerminal(
|
|
44
|
+
await runChatLoopInTerminal(user, {
|
|
48
45
|
welcome:
|
|
49
46
|
"Welcome to the code execution workflow! you can ask me anything can be resolved by running code.",
|
|
50
47
|
defaultQuestion: "10! = ?",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-workflow-code-execution",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework to build a code-execution 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-code-execution",
|
|
@@ -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/usage.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
#!/usr/bin/env npx -y bun
|
|
2
|
-
|
|
3
1
|
import assert from "node:assert";
|
|
4
|
-
import { AIAgent,
|
|
2
|
+
import { AIAgent, ExecutionEngine, FunctionAgent } from "@aigne/core";
|
|
3
|
+
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
|
|
7
6
|
const { OPENAI_API_KEY } = process.env;
|
|
8
7
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|
|
9
8
|
|
|
10
|
-
const model = new
|
|
9
|
+
const model = new OpenAIChatModel({
|
|
11
10
|
apiKey: OPENAI_API_KEY,
|
|
12
11
|
});
|
|
13
12
|
|
|
@@ -36,9 +35,9 @@ Work with the sandbox to execute your code.
|
|
|
36
35
|
|
|
37
36
|
const engine = new ExecutionEngine({ model });
|
|
38
37
|
|
|
39
|
-
const result = await engine.
|
|
38
|
+
const result = await engine.call(coder, "10! = ?");
|
|
40
39
|
console.log(result);
|
|
41
40
|
// Output:
|
|
42
41
|
// {
|
|
43
|
-
//
|
|
42
|
+
// $message: "The value of \\(10!\\) (10 factorial) is 3,628,800.",
|
|
44
43
|
// }
|