graphai 0.0.10 → 0.0.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.
Files changed (64) hide show
  1. package/README.md +104 -10
  2. package/lib/experimental_agents/array_agents.d.ts +4 -0
  3. package/lib/experimental_agents/array_agents.js +30 -0
  4. package/lib/experimental_agents/data_agent.d.ts +3 -0
  5. package/lib/experimental_agents/data_agent.js +25 -0
  6. package/lib/experimental_agents/index.d.ts +4 -0
  7. package/lib/experimental_agents/index.js +4 -0
  8. package/lib/experimental_agents/nested_agent.d.ts +6 -0
  9. package/lib/experimental_agents/nested_agent.js +24 -0
  10. package/lib/experimental_agents/slashgpt_agent.js +11 -6
  11. package/lib/experimental_agents/sleeper_agent.d.ts +10 -0
  12. package/lib/experimental_agents/sleeper_agent.js +28 -0
  13. package/lib/experimental_agents/string_agent.js +9 -5
  14. package/lib/graphai.d.ts +31 -8
  15. package/lib/graphai.js +138 -43
  16. package/lib/graphai_cli.js +1 -1
  17. package/lib/utils/utils.d.ts +1 -0
  18. package/lib/utils/utils.js +7 -0
  19. package/package.json +14 -4
  20. package/.eslintrc.js +0 -30
  21. package/.github/workflows/node.js.yml +0 -28
  22. package/.prettierrc +0 -3
  23. package/samples/agents/arxiv_agent.ts +0 -45
  24. package/samples/agents/parroting_agent.ts +0 -5
  25. package/samples/agents/slashgpt_agent.ts +0 -19
  26. package/samples/express.ts +0 -47
  27. package/samples/graphs/arxiv.yml +0 -25
  28. package/samples/graphs/slash_gpt.yml +0 -28
  29. package/samples/home.json +0 -112
  30. package/samples/home.ts +0 -51
  31. package/samples/interaction.ts +0 -42
  32. package/samples/runner.ts +0 -15
  33. package/samples/sample_co2.ts +0 -80
  34. package/samples/sample_gpt.ts +0 -8
  35. package/samples/sample_paper_ai.ts +0 -10
  36. package/src/experimental_agents/index.ts +0 -2
  37. package/src/experimental_agents/slashgpt_agent.ts +0 -30
  38. package/src/experimental_agents/string_agent.ts +0 -10
  39. package/src/graphai.ts +0 -417
  40. package/src/graphai_cli.ts +0 -37
  41. package/src/index.ts +0 -3
  42. package/tests/agents/agents.ts +0 -23
  43. package/tests/agents/test_string_agent.ts +0 -28
  44. package/tests/graphai/test_dispatch.ts +0 -41
  45. package/tests/graphai/test_fork.ts +0 -106
  46. package/tests/graphai/test_http_client.ts +0 -40
  47. package/tests/graphai/test_multiple_functions.ts +0 -46
  48. package/tests/graphai/test_sample_flow.ts +0 -71
  49. package/tests/graphs/test_base.yml +0 -19
  50. package/tests/graphs/test_cli.yaml +0 -4
  51. package/tests/graphs/test_dispatch.yml +0 -29
  52. package/tests/graphs/test_error.yml +0 -22
  53. package/tests/graphs/test_multiple_functions_1.yml +0 -30
  54. package/tests/graphs/test_retry.yml +0 -23
  55. package/tests/graphs/test_source.yml +0 -18
  56. package/tests/graphs/test_source2.yml +0 -19
  57. package/tests/graphs/test_timeout.yml +0 -22
  58. package/tests/http-server/README.md +0 -10
  59. package/tests/http-server/docs/llm.json +0 -4
  60. package/tests/http-server/docs/llm2.json +0 -4
  61. package/tests/utils/file_utils.ts +0 -33
  62. package/tests/utils/runner.ts +0 -40
  63. package/tests/utils/utils.ts +0 -3
  64. package/tsconfig.json +0 -113
