graphai 0.0.1 → 0.0.2
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 +20 -1
- package/lib/flow.d.ts +6 -6
- package/lib/flow.js +3 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/package.json +4 -4
- package/src/flow.ts +6 -6
- package/src/index.ts +2 -2
- package/tests/sample_flow.ts +2 -2
package/README.md
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GraphAI
|
|
2
|
+
|
|
3
|
+
GraphAI is a TypeScript library, which makes it easy to create AI applications that need to call asynchrouns AI API calls multiple times. You just need to describe dependencies among those API calls in a single JSON/YAML file, create a GraphAI object with it, and run it.
|
|
4
|
+
|
|
5
|
+
Here is an example:
|
|
6
|
+
|
|
7
|
+
```YAML
|
|
8
|
+
nodes:
|
|
9
|
+
taskA:
|
|
10
|
+
params:
|
|
11
|
+
// app-specific parameters for taskA
|
|
12
|
+
taskB:
|
|
13
|
+
params:
|
|
14
|
+
// app-specific parameters for taskB
|
|
15
|
+
taskC:
|
|
16
|
+
params:
|
|
17
|
+
// app-specific parameters for taskC
|
|
18
|
+
inputs: [taskA, taskB]
|
|
19
|
+
```
|
|
20
|
+
|
package/lib/flow.d.ts
CHANGED
|
@@ -30,13 +30,13 @@ declare class Node {
|
|
|
30
30
|
retryCount: number;
|
|
31
31
|
constructor(key: string, data: NodeData);
|
|
32
32
|
asString(): string;
|
|
33
|
-
complete(result: Record<string, any>, nodes: Record<string, Node>, graph:
|
|
34
|
-
reportError(result: Record<string, any>, nodes: Record<string, Node>, graph:
|
|
35
|
-
removePending(key: string, graph:
|
|
36
|
-
payload(graph:
|
|
37
|
-
executeIfReady(graph:
|
|
33
|
+
complete(result: Record<string, any>, nodes: Record<string, Node>, graph: GraphAI): void;
|
|
34
|
+
reportError(result: Record<string, any>, nodes: Record<string, Node>, graph: GraphAI): void;
|
|
35
|
+
removePending(key: string, graph: GraphAI): void;
|
|
36
|
+
payload(graph: GraphAI): Record<string, any>;
|
|
37
|
+
executeIfReady(graph: GraphAI): void;
|
|
38
38
|
}
|
|
39
|
-
export declare class
|
|
39
|
+
export declare class GraphAI {
|
|
40
40
|
nodes: Record<string, Node>;
|
|
41
41
|
callback: FlowCallback;
|
|
42
42
|
private runningNodes;
|
package/lib/flow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GraphAI = exports.FlowCommand = exports.NodeState = void 0;
|
|
4
4
|
var NodeState;
|
|
5
5
|
(function (NodeState) {
|
|
6
6
|
NodeState[NodeState["Waiting"] = 0] = "Waiting";
|
|
@@ -69,7 +69,7 @@ class Node {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
class
|
|
72
|
+
class GraphAI {
|
|
73
73
|
constructor(data, callback) {
|
|
74
74
|
this.callback = callback;
|
|
75
75
|
this.runningNodes = new Set();
|
|
@@ -115,4 +115,4 @@ class Graph {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
exports.
|
|
118
|
+
exports.GraphAI = GraphAI;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { GraphAI } from "./flow";
|
|
2
|
+
export { GraphAI };
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GraphAI = void 0;
|
|
4
4
|
const flow_1 = require("./flow");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "GraphAI", { enumerable: true, get: function () { return flow_1.GraphAI; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Asynchronous data flow execution engine to make it simple to build LLM apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/snakajima/
|
|
14
|
+
"url": "git+https://github.com/snakajima/graphai"
|
|
15
15
|
},
|
|
16
16
|
"author": "Satoshi Nakajima",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"bugs": {
|
|
19
|
-
"url": "https://github.com/snakajima/
|
|
19
|
+
"url": "https://github.com/snakajima/graphai/issues"
|
|
20
20
|
},
|
|
21
|
-
"homepage": "https://github.com/snakajima/
|
|
21
|
+
"homepage": "https://github.com/snakajima/graphai#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^20.8.7",
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
package/src/flow.ts
CHANGED
|
@@ -49,7 +49,7 @@ class Node {
|
|
|
49
49
|
return `${this.key}: ${this.state} ${[...this.waitlist]}`
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public complete(result: Record<string, any>, nodes: Record<string, Node>, graph:
|
|
52
|
+
public complete(result: Record<string, any>, nodes: Record<string, Node>, graph: GraphAI) {
|
|
53
53
|
this.state = NodeState.Completed;
|
|
54
54
|
this.result = result;
|
|
55
55
|
this.waitlist.forEach(key => {
|
|
@@ -59,7 +59,7 @@ class Node {
|
|
|
59
59
|
graph.remove(this);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public reportError(result: Record<string, any>, nodes: Record<string, Node>, graph:
|
|
62
|
+
public reportError(result: Record<string, any>, nodes: Record<string, Node>, graph: GraphAI) {
|
|
63
63
|
this.state = NodeState.Failed;
|
|
64
64
|
this.result = result;
|
|
65
65
|
if (this.retryCount < this.retryLimit) {
|
|
@@ -71,12 +71,12 @@ class Node {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
public removePending(key: string, graph:
|
|
74
|
+
public removePending(key: string, graph: GraphAI) {
|
|
75
75
|
this.pendings.delete(key);
|
|
76
76
|
this.executeIfReady(graph);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
public payload(graph:
|
|
79
|
+
public payload(graph: GraphAI) {
|
|
80
80
|
const foo: Record<string, any> = {};
|
|
81
81
|
return this.inputs.reduce((payload, key) => {
|
|
82
82
|
payload[key] = graph.nodes[key].result;
|
|
@@ -84,7 +84,7 @@ class Node {
|
|
|
84
84
|
}, foo);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
public executeIfReady(graph:
|
|
87
|
+
public executeIfReady(graph: GraphAI) {
|
|
88
88
|
if (this.pendings.size == 0) {
|
|
89
89
|
this.state = NodeState.Executing;
|
|
90
90
|
graph.add(this);
|
|
@@ -93,7 +93,7 @@ class Node {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export class
|
|
96
|
+
export class GraphAI {
|
|
97
97
|
public nodes: Record<string, Node>
|
|
98
98
|
public callback: FlowCallback;
|
|
99
99
|
private runningNodes: Set<string>;
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphAI } from "./flow";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { GraphAI };
|
package/tests/sample_flow.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { GraphAI, FlowCommand } from "../src/flow";
|
|
3
3
|
|
|
4
4
|
import { readManifestData } from "../src/file_utils";
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ const test = async (file: string) => {
|
|
|
7
7
|
const file_path = path.resolve(__dirname) + file;
|
|
8
8
|
const graph_data = readManifestData(file_path);
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
const graph = new
|
|
10
|
+
const graph = new GraphAI(graph_data, async (params) => {
|
|
11
11
|
if (params.cmd == FlowCommand.Execute) {
|
|
12
12
|
const node = params.node;
|
|
13
13
|
console.log("executing", node, params.params, params.payload)
|