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.
- package/README.md +104 -10
- package/lib/experimental_agents/array_agents.d.ts +4 -0
- package/lib/experimental_agents/array_agents.js +30 -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 +4 -0
- package/lib/experimental_agents/index.js +4 -0
- package/lib/experimental_agents/nested_agent.d.ts +6 -0
- package/lib/experimental_agents/nested_agent.js +24 -0
- package/lib/experimental_agents/slashgpt_agent.js +11 -6
- 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.js +9 -5
- package/lib/graphai.d.ts +31 -8
- package/lib/graphai.js +138 -43
- package/lib/graphai_cli.js +1 -1
- package/lib/utils/utils.d.ts +1 -0
- package/lib/utils/utils.js +7 -0
- package/package.json +14 -4
- 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 -19
- package/samples/express.ts +0 -47
- package/samples/graphs/arxiv.yml +0 -25
- package/samples/graphs/slash_gpt.yml +0 -28
- package/samples/home.json +0 -112
- package/samples/home.ts +0 -51
- package/samples/interaction.ts +0 -42
- package/samples/runner.ts +0 -15
- package/samples/sample_co2.ts +0 -80
- package/samples/sample_gpt.ts +0 -8
- package/samples/sample_paper_ai.ts +0 -10
- package/src/experimental_agents/index.ts +0 -2
- package/src/experimental_agents/slashgpt_agent.ts +0 -30
- package/src/experimental_agents/string_agent.ts +0 -10
- package/src/graphai.ts +0 -417
- package/src/graphai_cli.ts +0 -37
- package/src/index.ts +0 -3
- package/tests/agents/agents.ts +0 -23
- package/tests/agents/test_string_agent.ts +0 -28
- 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
package/lib/graphai.js
CHANGED
|
@@ -11,22 +11,38 @@ var NodeState;
|
|
|
11
11
|
NodeState["Injected"] = "injected";
|
|
12
12
|
NodeState["Dispatched"] = "dispatched";
|
|
13
13
|
})(NodeState || (exports.NodeState = NodeState = {}));
|
|
14
|
+
const parseNodeName = (name) => {
|
|
15
|
+
const parts = name.split(".");
|
|
16
|
+
if (parts.length == 1) {
|
|
17
|
+
return { sourceNodeId: parts[0] };
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return { sourceNodeId: parts[0], propId: parts[1] };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
14
23
|
class Node {
|
|
15
24
|
constructor(nodeId, forkIndex, data, graph) {
|
|
25
|
+
this.inputProps = {}; // optional properties for input
|
|
16
26
|
this.waitlist = new Set(); // List of nodes which need data from this node.
|
|
17
27
|
this.state = NodeState.Waiting;
|
|
18
28
|
this.result = undefined;
|
|
19
29
|
this.retryCount = 0;
|
|
20
30
|
this.nodeId = nodeId;
|
|
21
31
|
this.forkIndex = forkIndex;
|
|
22
|
-
this.inputs = data.inputs ?? []
|
|
32
|
+
this.inputs = (data.inputs ?? []).map((input) => {
|
|
33
|
+
const { sourceNodeId, propId } = parseNodeName(input);
|
|
34
|
+
if (propId) {
|
|
35
|
+
this.inputProps[sourceNodeId] = propId;
|
|
36
|
+
}
|
|
37
|
+
return sourceNodeId;
|
|
38
|
+
});
|
|
23
39
|
this.pendings = new Set(this.inputs);
|
|
24
40
|
this.params = data.params ?? {};
|
|
25
|
-
this.agentId = data.agentId;
|
|
41
|
+
this.agentId = data.agentId ?? graph.agentId;
|
|
26
42
|
this.fork = data.fork;
|
|
27
43
|
this.retryLimit = data.retry ?? 0;
|
|
28
44
|
this.timeout = data.timeout;
|
|
29
|
-
this.source =
|
|
45
|
+
this.source = this.agentId === undefined;
|
|
30
46
|
this.outputs = data.outputs;
|
|
31
47
|
this.graph = graph;
|
|
32
48
|
}
|
|
@@ -54,10 +70,18 @@ class Node {
|
|
|
54
70
|
}
|
|
55
71
|
pushQueueIfReady() {
|
|
56
72
|
if (this.pendings.size === 0 && !this.source) {
|
|
73
|
+
// If input property is specified, we need to ensure that the property value exists.
|
|
74
|
+
Object.keys(this.inputProps).forEach((nodeId) => {
|
|
75
|
+
const [result] = this.graph.resultsOf([nodeId]);
|
|
76
|
+
const propId = this.inputProps[nodeId];
|
|
77
|
+
if (!result || !(propId in result)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
57
81
|
this.graph.pushQueue(this);
|
|
58
82
|
}
|
|
59
83
|
}
|
|
60
|
-
|
|
84
|
+
injectValue(value) {
|
|
61
85
|
if (this.source) {
|
|
62
86
|
const log = {
|
|
63
87
|
nodeId: this.nodeId,
|
|
@@ -65,13 +89,13 @@ class Node {
|
|
|
65
89
|
state: NodeState.Injected,
|
|
66
90
|
startTime: Date.now(),
|
|
67
91
|
endTime: Date.now(),
|
|
68
|
-
result,
|
|
92
|
+
result: value,
|
|
69
93
|
};
|
|
70
94
|
this.graph.appendLog(log);
|
|
71
|
-
this.setResult(
|
|
95
|
+
this.setResult(value, NodeState.Injected);
|
|
72
96
|
}
|
|
73
97
|
else {
|
|
74
|
-
console.error("-
|
|
98
|
+
console.error("- injectValue called on non-source node.", this.nodeId);
|
|
75
99
|
}
|
|
76
100
|
}
|
|
77
101
|
setResult(result, state) {
|
|
@@ -85,15 +109,21 @@ class Node {
|
|
|
85
109
|
}
|
|
86
110
|
async execute() {
|
|
87
111
|
const results = this.graph.resultsOf(this.inputs);
|
|
112
|
+
this.inputs.forEach((nodeId, index) => {
|
|
113
|
+
const propId = this.inputProps[nodeId];
|
|
114
|
+
if (propId) {
|
|
115
|
+
results[index] = results[index][propId];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
88
118
|
const transactionId = Date.now();
|
|
89
119
|
const log = {
|
|
90
120
|
nodeId: this.nodeId,
|
|
91
|
-
retryCount: this.retryCount,
|
|
121
|
+
retryCount: this.retryCount > 0 ? this.retryCount : undefined,
|
|
92
122
|
state: NodeState.Executing,
|
|
93
123
|
startTime: transactionId,
|
|
94
124
|
agentId: this.agentId,
|
|
95
125
|
params: this.params,
|
|
96
|
-
inputs: results,
|
|
126
|
+
inputs: results.length > 0 ? results : undefined,
|
|
97
127
|
};
|
|
98
128
|
this.graph.appendLog(log);
|
|
99
129
|
this.state = NodeState.Executing;
|
|
@@ -111,12 +141,16 @@ class Node {
|
|
|
111
141
|
}
|
|
112
142
|
try {
|
|
113
143
|
const callback = this.graph.getCallback(this.agentId);
|
|
144
|
+
const localLog = [];
|
|
114
145
|
const result = await callback({
|
|
115
146
|
nodeId: this.nodeId,
|
|
116
147
|
retry: this.retryCount,
|
|
117
148
|
params: this.params,
|
|
118
149
|
inputs: results,
|
|
119
150
|
forkIndex: this.forkIndex,
|
|
151
|
+
verbose: this.graph.verbose,
|
|
152
|
+
agents: this.graph.callbackDictonary,
|
|
153
|
+
log: localLog,
|
|
120
154
|
});
|
|
121
155
|
if (this.transactionId !== transactionId) {
|
|
122
156
|
console.log(`-- ${this.nodeId}: transactionId mismatch`);
|
|
@@ -124,11 +158,20 @@ class Node {
|
|
|
124
158
|
}
|
|
125
159
|
log.endTime = Date.now();
|
|
126
160
|
log.result = result;
|
|
161
|
+
if (localLog.length > 0) {
|
|
162
|
+
log.log = localLog;
|
|
163
|
+
}
|
|
127
164
|
const outputs = this.outputs;
|
|
128
165
|
if (outputs !== undefined) {
|
|
129
|
-
Object.keys(
|
|
166
|
+
Object.keys(outputs).forEach((outputId) => {
|
|
130
167
|
const nodeId = outputs[outputId];
|
|
131
|
-
|
|
168
|
+
const value = result[outputId];
|
|
169
|
+
if (value) {
|
|
170
|
+
this.graph.injectValue(nodeId, value);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.error("-- Invalid outputId", outputId, result);
|
|
174
|
+
}
|
|
132
175
|
});
|
|
133
176
|
log.state = NodeState.Dispatched;
|
|
134
177
|
this.state = NodeState.Dispatched;
|
|
@@ -160,20 +203,10 @@ class Node {
|
|
|
160
203
|
}
|
|
161
204
|
const defaultConcurrency = 8;
|
|
162
205
|
class GraphAI {
|
|
163
|
-
|
|
164
|
-
this.isRunning = false;
|
|
165
|
-
this.runningNodes = new Set();
|
|
166
|
-
this.nodeQueue = [];
|
|
167
|
-
this.logs = [];
|
|
168
|
-
this.callbackDictonary = typeof callbackDictonary === "function" ? { _default: callbackDictonary } : callbackDictonary;
|
|
169
|
-
this.concurrency = data.concurrency ?? defaultConcurrency;
|
|
170
|
-
this.onComplete = () => {
|
|
171
|
-
console.error("-- SOMETHING IS WRONG: onComplete is called without run()");
|
|
172
|
-
};
|
|
206
|
+
createNodes(data) {
|
|
173
207
|
const nodeId2forkedNodeIds = {};
|
|
174
208
|
const forkedNodeId2Index = {};
|
|
175
|
-
|
|
176
|
-
this.nodes = Object.keys(data.nodes).reduce((nodes, nodeId) => {
|
|
209
|
+
const nodes = Object.keys(data.nodes).reduce((nodes, nodeId) => {
|
|
177
210
|
const fork = data.nodes[nodeId].fork;
|
|
178
211
|
if (fork) {
|
|
179
212
|
// For fork, change the nodeId and increase the node
|
|
@@ -191,8 +224,8 @@ class GraphAI {
|
|
|
191
224
|
return nodes;
|
|
192
225
|
}, {});
|
|
193
226
|
// Generate the waitlist for each node, and update the pendings in case of forked node.
|
|
194
|
-
Object.keys(
|
|
195
|
-
const node =
|
|
227
|
+
Object.keys(nodes).forEach((nodeId) => {
|
|
228
|
+
const node = nodes[nodeId];
|
|
196
229
|
node.pendings.forEach((pending) => {
|
|
197
230
|
// If the pending(previous) node is forking
|
|
198
231
|
if (nodeId2forkedNodeIds[pending]) {
|
|
@@ -200,36 +233,74 @@ class GraphAI {
|
|
|
200
233
|
if (node.fork) {
|
|
201
234
|
// 1:1 if current nodes are also forking.
|
|
202
235
|
const newPendingId = nodeId2forkedNodeIds[pending][forkedNodeId2Index[nodeId]];
|
|
203
|
-
|
|
236
|
+
nodes[newPendingId].waitlist.add(nodeId); // previousNode
|
|
204
237
|
node.pendings.add(newPendingId);
|
|
205
238
|
}
|
|
206
239
|
else {
|
|
207
240
|
// 1:n if current node is not forking.
|
|
208
241
|
nodeId2forkedNodeIds[pending].forEach((newPendingId) => {
|
|
209
|
-
|
|
242
|
+
nodes[newPendingId].waitlist.add(nodeId); // previousNode
|
|
210
243
|
node.pendings.add(newPendingId);
|
|
211
244
|
});
|
|
212
245
|
}
|
|
213
246
|
node.pendings.delete(pending);
|
|
214
247
|
}
|
|
215
248
|
else {
|
|
216
|
-
|
|
249
|
+
if (nodes[pending]) {
|
|
250
|
+
nodes[pending].waitlist.add(nodeId); // previousNode
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
console.error(`--- invalid input ${pending} for node, ${nodeId}`);
|
|
254
|
+
}
|
|
217
255
|
}
|
|
218
256
|
});
|
|
219
257
|
node.inputs = Array.from(node.pendings); // for fork.
|
|
220
258
|
});
|
|
259
|
+
return nodes;
|
|
260
|
+
}
|
|
261
|
+
getValueFromResults(key, results) {
|
|
262
|
+
const { sourceNodeId, propId } = parseNodeName(key);
|
|
263
|
+
const result = results[sourceNodeId];
|
|
264
|
+
return result ? (propId ? result[propId] : result) : undefined;
|
|
265
|
+
}
|
|
266
|
+
initializeNodes(previousResults) {
|
|
221
267
|
// If the result property is specified, inject it.
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
268
|
+
// If the previousResults exists (indicating we are in a loop),
|
|
269
|
+
// process the next property (nodeId or nodeId.propId).
|
|
270
|
+
Object.keys(this.data.nodes).forEach((nodeId) => {
|
|
271
|
+
const node = this.data.nodes[nodeId];
|
|
272
|
+
const { value, next } = node;
|
|
273
|
+
if (value) {
|
|
274
|
+
this.injectValue(nodeId, value);
|
|
275
|
+
}
|
|
276
|
+
if (next && previousResults) {
|
|
277
|
+
const result = this.getValueFromResults(next, previousResults);
|
|
278
|
+
if (result) {
|
|
279
|
+
this.injectValue(nodeId, result);
|
|
280
|
+
}
|
|
227
281
|
}
|
|
228
282
|
});
|
|
229
283
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
284
|
+
constructor(data, callbackDictonary) {
|
|
285
|
+
this.isRunning = false;
|
|
286
|
+
this.runningNodes = new Set();
|
|
287
|
+
this.nodeQueue = [];
|
|
288
|
+
this.repeatCount = 0;
|
|
289
|
+
this.logs = [];
|
|
290
|
+
this.data = data;
|
|
291
|
+
this.callbackDictonary = callbackDictonary;
|
|
292
|
+
this.concurrency = data.concurrency ?? defaultConcurrency;
|
|
293
|
+
this.loop = data.loop;
|
|
294
|
+
this.agentId = data.agentId;
|
|
295
|
+
this.verbose = data.verbose === true;
|
|
296
|
+
this.onComplete = () => {
|
|
297
|
+
console.error("-- SOMETHING IS WRONG: onComplete is called without run()");
|
|
298
|
+
};
|
|
299
|
+
this.nodes = this.createNodes(data);
|
|
300
|
+
this.initializeNodes();
|
|
301
|
+
}
|
|
302
|
+
getCallback(agentId) {
|
|
303
|
+
if (agentId && this.callbackDictonary[agentId]) {
|
|
233
304
|
return this.callbackDictonary[agentId];
|
|
234
305
|
}
|
|
235
306
|
throw new Error("No agent: " + agentId);
|
|
@@ -259,16 +330,19 @@ class GraphAI {
|
|
|
259
330
|
return errors;
|
|
260
331
|
}, {});
|
|
261
332
|
}
|
|
262
|
-
|
|
263
|
-
if (this.isRunning) {
|
|
264
|
-
console.error("-- Already Running");
|
|
265
|
-
}
|
|
266
|
-
this.isRunning = true;
|
|
333
|
+
pushReadyNodesIntoQueue() {
|
|
267
334
|
// Nodes without pending data should run immediately.
|
|
268
335
|
Object.keys(this.nodes).forEach((nodeId) => {
|
|
269
336
|
const node = this.nodes[nodeId];
|
|
270
337
|
node.pushQueueIfReady();
|
|
271
338
|
});
|
|
339
|
+
}
|
|
340
|
+
async run() {
|
|
341
|
+
if (this.isRunning) {
|
|
342
|
+
console.error("-- Already Running");
|
|
343
|
+
}
|
|
344
|
+
this.isRunning = true;
|
|
345
|
+
this.pushReadyNodesIntoQueue();
|
|
272
346
|
return new Promise((resolve, reject) => {
|
|
273
347
|
this.onComplete = () => {
|
|
274
348
|
this.isRunning = false;
|
|
@@ -304,6 +378,27 @@ class GraphAI {
|
|
|
304
378
|
}
|
|
305
379
|
}
|
|
306
380
|
if (this.runningNodes.size === 0) {
|
|
381
|
+
this.repeatCount++;
|
|
382
|
+
const loop = this.loop;
|
|
383
|
+
if (loop && (loop.count === undefined || this.repeatCount < loop.count)) {
|
|
384
|
+
const results = this.results(); // results from previous loop
|
|
385
|
+
this.isRunning = false; // temporarily stop it
|
|
386
|
+
this.nodes = this.createNodes(this.data);
|
|
387
|
+
this.initializeNodes(results);
|
|
388
|
+
const checkWhileCondition = () => {
|
|
389
|
+
if (loop.while) {
|
|
390
|
+
const value = this.getValueFromResults(loop.while, this.results());
|
|
391
|
+
// NOTE: We treat an empty array as false.
|
|
392
|
+
return Array.isArray(value) ? value.length > 0 : !!value;
|
|
393
|
+
}
|
|
394
|
+
return true;
|
|
395
|
+
};
|
|
396
|
+
if (checkWhileCondition()) {
|
|
397
|
+
this.isRunning = true; // restore it
|
|
398
|
+
this.pushReadyNodesIntoQueue();
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
307
402
|
this.onComplete();
|
|
308
403
|
}
|
|
309
404
|
}
|
|
@@ -313,10 +408,10 @@ class GraphAI {
|
|
|
313
408
|
transactionLogs() {
|
|
314
409
|
return this.logs;
|
|
315
410
|
}
|
|
316
|
-
|
|
411
|
+
injectValue(nodeId, value) {
|
|
317
412
|
const node = this.nodes[nodeId];
|
|
318
413
|
if (node) {
|
|
319
|
-
node.
|
|
414
|
+
node.injectValue(value);
|
|
320
415
|
}
|
|
321
416
|
else {
|
|
322
417
|
console.error("-- Invalid nodeId", nodeId);
|
package/lib/graphai_cli.js
CHANGED
|
@@ -9,7 +9,7 @@ const experimental_agents_1 = require("./experimental_agents");
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const yaml_1 = __importDefault(require("yaml"));
|
|
12
|
-
const testAgent = async (
|
|
12
|
+
const testAgent = async () => {
|
|
13
13
|
return {};
|
|
14
14
|
};
|
|
15
15
|
const main = async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Asynchronous data flow execution engine to make it simple to build LLM apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"bin":
|
|
6
|
+
"bin": {
|
|
7
|
+
"graphai": "lib/graphai_cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"./lib"
|
|
11
|
+
],
|
|
7
12
|
"scripts": {
|
|
8
13
|
"build": "tsc && tsc-alias",
|
|
9
|
-
"eslint": "eslint --fix --ext
|
|
14
|
+
"eslint": "eslint --fix --ext .ts ./src ./tests ./samples",
|
|
10
15
|
"format": "prettier --write '{src,tests,samples}/**/*.ts' .eslintrc.js",
|
|
11
16
|
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
12
17
|
"cli": "npx ts-node -r tsconfig-paths/register ./src/graphai_cli.ts",
|
|
18
|
+
"samples": "npx ts-node -r tsconfig-paths/register samples/sample_runner.ts",
|
|
13
19
|
"sample": "npx ts-node -r tsconfig-paths/register"
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
@@ -23,11 +29,14 @@
|
|
|
23
29
|
},
|
|
24
30
|
"homepage": "https://github.com/snakajima/graphai#readme",
|
|
25
31
|
"devDependencies": {
|
|
32
|
+
"@inquirer/prompts": "^5.0.0",
|
|
26
33
|
"@types/express": "^4.17.21",
|
|
27
34
|
"@types/node": "^20.8.7",
|
|
28
35
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
29
36
|
"@typescript-eslint/parser": "^6.8.0",
|
|
30
37
|
"arxiv-api-ts": "^1.0.3",
|
|
38
|
+
"deepmerge": "^4.3.1",
|
|
39
|
+
"dotenv": "^16.4.5",
|
|
31
40
|
"eslint": "^7.32.0 || ^8.2.0",
|
|
32
41
|
"eslint-plugin-import": "^2.25.2",
|
|
33
42
|
"express": "^4.19.2",
|
|
@@ -37,7 +46,8 @@
|
|
|
37
46
|
"ts-node": "^10.9.1",
|
|
38
47
|
"tsc-alias": "^1.8.8",
|
|
39
48
|
"tsconfig-paths": "^4.2.0",
|
|
40
|
-
"typescript": "^5.2.2"
|
|
49
|
+
"typescript": "^5.2.2",
|
|
50
|
+
"wikipedia": "^2.1.2"
|
|
41
51
|
},
|
|
42
52
|
"dependencies": {
|
|
43
53
|
"yaml": "^2.3.3"
|
package/.eslintrc.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
es2021: true,
|
|
4
|
-
node: true,
|
|
5
|
-
},
|
|
6
|
-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
7
|
-
overrides: [
|
|
8
|
-
{
|
|
9
|
-
env: {
|
|
10
|
-
node: true,
|
|
11
|
-
},
|
|
12
|
-
files: [".eslintrc.{js,cjs}"],
|
|
13
|
-
parserOptions: {
|
|
14
|
-
sourceType: "script",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
parser: "@typescript-eslint/parser",
|
|
19
|
-
parserOptions: {
|
|
20
|
-
ecmaVersion: "latest",
|
|
21
|
-
sourceType: "module",
|
|
22
|
-
},
|
|
23
|
-
plugins: ["@typescript-eslint"],
|
|
24
|
-
rules: {
|
|
25
|
-
indent: ["error", 2],
|
|
26
|
-
"linebreak-style": ["error", "unix"],
|
|
27
|
-
quotes: ["error", "double"],
|
|
28
|
-
semi: ["error", "always"],
|
|
29
|
-
},
|
|
30
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Node.js CI
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
pull_request
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
build:
|
|
11
|
-
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
|
|
14
|
-
strategy:
|
|
15
|
-
matrix:
|
|
16
|
-
node-version: [18.x, 20.x]
|
|
17
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
18
|
-
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@v4
|
|
21
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
22
|
-
uses: actions/setup-node@v4
|
|
23
|
-
with:
|
|
24
|
-
node-version: ${{ matrix.node-version }}
|
|
25
|
-
cache: 'npm'
|
|
26
|
-
- run: yarn install
|
|
27
|
-
- run: cd tests/http-server/docs/ && npx http-server &
|
|
28
|
-
- run: yarn test
|
package/.prettierrc
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import search from "arXiv-api-ts";
|
|
2
|
-
|
|
3
|
-
import { AgentFunction } from "@/graphai";
|
|
4
|
-
|
|
5
|
-
type arxivData = { id: string; title: string; summary: string };
|
|
6
|
-
|
|
7
|
-
const search_arxiv_papers = async (keywords: string[], limit = 10) => {
|
|
8
|
-
const includes = keywords.map((k) => {
|
|
9
|
-
return { name: k };
|
|
10
|
-
});
|
|
11
|
-
const papers = await search({
|
|
12
|
-
searchQueryParams: [
|
|
13
|
-
{
|
|
14
|
-
include: includes,
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
sortBy: "lastUpdatedDate",
|
|
18
|
-
sortOrder: "descending",
|
|
19
|
-
start: 0,
|
|
20
|
-
maxResults: limit,
|
|
21
|
-
});
|
|
22
|
-
return papers.entries || [];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const arxivAgent: AgentFunction<{ keywords: string[]; limit: number }, arxivData[]> = async (context) => {
|
|
26
|
-
const { keywords, limit } = context.params;
|
|
27
|
-
const arxivResult = await search_arxiv_papers(keywords, limit);
|
|
28
|
-
// console.log("executing", arxivResult, context.params.keywords);
|
|
29
|
-
|
|
30
|
-
const result = arxivResult.map((r: any) => {
|
|
31
|
-
const { id, title, summary } = r;
|
|
32
|
-
return { id, title, summary };
|
|
33
|
-
});
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const arxiv2TextAgent: AgentFunction<{}, Record<string, any>, string[]> = async (context) => {
|
|
38
|
-
const result = (context.inputs[0] || [])
|
|
39
|
-
.map((r: any) => {
|
|
40
|
-
const { id, title, summary } = r;
|
|
41
|
-
return ["id:", id, "title:", title, "summary:", summary].join("\n");
|
|
42
|
-
})
|
|
43
|
-
.join("\n\n\n");
|
|
44
|
-
return { content: result };
|
|
45
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { AgentFunction } from "@/graphai";
|
|
3
|
-
import { ChatSession, ChatConfig, ManifestData } from "slashgpt";
|
|
4
|
-
|
|
5
|
-
const config = new ChatConfig(path.resolve(__dirname));
|
|
6
|
-
|
|
7
|
-
export const slashGPTFuncitons2TextAgent: AgentFunction<
|
|
8
|
-
{ function_data_key: string; result_key: number },
|
|
9
|
-
Record<string, string>,
|
|
10
|
-
{ function_data: { [key: string]: string[] } }
|
|
11
|
-
> = async (context) => {
|
|
12
|
-
const { params } = context;
|
|
13
|
-
const result = (context?.inputs[0].function_data[params.function_data_key] || []).map((r: any) => {
|
|
14
|
-
const { title, description } = r;
|
|
15
|
-
return ["title:", title, "description:", description].join("\n");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return { content: result[context.forkIndex ?? 0] };
|
|
19
|
-
};
|
package/samples/express.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// npx ts-node samples/express.ts
|
|
2
|
-
import { GraphAI, AgentFunction } from "@/graphai";
|
|
3
|
-
|
|
4
|
-
import express from "express";
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
const graphAISample = async (req: express.Request, res: express.Response) => {
|
|
9
|
-
const graph_data = {
|
|
10
|
-
nodes: {
|
|
11
|
-
node1: {
|
|
12
|
-
params: {},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
concurrency: 8,
|
|
16
|
-
};
|
|
17
|
-
const testFunction: AgentFunction<Record<string, string>> = async (context) => {
|
|
18
|
-
console.log("hello");
|
|
19
|
-
return {};
|
|
20
|
-
};
|
|
21
|
-
const graph = new GraphAI(graph_data, testFunction);
|
|
22
|
-
const response = await graph.run();
|
|
23
|
-
res.json({ result: response });
|
|
24
|
-
res.end();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const hello = async (req: express.Request, res: express.Response) => {
|
|
28
|
-
const { params, query } = req;
|
|
29
|
-
res.json({
|
|
30
|
-
result: [
|
|
31
|
-
{
|
|
32
|
-
message: "hello",
|
|
33
|
-
params,
|
|
34
|
-
query,
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
});
|
|
38
|
-
res.end();
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
app.use(express.json());
|
|
42
|
-
app.get("/", hello);
|
|
43
|
-
app.get("/mock", graphAISample);
|
|
44
|
-
|
|
45
|
-
const server = app.listen(8080, () => {
|
|
46
|
-
console.log("Running Server");
|
|
47
|
-
});
|
package/samples/graphs/arxiv.yml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
searchArxiv:
|
|
3
|
-
params:
|
|
4
|
-
keywords:
|
|
5
|
-
- llm
|
|
6
|
-
- gpt
|
|
7
|
-
limit: 10
|
|
8
|
-
agentId: arxivAgent
|
|
9
|
-
arxiv2TextAgent:
|
|
10
|
-
inputs: [searchArxiv]
|
|
11
|
-
agentId: arxiv2TextAgent
|
|
12
|
-
slashGPTAgent:
|
|
13
|
-
inputs: [arxiv2TextAgent]
|
|
14
|
-
agentId: slashGPTAgent
|
|
15
|
-
params:
|
|
16
|
-
query: |
|
|
17
|
-
与えられたそれぞれの論文の要点をまとめ、以下の項目で日本語で出力せよ。それぞれの項目は最大でも180文字以内に要約せよ。
|
|
18
|
-
```
|
|
19
|
-
論文名:タイトルの日本語訳
|
|
20
|
-
キーワード:この論文のキーワード
|
|
21
|
-
課題:この論文が解決する課題
|
|
22
|
-
手法:この論文が提案する手法,
|
|
23
|
-
結果:提案手法によって得られた結果
|
|
24
|
-
```
|
|
25
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
nodes:
|
|
2
|
-
node1:
|
|
3
|
-
agentId: slashgpt
|
|
4
|
-
params:
|
|
5
|
-
query: Come up with ten business ideas for AI startup
|
|
6
|
-
node2:
|
|
7
|
-
agentId: stringTemplate
|
|
8
|
-
inputs: [node1]
|
|
9
|
-
params:
|
|
10
|
-
template: |
|
|
11
|
-
Please evaluate following business ideas.
|
|
12
|
-
${0}
|
|
13
|
-
node3:
|
|
14
|
-
agentId: slashgpt
|
|
15
|
-
inputs: [node2]
|
|
16
|
-
node4:
|
|
17
|
-
agentId: stringTemplate
|
|
18
|
-
inputs: [node1, node3]
|
|
19
|
-
params:
|
|
20
|
-
template: |
|
|
21
|
-
Please pick the winner of this business idea contest.
|
|
22
|
-
[ideas]
|
|
23
|
-
${0}
|
|
24
|
-
[evalutations]
|
|
25
|
-
${1}
|
|
26
|
-
node5:
|
|
27
|
-
agentId: slashgpt
|
|
28
|
-
inputs: [node4]
|