package/src/graphai.ts DELETED
@@ -1,417 +0,0 @@
1
- export enum NodeState {
2
- Waiting = "waiting",
3
- Executing = "executing",
4
- Failed = "failed",
5
- TimedOut = "timed-out",
6
- Completed = "completed",
7
- Injected = "injected",
8
- Dispatched = "dispatched",
9
- }
10
- type ResultData<ResultType = Record<string, any>> = ResultType | undefined;
11
- type ResultDataDictonary<ResultType = Record<string, any>> = Record<string, ResultData<ResultType>>;
12
-
13
- export type NodeDataParams<ParamsType = Record<string, any>> = ParamsType; // Agent-specific parameters
14
-
15
- type NodeData = {
16
- inputs?: Array<string>;
17
- params?: NodeDataParams;
18
- retry?: number;
19
- timeout?: number; // msec
20
- agentId?: string;
21
- fork?: number;
22
- source?: boolean;
23
- result?: ResultData; // preset result for source node.
24
- outputs?: Record<string, string>; // mapping from routeId to nodeId
25
- };
26
-
27
- export type GraphData = {
28
- nodes: Record<string, NodeData>;
29
- concurrency?: number;
30
- };
31
-
32
- export type TransactionLog = {
33
- nodeId: string;
34
- state: NodeState;
35
- startTime: number;
36
- endTime?: number;
37
- retryCount: number;
38
- agentId?: string;
39
- params?: NodeDataParams;
40
- inputs?: Array<ResultData>;
41
- errorMessage?: string;
42
- result?: ResultData;
43
- };
44
-
45
- export type AgentFunctionContext<ParamsType, ResultType, PreviousResultType> = {
46
- nodeId: string;
47
- forkIndex?: number;
48
- retry: number;
49
- params: NodeDataParams<ParamsType>;
50
- inputs: Array<PreviousResultType>;
51
- };
52
-
53
- export type AgentFunction<ParamsType = Record<string, any>, ResultType = Record<string, any>, PreviousResultType = Record<string, any>> = (
54
- context: AgentFunctionContext<ParamsType, ResultType, PreviousResultType>,
55
- ) => Promise<ResultData<ResultType>>;
56
-
57
- export type AgentFunctionDictonary = Record<string, AgentFunction<any, any, any>>;
58
-
59
- class Node {
60
- public nodeId: string;
61
- public params: NodeDataParams; // Agent-specific parameters
62
- public inputs: Array<string>; // List of nodes this node needs data from.
63
- public pendings: Set<string>; // List of nodes this node is waiting data from.
64
- public waitlist = new Set<string>(); // List of nodes which need data from this node.
65
- public state = NodeState.Waiting;
66
- public agentId?: string;
67
- public fork?: number;
68
- public forkIndex?: number;
69
- public result: ResultData = undefined;
70
- public retryLimit: number;
71
- public retryCount: number = 0;
72
- public transactionId: undefined | number; // To reject callbacks from timed-out transactions
73
- public timeout?: number; // msec
74
- public error?: Error;
75
- public source: boolean;
76
- public outputs?: Record<string, string>; // Mapping from routeId to nodeId
77
-
78
- private graph: GraphAI;
79
-
80
- constructor(nodeId: string, forkIndex: number | undefined, data: NodeData, graph: GraphAI) {
81
- this.nodeId = nodeId;
82
- this.forkIndex = forkIndex;
83
- this.inputs = data.inputs ?? [];
84
- this.pendings = new Set(this.inputs);
85
- this.params = data.params ?? {};
86
- this.agentId = data.agentId;
87
- this.fork = data.fork;
88
- this.retryLimit = data.retry ?? 0;
89
- this.timeout = data.timeout;
90
- this.source = data.source === true;
91
- this.outputs = data.outputs;
92
- this.graph = graph;
93
- }
94
-
95
- public asString() {
96
- return `${this.nodeId}: ${this.state} ${[...this.waitlist]}`;
97
- }
98
-
99
- private retry(state: NodeState, error: Error) {
100
- if (this.retryCount < this.retryLimit) {
101
- this.retryCount++;
102
- this.execute();
103
- } else {
104
- this.state = state;
105
- this.result = undefined;
106
- this.error = error;
107
- this.transactionId = undefined; // This is necessary for timeout case
108
- this.graph.removeRunning(this);
109
- }
110
- }
111
-
112
- public removePending(nodeId: string) {
113
- this.pendings.delete(nodeId);
114
- if (this.graph.isRunning) {
115
- this.pushQueueIfReady();
116
- }
117
- }
118
-
119
- public pushQueueIfReady() {
120
- if (this.pendings.size === 0 && !this.source) {
121
- this.graph.pushQueue(this);
122
- }
123
- }
124
-
125
- public injectResult(result: ResultData) {
126
- if (this.source) {
127
- const log: TransactionLog = {
128
- nodeId: this.nodeId,
129
- retryCount: this.retryCount,
130
- state: NodeState.Injected,
131
- startTime: Date.now(),
132
- endTime: Date.now(),
133
- result,
134
- };
135
- this.graph.appendLog(log);
136
- this.setResult(result, NodeState.Injected);
137
- } else {
138
- console.error("- injectResult called on non-source node.", this.nodeId);
139
- }
140
- }
141
-
142
- private setResult(result: ResultData, state: NodeState) {
143
- this.state = state;
144
- this.result = result;
145
- this.waitlist.forEach((nodeId) => {
146
- const node = this.graph.nodes[nodeId];
147
- // Todo: Avoid running before Run()
148
- node.removePending(this.nodeId);
149
- });
150
- }
151
-
152
- public async execute() {
153
- const results = this.graph.resultsOf(this.inputs);
154
- const transactionId = Date.now();
155
- const log: TransactionLog = {
156
- nodeId: this.nodeId,
157
- retryCount: this.retryCount,
158
- state: NodeState.Executing,
159
- startTime: transactionId,
160
- agentId: this.agentId,
161
- params: this.params,
162
- inputs: results,
163
- };
164
- this.graph.appendLog(log);
165
- this.state = NodeState.Executing;
166
- this.transactionId = transactionId;
167
-
168
- if (this.timeout && this.timeout > 0) {
169
- setTimeout(() => {
170
- if (this.state === NodeState.Executing && this.transactionId === transactionId) {
171
- console.log(`-- ${this.nodeId}: timeout ${this.timeout}`);
172
- log.errorMessage = "Timeout";
173
- log.state = NodeState.TimedOut;
174
- log.endTime = Date.now();
175
- this.retry(NodeState.TimedOut, Error("Timeout"));
176
- }
177
- }, this.timeout);
178
- }
179
-
180
- try {
181
- const callback = this.graph.getCallback(this.agentId);
182
- const result = await callback({
183
- nodeId: this.nodeId,
184
- retry: this.retryCount,
185
- params: this.params,
186
- inputs: results,
187
- forkIndex: this.forkIndex,
188
- });
189
- if (this.transactionId !== transactionId) {
190
- console.log(`-- ${this.nodeId}: transactionId mismatch`);
191
- return;
192
- }
193
-
194
- log.endTime = Date.now();
195
- log.result = result;
196
-
197
- const outputs = this.outputs;
198
- if (outputs !== undefined) {
199
- Object.keys(result).forEach((outputId) => {
200
- const nodeId = outputs[outputId];
201
- this.graph.injectResult(nodeId, result[outputId]);
202
- });
203
- log.state = NodeState.Dispatched;
204
- this.state = NodeState.Dispatched;
205
- this.graph.removeRunning(this);
206
- return;
207
- }
208
- log.state = NodeState.Completed;
209
- this.setResult(result, NodeState.Completed);
210
- this.graph.removeRunning(this);
211
- } catch (error) {
212
- if (this.transactionId !== transactionId) {
213
- console.log(`-- ${this.nodeId}: transactionId mismatch(error)`);
214
- return;
215
- }
216
- log.state = NodeState.Failed;
217
- log.endTime = Date.now();
218
- if (error instanceof Error) {
219
- log.errorMessage = error.message;
220
- this.retry(NodeState.Failed, error);
221
- } else {
222
- console.error(`-- ${this.nodeId}: Unexpecrted error was caught`);
223
- log.errorMessage = "Unknown";
224
- this.retry(NodeState.Failed, Error("Unknown"));
225
- }
226
- }
227
- }
228
- }
229
-
230
- type GraphNodes = Record<string, Node>;
231
-
232
- const defaultConcurrency = 8;
233
-
234
- export class GraphAI {
235
- public nodes: GraphNodes;
236
- public callbackDictonary: AgentFunctionDictonary;
237
- public isRunning = false;
238
- private runningNodes = new Set<string>();
239
- private nodeQueue: Array<Node> = [];
240
- private onComplete: () => void;
241
- private concurrency: number;
242
- private logs: Array<TransactionLog> = [];
243
-
244
- constructor(data: GraphData, callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>) {
245
- this.callbackDictonary = typeof callbackDictonary === "function" ? { _default: callbackDictonary } : callbackDictonary;
246
- this.concurrency = data.concurrency ?? defaultConcurrency;
247
- this.onComplete = () => {
248
- console.error("-- SOMETHING IS WRONG: onComplete is called without run()");
249
- };
250
- const nodeId2forkedNodeIds: Record<string, string[]> = {};
251
- const forkedNodeId2Index: Record<string, number> = {};
252
-
253
- // Create node instances from data.nodes
254
- this.nodes = Object.keys(data.nodes).reduce((nodes: GraphNodes, nodeId: string) => {
255
- const fork = data.nodes[nodeId].fork;
256
- if (fork) {
257
- // For fork, change the nodeId and increase the node
258
- nodeId2forkedNodeIds[nodeId] = new Array(fork).fill(undefined).map((_, i) => {
259
- const forkedNodeId = `${nodeId}_${i}`;
260
- nodes[forkedNodeId] = new Node(forkedNodeId, i, data.nodes[nodeId], this);
261
- // Data for pending and waiting
262
- forkedNodeId2Index[forkedNodeId] = i;
263
- return forkedNodeId;
264
- });
265
- } else {
266
- nodes[nodeId] = new Node(nodeId, undefined, data.nodes[nodeId], this);
267
- }
268
- return nodes;
269
- }, {});
270
-
271
- // Generate the waitlist for each node, and update the pendings in case of forked node.
272
- Object.keys(this.nodes).forEach((nodeId) => {
273
- const node = this.nodes[nodeId];
274
- node.pendings.forEach((pending) => {
275
- // If the pending(previous) node is forking
276
- if (nodeId2forkedNodeIds[pending]) {
277
- // update node.pending and pending(previous) node.wailtlist
278
- if (node.fork) {
279
- // 1:1 if current nodes are also forking.
280
- const newPendingId = nodeId2forkedNodeIds[pending][forkedNodeId2Index[nodeId]];
281
- this.nodes[newPendingId].waitlist.add(nodeId); // previousNode
282
- node.pendings.add(newPendingId);
283
- } else {
284
- // 1:n if current node is not forking.
285
- nodeId2forkedNodeIds[pending].forEach((newPendingId) => {
286
- this.nodes[newPendingId].waitlist.add(nodeId); // previousNode
287
- node.pendings.add(newPendingId);
288
- });
289
- }
290
- node.pendings.delete(pending);
291
- } else {
292
- this.nodes[pending].waitlist.add(nodeId); // previousNode
293
- }
294
- });
295
- node.inputs = Array.from(node.pendings); // for fork.
296
- });
297
-
298
- // If the result property is specified, inject it.
299
- // NOTE: This must be done at the end of this constructor
300
- Object.keys(data.nodes).forEach((nodeId) => {
301
- const result = data.nodes[nodeId].result;
302
- if (result) {
303
- this.injectResult(nodeId, result);
304
- }
305
- });
306
- }
307
-
308
- public getCallback(_agentId?: string) {
309
- const agentId = _agentId ?? "_default";
310
- if (this.callbackDictonary[agentId]) {
311
- return this.callbackDictonary[agentId];
312
- }
313
- throw new Error("No agent: " + agentId);
314
- }
315
-
316
- public asString() {
317
- return Object.keys(this.nodes)
318
- .map((nodeId) => {
319
- return this.nodes[nodeId].asString();
320
- })
321
- .join("\n");
322
- }
323
-
324
- public results() {
325
- return Object.keys(this.nodes).reduce((results: ResultDataDictonary, nodeId) => {
326
- const node = this.nodes[nodeId];
327
- if (node.result !== undefined) {
328
- results[nodeId] = node.result;
329
- }
330
- return results;
331
- }, {});
332
- }
333
-
334
- public errors() {
335
- return Object.keys(this.nodes).reduce((errors: Record<string, Error>, nodeId) => {
336
- const node = this.nodes[nodeId];
337
- if (node.error !== undefined) {
338
- errors[nodeId] = node.error;
339
- }
340
- return errors;
341
- }, {});
342
- }
343
-
344
- public async run(): Promise<ResultDataDictonary> {
345
- if (this.isRunning) {
346
- console.error("-- Already Running");
347
- }
348
- this.isRunning = true;
349
- // Nodes without pending data should run immediately.
350
- Object.keys(this.nodes).forEach((nodeId) => {
351
- const node = this.nodes[nodeId];
352
- node.pushQueueIfReady();
353
- });
354
-
355
- return new Promise((resolve, reject) => {
356
- this.onComplete = () => {
357
- this.isRunning = false;
358
- const errors = this.errors();
359
- const nodeIds = Object.keys(errors);
360
- if (nodeIds.length > 0) {
361
- reject(errors[nodeIds[0]]);
362
- } else {
363
- resolve(this.results());
364
- }
365
- };
366
- });
367
- }
368
-
369
- private runNode(node: Node) {
370
- this.runningNodes.add(node.nodeId);
371
- node.execute();
372
- }
373
-
374
- public pushQueue(node: Node) {
375
- if (this.runningNodes.size < this.concurrency) {
376
- this.runNode(node);
377
- } else {
378
- this.nodeQueue.push(node);
379
- }
380
- }
381
-
382
- public removeRunning(node: Node) {
383
- this.runningNodes.delete(node.nodeId);
384
- if (this.nodeQueue.length > 0) {
385
- const n = this.nodeQueue.shift();
386
- if (n) {
387
- this.runNode(n);
388
- }
389
- }
390
- if (this.runningNodes.size === 0) {
391
- this.onComplete();
392
- }
393
- }
394
-
395
- public appendLog(log: TransactionLog) {
396
- this.logs.push(log);
397
- }
398
-
399
- public transactionLogs() {
400
- return this.logs;
401
- }
402
-
403
- public injectResult(nodeId: string, result: ResultData) {
404
- const node = this.nodes[nodeId];
405
- if (node) {
406
- node.injectResult(result);
407
- } else {
408
- console.error("-- Invalid nodeId", nodeId);
409
- }
410
- }
411
-
412
- public resultsOf(nodeIds: Array<string>) {
413
- return nodeIds.map((nodeId) => {
414
- return this.nodes[nodeId].result;
415
- });
416
- }
417
- }
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { GraphAI, AgentFunction } from "./graphai";
4
- import { slashGPTAgent, stringTemplateAgent } from "./experimental_agents";
5
-
6
- import fs from "fs";
7
- import path from "path";
8
- import YAML from "yaml";
9
-
10
- const testAgent: AgentFunction<{ delay: number; fail: boolean }> = async (context) => {
11
- return {};
12
- };
13
-
14
- const main = async () => {
15
- const file = process.argv[2];
16
- if (file === undefined) {
17
- console.log("no file");
18
- return;
19
- }
20
- const file_path = path.resolve(process.cwd() + "/" + file);
21
- if (!fs.existsSync(file_path)) {
22
- console.log("no file");
23
- return;
24
- }
25
- try {
26
- const graph_data_file = fs.readFileSync(file_path, "utf8");
27
- const graph_data = YAML.parse(graph_data_file);
28
-
29
- const graph = new GraphAI(graph_data, { testAgent, slashGPTAgent, stringTemplateAgent });
30
- const results = await graph.run();
31
- console.log(results);
32
- } catch (e) {
33
- console.log("error", e);
34
- }
35
- };
36
-
37
- main();
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import { GraphAI } from "./graphai";
2
-
3
- export { GraphAI };
@@ -1,23 +0,0 @@
1
- import { AgentFunction } from "@/graphai";
2
- import { sleep } from "~/utils/utils";
3
-
4
- export const testAgent: AgentFunction<{ delay: number; fail: boolean }> = async (context) => {
5
- const { nodeId, retry, params, inputs } = context;
6
- console.log("executing", nodeId);
7
- await sleep(params.delay / (retry + 1));
8
-
9
- if (params.fail && retry < 2) {
10
- const result = { [nodeId]: "failed" };
11
- console.log("failed (intentional)", nodeId, retry);
12
- throw new Error("Intentional Failure");
13
- } else {
14
- const result = inputs.reduce(
15
- (result: Record<string, any>, input: Record<string, any>) => {
16
- return { ...result, ...input };
17
- },
18
- { [nodeId]: "output" },
19
- );
20
- console.log("completing", nodeId);
21
- return result;
22
- }
23
- };
@@ -1,28 +0,0 @@
1
- import { stringTemplateAgent } from "@/experimental_agents";
2
-
3
- import test from "node:test";
4
- import assert from "node:assert";
5
-
6
- test("test stringTemplateAgent simple", async () => {
7
- const result = await stringTemplateAgent({
8
- nodeId: "test",
9
- retry: 0,
10
- params: { template: "${0}: ${1}" },
11
- inputs: [{ content: "hello" }, { content: "test" }] as any,
12
- });
13
- assert.deepStrictEqual(result, {
14
- content: "hello: test",
15
- });
16
- });
17
-
18
- test("test stringTemplateAgent simple", async () => {
19
- const result = await stringTemplateAgent({
20
- nodeId: "test",
21
- retry: 0,
22
- params: { template: "${0}: ${1}", inputKey: "key" },
23
- inputs: [{ key: "hello" }, { key: "test" }],
24
- });
25
- assert.deepStrictEqual(result, {
26
- content: "hello: test",
27
- });
28
- });
@@ -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
- });