graphai 0.0.9 → 0.0.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.
- package/README.md +58 -0
- package/lib/experimental_agents/data_agent.d.ts +3 -0
- package/lib/experimental_agents/data_agent.js +25 -0
- package/lib/experimental_agents/index.d.ts +5 -0
- package/lib/experimental_agents/index.js +21 -0
- package/lib/experimental_agents/nested_agent.d.ts +6 -0
- package/lib/experimental_agents/nested_agent.js +22 -0
- package/lib/experimental_agents/slashgpt_agent.d.ts +9 -0
- package/lib/experimental_agents/slashgpt_agent.js +32 -0
- package/lib/experimental_agents/sleeper_agent.d.ts +10 -0
- package/lib/experimental_agents/sleeper_agent.js +28 -0
- package/lib/experimental_agents/string_agent.d.ts +7 -0
- package/lib/experimental_agents/string_agent.js +15 -0
- package/lib/graphai.d.ts +7 -2
- package/lib/graphai.js +3 -0
- package/lib/graphai_cli.js +2 -1
- package/lib/utils/utils.d.ts +1 -0
- package/lib/utils/utils.js +7 -0
- package/package.json +13 -3
- package/.eslintrc.js +0 -30
- package/.github/workflows/node.js.yml +0 -28
- package/.prettierrc +0 -3
- package/samples/agents/arxiv_agent.ts +0 -45
- package/samples/agents/parroting_agent.ts +0 -5
- package/samples/agents/slashgpt_agent.ts +0 -50
- package/samples/express.ts +0 -47
- package/samples/graphs/arxiv.yml +0 -25
- package/samples/graphs/slash_gpt.yml +0 -19
- package/samples/interaction.ts +0 -49
- package/samples/sample_co2.ts +0 -85
- package/samples/sample_gpt.ts +0 -40
- package/samples/sample_paper_ai.ts +0 -22
- package/src/graphai.ts +0 -417
- package/src/graphai_cli.ts +0 -35
- package/src/index.ts +0 -3
- package/tests/agents/agents.ts +0 -23
- package/tests/graphai/test_dispatch.ts +0 -41
- package/tests/graphai/test_fork.ts +0 -106
- package/tests/graphai/test_http_client.ts +0 -40
- package/tests/graphai/test_multiple_functions.ts +0 -46
- package/tests/graphai/test_sample_flow.ts +0 -71
- package/tests/graphs/test_base.yml +0 -19
- package/tests/graphs/test_cli.yaml +0 -4
- package/tests/graphs/test_dispatch.yml +0 -29
- package/tests/graphs/test_error.yml +0 -22
- package/tests/graphs/test_multiple_functions_1.yml +0 -30
- package/tests/graphs/test_retry.yml +0 -23
- package/tests/graphs/test_source.yml +0 -18
- package/tests/graphs/test_source2.yml +0 -19
- package/tests/graphs/test_timeout.yml +0 -22
- package/tests/http-server/README.md +0 -10
- package/tests/http-server/docs/llm.json +0 -4
- package/tests/http-server/docs/llm2.json +0 -4
- package/tests/utils/file_utils.ts +0 -33
- package/tests/utils/runner.ts +0 -40
- package/tests/utils/utils.ts +0 -3
- package/tsconfig.json +0 -113
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AgentFunction } from "@/graphai";
|
|
2
|
-
import { fileTestRunner } from "~/utils/runner";
|
|
3
|
-
|
|
4
|
-
import { sleep } from "~/utils/utils";
|
|
5
|
-
|
|
6
|
-
import { testAgent } from "~/agents/agents";
|
|
7
|
-
|
|
8
|
-
import test from "node:test";
|
|
9
|
-
import assert from "node:assert";
|
|
10
|
-
|
|
11
|
-
const dispatchAgent: AgentFunction<{ delay: number; fail: boolean }, Record<string, any>, Record<string, any>> = async (context) => {
|
|
12
|
-
const { nodeId, retry, params, inputs } = context;
|
|
13
|
-
console.log("executing", nodeId);
|
|
14
|
-
await sleep(params.delay / (retry + 1));
|
|
15
|
-
|
|
16
|
-
if (params.fail && retry < 2) {
|
|
17
|
-
const result = { [nodeId]: "failed" };
|
|
18
|
-
console.log("failed (intentional)", nodeId, retry);
|
|
19
|
-
throw new Error("Intentional Failure");
|
|
20
|
-
} else {
|
|
21
|
-
const result = inputs.reduce(
|
|
22
|
-
(result: Record<string, any>, input: Record<string, any>) => {
|
|
23
|
-
return { ...result, ...input };
|
|
24
|
-
},
|
|
25
|
-
{ [nodeId]: "dispatch" },
|
|
26
|
-
);
|
|
27
|
-
console.log("completing", nodeId);
|
|
28
|
-
return { output1: result };
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
test("test dispatch", async () => {
|
|
33
|
-
const result = await fileTestRunner("/graphs/test_dispatch.yml", { test: testAgent, alt: dispatchAgent });
|
|
34
|
-
assert.deepStrictEqual(result, {
|
|
35
|
-
node1: { node1: "output" },
|
|
36
|
-
node20: { node2: "dispatch" },
|
|
37
|
-
node3: { node3: "output", node1: "output", node2: "dispatch" },
|
|
38
|
-
node4: { node4: "output", node3: "output", node1: "output", node2: "dispatch" },
|
|
39
|
-
node5: { node5: "output", node4: "output", node3: "output", node1: "output", node2: "dispatch" },
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { GraphAI, AgentFunction } from "@/graphai";
|
|
2
|
-
import { testAgent } from "~/agents/agents";
|
|
3
|
-
import { graphDataTestRunner } from "~/utils/runner";
|
|
4
|
-
|
|
5
|
-
import test from "node:test";
|
|
6
|
-
import assert from "node:assert";
|
|
7
|
-
|
|
8
|
-
const testAgent1: AgentFunction = async (context) => {
|
|
9
|
-
const { nodeId, retry, params, inputs } = context;
|
|
10
|
-
console.log("executing", nodeId, params, inputs);
|
|
11
|
-
|
|
12
|
-
const result = {
|
|
13
|
-
[nodeId]: [nodeId, inputs.map((a) => Object.values(a).flat())]
|
|
14
|
-
.flat()
|
|
15
|
-
.filter((a) => !!a)
|
|
16
|
-
.join(":"),
|
|
17
|
-
};
|
|
18
|
-
console.log("completing", nodeId, result);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
test("test base", async () => {
|
|
23
|
-
const forkGraph = {
|
|
24
|
-
nodes: {
|
|
25
|
-
node1: {
|
|
26
|
-
params: {},
|
|
27
|
-
},
|
|
28
|
-
node2: {
|
|
29
|
-
params: {},
|
|
30
|
-
fork: 10,
|
|
31
|
-
inputs: ["node1"],
|
|
32
|
-
},
|
|
33
|
-
node3: {
|
|
34
|
-
params: {},
|
|
35
|
-
// fork: 10,
|
|
36
|
-
inputs: ["node2"],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const result = await graphDataTestRunner("fork.yml", forkGraph, testAgent1);
|
|
42
|
-
// console.log(result);
|
|
43
|
-
assert.deepStrictEqual(result, {
|
|
44
|
-
node1: { node1: "node1" },
|
|
45
|
-
node2_0: { node2_0: "node2_0:node1" },
|
|
46
|
-
node2_1: { node2_1: "node2_1:node1" },
|
|
47
|
-
node2_2: { node2_2: "node2_2:node1" },
|
|
48
|
-
node2_3: { node2_3: "node2_3:node1" },
|
|
49
|
-
node2_4: { node2_4: "node2_4:node1" },
|
|
50
|
-
node2_5: { node2_5: "node2_5:node1" },
|
|
51
|
-
node2_6: { node2_6: "node2_6:node1" },
|
|
52
|
-
node2_7: { node2_7: "node2_7:node1" },
|
|
53
|
-
node2_8: { node2_8: "node2_8:node1" },
|
|
54
|
-
node2_9: { node2_9: "node2_9:node1" },
|
|
55
|
-
node3: {
|
|
56
|
-
node3:
|
|
57
|
-
"node3:node2_0:node1:node2_1:node1:node2_2:node1:node2_3:node1:node2_4:node1:node2_5:node1:node2_6:node1:node2_7:node1:node2_8:node1:node2_9:node1",
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("test base", async () => {
|
|
63
|
-
const forkGraph = {
|
|
64
|
-
nodes: {
|
|
65
|
-
node1: {
|
|
66
|
-
params: {},
|
|
67
|
-
},
|
|
68
|
-
node2: {
|
|
69
|
-
params: {},
|
|
70
|
-
fork: 10,
|
|
71
|
-
inputs: ["node1"],
|
|
72
|
-
},
|
|
73
|
-
node3: {
|
|
74
|
-
params: {},
|
|
75
|
-
fork: 10,
|
|
76
|
-
inputs: ["node2"],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const result = await graphDataTestRunner("fork.yml", forkGraph, testAgent1);
|
|
82
|
-
// console.log(result);
|
|
83
|
-
assert.deepStrictEqual(result, {
|
|
84
|
-
node1: { node1: "node1" },
|
|
85
|
-
node2_0: { node2_0: "node2_0:node1" },
|
|
86
|
-
node2_1: { node2_1: "node2_1:node1" },
|
|
87
|
-
node2_2: { node2_2: "node2_2:node1" },
|
|
88
|
-
node2_3: { node2_3: "node2_3:node1" },
|
|
89
|
-
node2_4: { node2_4: "node2_4:node1" },
|
|
90
|
-
node2_5: { node2_5: "node2_5:node1" },
|
|
91
|
-
node2_6: { node2_6: "node2_6:node1" },
|
|
92
|
-
node2_7: { node2_7: "node2_7:node1" },
|
|
93
|
-
node2_8: { node2_8: "node2_8:node1" },
|
|
94
|
-
node2_9: { node2_9: "node2_9:node1" },
|
|
95
|
-
node3_0: { node3_0: "node3_0:node2_0:node1" },
|
|
96
|
-
node3_1: { node3_1: "node3_1:node2_1:node1" },
|
|
97
|
-
node3_2: { node3_2: "node3_2:node2_2:node1" },
|
|
98
|
-
node3_3: { node3_3: "node3_3:node2_3:node1" },
|
|
99
|
-
node3_4: { node3_4: "node3_4:node2_4:node1" },
|
|
100
|
-
node3_5: { node3_5: "node3_5:node2_5:node1" },
|
|
101
|
-
node3_6: { node3_6: "node3_6:node2_6:node1" },
|
|
102
|
-
node3_7: { node3_7: "node3_7:node2_7:node1" },
|
|
103
|
-
node3_8: { node3_8: "node3_8:node2_8:node1" },
|
|
104
|
-
node3_9: { node3_9: "node3_9:node2_9:node1" },
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { GraphAI, AgentFunction } from "@/graphai";
|
|
2
|
-
import { graphDataTestRunner } from "~/utils/runner";
|
|
3
|
-
|
|
4
|
-
import test from "node:test";
|
|
5
|
-
import assert from "node:assert";
|
|
6
|
-
|
|
7
|
-
const httpClientAgent: AgentFunction<Record<string, string>> = async (context) => {
|
|
8
|
-
const { nodeId, retry, params, inputs } = context;
|
|
9
|
-
console.log("executing", nodeId, params, inputs);
|
|
10
|
-
|
|
11
|
-
const response = await fetch(params.url);
|
|
12
|
-
const result = await response.json();
|
|
13
|
-
|
|
14
|
-
console.log("completing", nodeId, result);
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const graph_data = {
|
|
19
|
-
nodes: {
|
|
20
|
-
node1: {
|
|
21
|
-
params: {
|
|
22
|
-
url: "http://127.0.0.1:8080/llm.json",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
node2: {
|
|
26
|
-
params: {
|
|
27
|
-
url: "http://127.0.0.1:8080/llm2.json",
|
|
28
|
-
},
|
|
29
|
-
inputs: ["node1"],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
test("test http client", async () => {
|
|
35
|
-
const result = await graphDataTestRunner("http.log", graph_data, httpClientAgent);
|
|
36
|
-
assert.deepStrictEqual(result, {
|
|
37
|
-
node1: { result: true, messages: ["hello"] },
|
|
38
|
-
node2: { result: true, messages: ["hello2"] },
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { GraphAI, AgentFunction } from "@/graphai";
|
|
3
|
-
import { readGraphaiData } from "~/utils/file_utils";
|
|
4
|
-
import { fileTestRunner } from "~/utils/runner";
|
|
5
|
-
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import assert from "node:assert";
|
|
8
|
-
|
|
9
|
-
const testAgent1: AgentFunction = async (context) => {
|
|
10
|
-
const { nodeId, retry, params } = context;
|
|
11
|
-
console.log("executing", nodeId, params);
|
|
12
|
-
|
|
13
|
-
const result = { [nodeId]: "output 1" };
|
|
14
|
-
console.log("completing", nodeId, result);
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const testAgent2: AgentFunction = async (context) => {
|
|
19
|
-
const { nodeId, retry, params } = context;
|
|
20
|
-
console.log("executing", nodeId, params);
|
|
21
|
-
|
|
22
|
-
const result = { [nodeId]: "output 2" };
|
|
23
|
-
console.log("completing", nodeId, result);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const numberTestAgent: AgentFunction<{ number: number }, { [key: string]: number }> = async (context) => {
|
|
28
|
-
const { nodeId, retry, params } = context;
|
|
29
|
-
console.log("executing", nodeId, params);
|
|
30
|
-
|
|
31
|
-
const result = { [nodeId]: params.number };
|
|
32
|
-
console.log("completing", nodeId, result);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
test("test multiple function", async () => {
|
|
37
|
-
const result = await fileTestRunner("/graphs/test_multiple_functions_1.yml", { test1: testAgent1, test2: testAgent2, numberTestAgent });
|
|
38
|
-
assert.deepStrictEqual(result, {
|
|
39
|
-
node1: { node1: "output 1" },
|
|
40
|
-
node2: { node2: "output 1" },
|
|
41
|
-
node3: { node3: "output 2" },
|
|
42
|
-
node4: { node4: "output 1" },
|
|
43
|
-
node5: { node5: "output 2" },
|
|
44
|
-
node6: { node6: 10 },
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { GraphAI } from "@/graphai";
|
|
2
|
-
import { testAgent } from "~/agents/agents";
|
|
3
|
-
import { fileTestRunner } from "~/utils/runner";
|
|
4
|
-
|
|
5
|
-
import test from "node:test";
|
|
6
|
-
import assert from "node:assert";
|
|
7
|
-
|
|
8
|
-
test("test base", async () => {
|
|
9
|
-
const result = await fileTestRunner("/graphs/test_base.yml", testAgent);
|
|
10
|
-
assert.deepStrictEqual(result, {
|
|
11
|
-
node1: { node1: "output" },
|
|
12
|
-
node2: { node2: "output" },
|
|
13
|
-
node3: { node3: "output", node1: "output", node2: "output" },
|
|
14
|
-
node4: { node4: "output", node3: "output", node1: "output", node2: "output" },
|
|
15
|
-
node5: { node5: "output", node4: "output", node3: "output", node1: "output", node2: "output" },
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("test retry", async () => {
|
|
20
|
-
const result = await fileTestRunner("/graphs/test_retry.yml", testAgent);
|
|
21
|
-
assert.deepStrictEqual(result, {
|
|
22
|
-
node1: { node1: "output" },
|
|
23
|
-
node2: { node2: "output" },
|
|
24
|
-
node3: { node3: "output", node1: "output", node2: "output" },
|
|
25
|
-
node4: { node4: "output", node3: "output", node1: "output", node2: "output" },
|
|
26
|
-
node5: { node5: "output", node4: "output", node3: "output", node1: "output", node2: "output" },
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("test error", async () => {
|
|
31
|
-
const result = await fileTestRunner("/graphs/test_error.yml", testAgent);
|
|
32
|
-
assert.deepStrictEqual(result, {
|
|
33
|
-
node1: { node1: "output" },
|
|
34
|
-
node2: { node2: "output" },
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("test timeout", async () => {
|
|
39
|
-
const result = await fileTestRunner("/graphs/test_timeout.yml", testAgent);
|
|
40
|
-
assert.deepStrictEqual(result, {
|
|
41
|
-
node1: { node1: "output" },
|
|
42
|
-
node2: { node2: "output" },
|
|
43
|
-
node3: { node3: "output", node1: "output", node2: "output" },
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("test source", async () => {
|
|
48
|
-
const result = await fileTestRunner("/graphs/test_source.yml", testAgent, (graph: GraphAI) => {
|
|
49
|
-
graph.injectResult("node2", { node2: "injected" });
|
|
50
|
-
});
|
|
51
|
-
assert.deepStrictEqual(result, {
|
|
52
|
-
node1: { node1: "output" },
|
|
53
|
-
node2: { node2: "injected" },
|
|
54
|
-
node3: { node3: "output", node1: "output", node2: "injected" },
|
|
55
|
-
node4: { node4: "output", node3: "output", node1: "output", node2: "injected" },
|
|
56
|
-
node5: { node5: "output", node4: "output", node3: "output", node1: "output", node2: "injected" },
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("test source2", async () => {
|
|
61
|
-
const result = await fileTestRunner("/graphs/test_source2.yml", testAgent, (graph: GraphAI) => {
|
|
62
|
-
graph.injectResult("node1", { node1: "injected" });
|
|
63
|
-
});
|
|
64
|
-
assert.deepStrictEqual(result, {
|
|
65
|
-
node1: { node1: "injected" },
|
|
66
|
-
node2: { node2: "preset" },
|
|
67
|
-
node3: { node3: "output", node1: "injected", node2: "preset" },
|
|
68
|
-
node4: { node4: "output", node3: "output", node1: "injected", node2: "preset" },
|
|
69
|
-
node5: { node5: "output", node4: "output", node3: "output", node1: "injected", node2: "preset" },
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
node2:
|
|
6
|
-
params:
|
|
7
|
-
delay: 100
|
|
8
|
-
node3:
|
|
9
|
-
params:
|
|
10
|
-
delay: 500
|
|
11
|
-
inputs: [node1, node2]
|
|
12
|
-
node4:
|
|
13
|
-
params:
|
|
14
|
-
delay: 100
|
|
15
|
-
inputs: [node3]
|
|
16
|
-
node5:
|
|
17
|
-
params:
|
|
18
|
-
delay: 500
|
|
19
|
-
inputs: [node2, node4]
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
agentId: test
|
|
6
|
-
node2:
|
|
7
|
-
params:
|
|
8
|
-
delay: 100
|
|
9
|
-
agentId: alt
|
|
10
|
-
outputs:
|
|
11
|
-
output1: node20
|
|
12
|
-
node20:
|
|
13
|
-
source: true
|
|
14
|
-
agentId: test
|
|
15
|
-
node3:
|
|
16
|
-
params:
|
|
17
|
-
delay: 500
|
|
18
|
-
inputs: [node1, node20]
|
|
19
|
-
agentId: test
|
|
20
|
-
node4:
|
|
21
|
-
params:
|
|
22
|
-
delay: 100
|
|
23
|
-
inputs: [node3]
|
|
24
|
-
agentId: test
|
|
25
|
-
node5:
|
|
26
|
-
params:
|
|
27
|
-
delay: 500
|
|
28
|
-
inputs: [node20, node4]
|
|
29
|
-
agentId: test
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
node2:
|
|
6
|
-
params:
|
|
7
|
-
delay: 100
|
|
8
|
-
node3:
|
|
9
|
-
params:
|
|
10
|
-
delay: 500
|
|
11
|
-
fail: true
|
|
12
|
-
inputs: [node1, node2]
|
|
13
|
-
node4:
|
|
14
|
-
timeout: 200
|
|
15
|
-
retry: 2
|
|
16
|
-
params:
|
|
17
|
-
delay: 300
|
|
18
|
-
inputs: [node3]
|
|
19
|
-
node5:
|
|
20
|
-
params:
|
|
21
|
-
delay: 100
|
|
22
|
-
inputs: [node4]
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
agentId: test1
|
|
6
|
-
node2:
|
|
7
|
-
params:
|
|
8
|
-
delay: 100
|
|
9
|
-
agentId: test1
|
|
10
|
-
node3:
|
|
11
|
-
params:
|
|
12
|
-
delay: 500
|
|
13
|
-
inputs: [node1, node2]
|
|
14
|
-
agentId: test2
|
|
15
|
-
node4:
|
|
16
|
-
params:
|
|
17
|
-
delay: 100
|
|
18
|
-
inputs: [node3]
|
|
19
|
-
agentId: test1
|
|
20
|
-
node5:
|
|
21
|
-
params:
|
|
22
|
-
delay: 500
|
|
23
|
-
inputs: [node2, node4]
|
|
24
|
-
agentId: test2
|
|
25
|
-
node6:
|
|
26
|
-
params:
|
|
27
|
-
delay: 100
|
|
28
|
-
number: 10
|
|
29
|
-
inputs: [node4]
|
|
30
|
-
agentId: numberTestAgent
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
node2:
|
|
6
|
-
params:
|
|
7
|
-
delay: 100
|
|
8
|
-
node3:
|
|
9
|
-
params:
|
|
10
|
-
delay: 500
|
|
11
|
-
fail: true
|
|
12
|
-
inputs: [node1, node2]
|
|
13
|
-
retry: 2
|
|
14
|
-
node4:
|
|
15
|
-
timeout: 200
|
|
16
|
-
retry: 2
|
|
17
|
-
params:
|
|
18
|
-
delay: 300
|
|
19
|
-
inputs: [node3]
|
|
20
|
-
node5:
|
|
21
|
-
params:
|
|
22
|
-
delay: 100
|
|
23
|
-
inputs: [node4]
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
source: true
|
|
4
|
-
node2:
|
|
5
|
-
source: true
|
|
6
|
-
result:
|
|
7
|
-
node2: preset
|
|
8
|
-
node3:
|
|
9
|
-
params:
|
|
10
|
-
delay: 500
|
|
11
|
-
inputs: [node1, node2]
|
|
12
|
-
node4:
|
|
13
|
-
params:
|
|
14
|
-
delay: 100
|
|
15
|
-
inputs: [node3]
|
|
16
|
-
node5:
|
|
17
|
-
params:
|
|
18
|
-
delay: 500
|
|
19
|
-
inputs: [node2, node4]
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
params:
|
|
4
|
-
delay: 500
|
|
5
|
-
node2:
|
|
6
|
-
params:
|
|
7
|
-
delay: 100
|
|
8
|
-
node3:
|
|
9
|
-
params:
|
|
10
|
-
delay: 500
|
|
11
|
-
fail: true
|
|
12
|
-
inputs: [node1, node2]
|
|
13
|
-
retry: 2
|
|
14
|
-
node4:
|
|
15
|
-
timeout: 200
|
|
16
|
-
params:
|
|
17
|
-
delay: 300
|
|
18
|
-
inputs: [node3]
|
|
19
|
-
node5:
|
|
20
|
-
params:
|
|
21
|
-
delay: 100
|
|
22
|
-
inputs: [node4]
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import YAML from "yaml";
|
|
4
|
-
|
|
5
|
-
export const mkdirLogDir = () => {
|
|
6
|
-
const logsDir = path.join(__dirname, "../logs");
|
|
7
|
-
|
|
8
|
-
if (!fs.existsSync(logsDir)) {
|
|
9
|
-
fs.mkdirSync(logsDir, { recursive: true });
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const readGraphaiData = (file: string) => {
|
|
14
|
-
if (file.endsWith(".yaml") || file.endsWith(".yml")) {
|
|
15
|
-
return readYamlManifest(file);
|
|
16
|
-
}
|
|
17
|
-
if (file.endsWith(".json")) {
|
|
18
|
-
return readJsonManifest(file);
|
|
19
|
-
}
|
|
20
|
-
throw new Error("No file exists " + file);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const readJsonManifest = (fileName: string) => {
|
|
24
|
-
const manifest_file = fs.readFileSync(fileName, "utf8");
|
|
25
|
-
const manifest = JSON.parse(manifest_file);
|
|
26
|
-
return manifest;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const readYamlManifest = (fileName: string) => {
|
|
30
|
-
const manifest_file = fs.readFileSync(fileName, "utf8");
|
|
31
|
-
const manifest = YAML.parse(manifest_file);
|
|
32
|
-
return manifest;
|
|
33
|
-
};
|
package/tests/utils/runner.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { GraphAI, GraphData, AgentFunctionDictonary, AgentFunction } from "@/graphai";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { readGraphaiData, mkdirLogDir } from "~/utils/file_utils";
|
|
5
|
-
|
|
6
|
-
export const fileTestRunner = async (
|
|
7
|
-
file: string,
|
|
8
|
-
callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>,
|
|
9
|
-
callback: (graph: GraphAI) => void = () => {},
|
|
10
|
-
) => {
|
|
11
|
-
const file_path = path.resolve(__dirname) + "/.." + file;
|
|
12
|
-
const graph_data = readGraphaiData(file_path);
|
|
13
|
-
return await graphDataTestRunner(file, graph_data, callbackDictonary, callback);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const graphDataTestRunner = async (
|
|
17
|
-
logFileName: string,
|
|
18
|
-
graph_data: GraphData,
|
|
19
|
-
callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>,
|
|
20
|
-
callback: (graph: GraphAI) => void = () => {},
|
|
21
|
-
) => {
|
|
22
|
-
mkdirLogDir();
|
|
23
|
-
|
|
24
|
-
const log_path = path.resolve(__dirname) + "/../logs/" + path.basename(logFileName).replace(/\.yml$/, ".log");
|
|
25
|
-
const graph = new GraphAI(graph_data, callbackDictonary);
|
|
26
|
-
callback(graph);
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const results = await graph.run();
|
|
30
|
-
fs.writeFileSync(log_path, JSON.stringify(graph.transactionLogs(), null, 2));
|
|
31
|
-
// console.log(graph.transactionLogs());
|
|
32
|
-
return results;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (error instanceof Error) {
|
|
35
|
-
console.log("Error:", error.message);
|
|
36
|
-
}
|
|
37
|
-
// console.log(graph.transactionLogs());
|
|
38
|
-
return graph.results();
|
|
39
|
-
}
|
|
40
|
-
};
|
package/tests/utils/utils.ts
DELETED