graphai 0.1.0 → 0.1.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 +47 -35
- package/lib/experimental_agents/array_agents/index.d.ts +3 -0
- package/lib/experimental_agents/array_agents/index.js +9 -0
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/pop_agent.js +15 -0
- package/lib/experimental_agents/array_agents/push_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/push_agent.js +14 -0
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +2 -0
- package/lib/experimental_agents/{array_agents.js → array_agents/shift_agent.js} +2 -17
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +28 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +38 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +17 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +30 -0
- package/lib/experimental_agents/data_agents/index.d.ts +3 -0
- package/lib/experimental_agents/data_agents/index.js +9 -0
- package/lib/experimental_agents/data_agents/total_agent.d.ts +46 -0
- package/lib/experimental_agents/data_agents/total_agent.js +51 -0
- package/lib/experimental_agents/embedding_agent.d.ts +6 -0
- package/lib/experimental_agents/embedding_agent.js +43 -0
- package/lib/experimental_agents/index.d.ts +8 -3
- package/lib/experimental_agents/index.js +8 -3
- package/lib/experimental_agents/map_agent.d.ts +4 -0
- package/lib/experimental_agents/map_agent.js +46 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +4 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +24 -0
- package/lib/experimental_agents/matrix_agents/index.d.ts +2 -0
- package/lib/experimental_agents/matrix_agents/index.js +7 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +6 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +29 -0
- package/lib/experimental_agents/nested_agent.d.ts +1 -2
- package/lib/experimental_agents/nested_agent.js +24 -8
- package/lib/experimental_agents/slashgpt_agent.d.ts +1 -1
- package/lib/experimental_agents/slashgpt_agent.js +2 -7
- package/lib/experimental_agents/sleeper_agents/index.d.ts +2 -0
- package/lib/experimental_agents/sleeper_agents/index.js +7 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +5 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +16 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +6 -0
- package/lib/experimental_agents/{sleeper_agent.js → sleeper_agents/sleeper_agent_debug.js} +4 -13
- package/lib/experimental_agents/string_agents/index.d.ts +2 -0
- package/lib/experimental_agents/string_agents/index.js +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +39 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +64 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +27 -0
- package/lib/experimental_agents/string_agents/string_template_agent.js +33 -0
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/bypass_agent.js +10 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.js +9 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.js +11 -0
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/counting_agent.js +11 -0
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +7 -0
- package/lib/experimental_agents/test_agents/index.d.ts +6 -0
- package/lib/experimental_agents/test_agents/index.js +15 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +10 -0
- package/lib/experimental_agents/token_agent.d.ts +6 -0
- package/lib/experimental_agents/token_agent.js +33 -0
- package/lib/graphai.d.ts +23 -18
- package/lib/graphai.js +106 -115
- package/lib/index.d.ts +2 -0
- package/lib/node.d.ts +30 -25
- package/lib/node.js +131 -101
- package/lib/task_manager.d.ts +20 -0
- package/lib/task_manager.js +69 -0
- package/lib/transaction_log.d.ts +27 -0
- package/lib/transaction_log.js +56 -0
- package/lib/type.d.ts +45 -32
- package/lib/type.js +1 -0
- package/lib/utils/test_agents.d.ts +2 -0
- package/lib/utils/test_agents.js +20 -0
- package/lib/utils/test_utils.d.ts +12 -0
- package/lib/utils/test_utils.js +34 -0
- package/lib/utils/utils.d.ts +3 -1
- package/lib/utils/utils.js +17 -6
- package/lib/validator.d.ts +2 -0
- package/lib/validator.js +28 -0
- package/lib/validators/agent_validator.d.ts +1 -0
- package/lib/validators/agent_validator.js +12 -0
- package/lib/validators/common.d.ts +3 -0
- package/lib/validators/common.js +6 -0
- package/lib/validators/computed_node_validator.d.ts +2 -0
- package/lib/validators/computed_node_validator.js +13 -0
- package/lib/validators/graph_data_validator.d.ts +3 -0
- package/lib/validators/graph_data_validator.js +43 -0
- package/lib/validators/nodeValidator.d.ts +2 -0
- package/lib/validators/nodeValidator.js +13 -0
- package/lib/validators/relation_validator.d.ts +2 -0
- package/lib/validators/relation_validator.js +62 -0
- package/lib/validators/static_node_validator.d.ts +2 -0
- package/lib/validators/static_node_validator.js +13 -0
- package/package.json +10 -14
- package/lib/experimental_agents/array_agents.d.ts +0 -4
- package/lib/experimental_agents/data_agent.d.ts +0 -3
- package/lib/experimental_agents/data_agent.js +0 -25
- package/lib/experimental_agents/sleeper_agent.d.ts +0 -10
- package/lib/experimental_agents/string_agent.d.ts +0 -7
- package/lib/experimental_agents/string_agent.js +0 -15
- package/lib/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -48
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortByValuesAgent = void 0;
|
|
4
|
+
// This agent returned a sorted array of one array (A) based on another array (B).
|
|
5
|
+
// The default sorting order is "decendant".
|
|
6
|
+
//
|
|
7
|
+
// Parameters:
|
|
8
|
+
// acendant: Specifies if the sorting order should be acendant. The default is "false" (decendant).
|
|
9
|
+
// Inputs:
|
|
10
|
+
// inputs[0]: Array<any>; // array to be sorted
|
|
11
|
+
// inputs[1]: Array<number>; // array of numbers for sorting
|
|
12
|
+
//
|
|
13
|
+
const sortByValuesAgent = async ({ params, inputs }) => {
|
|
14
|
+
const direction = params?.assendant ?? false ? -1 : 1;
|
|
15
|
+
const sources = inputs[0];
|
|
16
|
+
const values = inputs[1];
|
|
17
|
+
const joined = sources.map((item, index) => {
|
|
18
|
+
return { item, value: values[index] };
|
|
19
|
+
});
|
|
20
|
+
const contents = joined
|
|
21
|
+
.sort((a, b) => {
|
|
22
|
+
return (b.value - a.value) * direction;
|
|
23
|
+
})
|
|
24
|
+
.map((a) => {
|
|
25
|
+
return a.item;
|
|
26
|
+
});
|
|
27
|
+
return { contents };
|
|
28
|
+
};
|
|
29
|
+
exports.sortByValuesAgent = sortByValuesAgent;
|
|
@@ -2,19 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nestedAgent = void 0;
|
|
4
4
|
const graphai_1 = require("../graphai");
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const utils_1 = require("../utils/utils");
|
|
6
|
+
const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
7
|
+
if (taskManager) {
|
|
8
|
+
const status = taskManager.getStatus(false);
|
|
9
|
+
(0, utils_1.assert)(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
|
|
10
|
+
}
|
|
11
|
+
(0, utils_1.assert)(graphData !== undefined, "nestedAgent: graphData is required");
|
|
12
|
+
const injectionTo = params.injectionTo ??
|
|
13
|
+
inputs.map((__input, index) => {
|
|
14
|
+
return `$${index}`;
|
|
15
|
+
});
|
|
16
|
+
injectionTo.forEach((nodeId) => {
|
|
17
|
+
if (graphData.nodes[nodeId] === undefined) {
|
|
18
|
+
// If the input node does not exist, automatically create a static node
|
|
19
|
+
graphData.nodes[nodeId] = { value: {} };
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const graphAI = new graphai_1.GraphAI(graphData, agents || {}, taskManager);
|
|
7
23
|
try {
|
|
8
24
|
// Inject inputs to specified source nodes
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
injectionTo.forEach((injectToNodeId, index) => {
|
|
26
|
+
graphAI.injectValue(injectToNodeId, inputs[index]);
|
|
11
27
|
});
|
|
12
|
-
const results = await
|
|
13
|
-
log
|
|
14
|
-
return results
|
|
28
|
+
const results = await graphAI.run(false);
|
|
29
|
+
log?.push(...graphAI.transactionLogs());
|
|
30
|
+
return results;
|
|
15
31
|
}
|
|
16
32
|
catch (error) {
|
|
17
|
-
log
|
|
33
|
+
log?.push(...graphAI.transactionLogs());
|
|
18
34
|
if (error instanceof Error) {
|
|
19
35
|
console.log("Error:", error.message);
|
|
20
36
|
}
|
|
@@ -7,18 +7,13 @@ exports.slashGPTAgent = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const slashgpt_1 = require("slashgpt");
|
|
9
9
|
const config = new slashgpt_1.ChatConfig(path_1.default.resolve(__dirname));
|
|
10
|
-
const slashGPTAgent = async ({
|
|
10
|
+
const slashGPTAgent = async ({ params, inputs, debugInfo: { verbose, nodeId } }) => {
|
|
11
11
|
if (verbose) {
|
|
12
12
|
console.log("executing", nodeId, params);
|
|
13
13
|
}
|
|
14
14
|
const session = new slashgpt_1.ChatSession(config, params.manifest ?? {});
|
|
15
15
|
const query = params?.query ? [params.query] : [];
|
|
16
|
-
const contents = query.concat(inputs
|
|
17
|
-
if (typeof input === "string") {
|
|
18
|
-
return input;
|
|
19
|
-
}
|
|
20
|
-
return input.content;
|
|
21
|
-
}));
|
|
16
|
+
const contents = query.concat(inputs);
|
|
22
17
|
session.append_user_question(contents.join("\n"));
|
|
23
18
|
await session.call_loop(() => { });
|
|
24
19
|
const message = (() => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleeperAgentDebug = exports.sleeperAgent = void 0;
|
|
4
|
+
var sleeper_agent_1 = require("../../experimental_agents/sleeper_agents/sleeper_agent");
|
|
5
|
+
Object.defineProperty(exports, "sleeperAgent", { enumerable: true, get: function () { return sleeper_agent_1.sleeperAgent; } });
|
|
6
|
+
var sleeper_agent_debug_1 = require("../../experimental_agents/sleeper_agents/sleeper_agent_debug");
|
|
7
|
+
Object.defineProperty(exports, "sleeperAgentDebug", { enumerable: true, get: function () { return sleeper_agent_debug_1.sleeperAgentDebug; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sleeperAgent = void 0;
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
9
|
+
const sleeperAgent = async (context) => {
|
|
10
|
+
const { params, inputs } = context;
|
|
11
|
+
await (0, utils_1.sleep)(params?.duration ?? 10);
|
|
12
|
+
return inputs.reduce((result, input) => {
|
|
13
|
+
return (0, deepmerge_1.default)(result, input);
|
|
14
|
+
}, params.value ?? {});
|
|
15
|
+
};
|
|
16
|
+
exports.sleeperAgent = sleeperAgent;
|
|
@@ -3,22 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sleeperAgentDebug =
|
|
7
|
-
const utils_1 = require("
|
|
6
|
+
exports.sleeperAgentDebug = void 0;
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
8
|
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
9
|
-
const
|
|
10
|
-
const { params, inputs } = context;
|
|
11
|
-
await (0, utils_1.sleep)(params.duration);
|
|
12
|
-
return inputs.reduce((result, input) => {
|
|
13
|
-
return (0, deepmerge_1.default)(result, input);
|
|
14
|
-
}, params.value ?? {});
|
|
15
|
-
};
|
|
16
|
-
exports.sleeperAgent = sleeperAgent;
|
|
17
|
-
const sleeperAgentDebug = async (context) => {
|
|
18
|
-
const { nodeId, params, inputs, retry } = context;
|
|
9
|
+
const sleeperAgentDebug = async ({ params, inputs, debugInfo: { retry }, }) => {
|
|
19
10
|
await (0, utils_1.sleep)(params.duration / (retry + 1));
|
|
20
11
|
if (params.fail && retry < 2) {
|
|
21
|
-
console.log("failed (intentional)", nodeId, retry);
|
|
12
|
+
// console.log("failed (intentional)", nodeId, retry);
|
|
22
13
|
throw new Error("Intentional Failure");
|
|
23
14
|
}
|
|
24
15
|
return inputs.reduce((result, input) => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringTemplateAgent = exports.stringSplitterAgent = void 0;
|
|
4
|
+
var string_splitter_agent_1 = require("../../experimental_agents/string_agents/string_splitter_agent");
|
|
5
|
+
Object.defineProperty(exports, "stringSplitterAgent", { enumerable: true, get: function () { return string_splitter_agent_1.stringSplitterAgent; } });
|
|
6
|
+
var string_template_agent_1 = require("../../experimental_agents/string_agents/string_template_agent");
|
|
7
|
+
Object.defineProperty(exports, "stringTemplateAgent", { enumerable: true, get: function () { return string_template_agent_1.stringTemplateAgent; } });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const stringSplitterAgent: AgentFunction<{
|
|
3
|
+
chunkSize?: number;
|
|
4
|
+
overlap?: number;
|
|
5
|
+
}, {
|
|
6
|
+
contents: Array<string>;
|
|
7
|
+
}, string>;
|
|
8
|
+
declare const stringSplitterAgentInfo: {
|
|
9
|
+
name: string;
|
|
10
|
+
agent: AgentFunction<{
|
|
11
|
+
chunkSize?: number | undefined;
|
|
12
|
+
overlap?: number | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
contents: Array<string>;
|
|
15
|
+
}, string>;
|
|
16
|
+
mock: AgentFunction<{
|
|
17
|
+
chunkSize?: number | undefined;
|
|
18
|
+
overlap?: number | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
contents: Array<string>;
|
|
21
|
+
}, string>;
|
|
22
|
+
samples: {
|
|
23
|
+
inputs: string[];
|
|
24
|
+
params: {
|
|
25
|
+
chunkSize: number;
|
|
26
|
+
};
|
|
27
|
+
result: {
|
|
28
|
+
contents: string[];
|
|
29
|
+
count: number;
|
|
30
|
+
chunkSize: number;
|
|
31
|
+
overlap: number;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
description: string;
|
|
35
|
+
author: string;
|
|
36
|
+
repository: string;
|
|
37
|
+
license: string;
|
|
38
|
+
};
|
|
39
|
+
export default stringSplitterAgentInfo;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringSplitterAgent = void 0;
|
|
4
|
+
// This agent strip one long string into chunks using following parameters
|
|
5
|
+
//
|
|
6
|
+
// chunkSize: number; // default is 2048
|
|
7
|
+
// overlap: number; // default is 1/8th of chunkSize.
|
|
8
|
+
//
|
|
9
|
+
// see example
|
|
10
|
+
// tests/agents/test_string_agent.ts
|
|
11
|
+
//
|
|
12
|
+
const defaultChunkSize = 2048;
|
|
13
|
+
const stringSplitterAgent = async ({ params, inputs }) => {
|
|
14
|
+
const source = inputs[0];
|
|
15
|
+
const chunkSize = params.chunkSize ?? defaultChunkSize;
|
|
16
|
+
const overlap = params.overlap ?? Math.floor(chunkSize / 8);
|
|
17
|
+
const count = Math.floor(source.length / (chunkSize - overlap)) + 1;
|
|
18
|
+
const contents = new Array(count).fill(undefined).map((_, i) => {
|
|
19
|
+
const startIndex = i * (chunkSize - overlap);
|
|
20
|
+
return source.substring(startIndex, startIndex + chunkSize);
|
|
21
|
+
});
|
|
22
|
+
return { contents, count, chunkSize, overlap };
|
|
23
|
+
};
|
|
24
|
+
exports.stringSplitterAgent = stringSplitterAgent;
|
|
25
|
+
// for test and document
|
|
26
|
+
const sampleInput = [
|
|
27
|
+
"Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes ... the ones who see things differently -- they're not fond of rules, and they have no respect for the status quo. ... You can quote them, disagree with them, glorify or vilify them, but the only thing you can't do is ignore them because they change things. ... They push the human race forward, and while some may see them as the crazy ones, we see genius, because the people who are crazy enough to think that they can change the world, are the ones who do.",
|
|
28
|
+
];
|
|
29
|
+
const sampleParams = { chunkSize: 64 };
|
|
30
|
+
const sampleResult = {
|
|
31
|
+
contents: [
|
|
32
|
+
"Here's to the crazy ones, the misfits, the rebels, the troublema",
|
|
33
|
+
"roublemakers, the round pegs in the square holes ... the ones wh",
|
|
34
|
+
" ones who see things differently -- they're not fond of rules, a",
|
|
35
|
+
"rules, and they have no respect for the status quo. ... You can ",
|
|
36
|
+
"You can quote them, disagree with them, glorify or vilify them, ",
|
|
37
|
+
"y them, but the only thing you can't do is ignore them because t",
|
|
38
|
+
"ecause they change things. ... They push the human race forward,",
|
|
39
|
+
"forward, and while some may see them as the crazy ones, we see g",
|
|
40
|
+
"we see genius, because the people who are crazy enough to think ",
|
|
41
|
+
"o think that they can change the world, are the ones who do.",
|
|
42
|
+
" do.",
|
|
43
|
+
],
|
|
44
|
+
count: 11,
|
|
45
|
+
chunkSize: 64,
|
|
46
|
+
overlap: 8,
|
|
47
|
+
};
|
|
48
|
+
const stringSplitterAgentInfo = {
|
|
49
|
+
name: "stringSplitterAgent",
|
|
50
|
+
agent: exports.stringSplitterAgent,
|
|
51
|
+
mock: exports.stringSplitterAgent,
|
|
52
|
+
samples: [
|
|
53
|
+
{
|
|
54
|
+
inputs: sampleInput,
|
|
55
|
+
params: sampleParams,
|
|
56
|
+
result: sampleResult,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
description: "This agent strip one long string into chunks using following parameters",
|
|
60
|
+
author: "Satoshi Nakajima",
|
|
61
|
+
repository: "https://github.com/receptron/graphai",
|
|
62
|
+
license: "MIT",
|
|
63
|
+
};
|
|
64
|
+
exports.default = stringSplitterAgentInfo;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const stringTemplateAgent: AgentFunction<{
|
|
3
|
+
template: string;
|
|
4
|
+
}, Record<string, any> | string, string>;
|
|
5
|
+
declare const stringTemplateAgentInfo: {
|
|
6
|
+
name: string;
|
|
7
|
+
agent: AgentFunction<{
|
|
8
|
+
template: string;
|
|
9
|
+
}, string | Record<string, any>, string>;
|
|
10
|
+
mock: AgentFunction<{
|
|
11
|
+
template: string;
|
|
12
|
+
}, string | Record<string, any>, string>;
|
|
13
|
+
samples: {
|
|
14
|
+
inputs: string[];
|
|
15
|
+
params: {
|
|
16
|
+
template: string;
|
|
17
|
+
};
|
|
18
|
+
result: {
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
}[];
|
|
22
|
+
description: string;
|
|
23
|
+
author: string;
|
|
24
|
+
repository: string;
|
|
25
|
+
license: string;
|
|
26
|
+
};
|
|
27
|
+
export default stringTemplateAgentInfo;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringTemplateAgent = void 0;
|
|
4
|
+
// see example
|
|
5
|
+
// tests/agents/test_string_agent.ts
|
|
6
|
+
const stringTemplateAgent = async ({ params, inputs }) => {
|
|
7
|
+
const content = inputs.reduce((template, input, index) => {
|
|
8
|
+
return template.replace("${" + index + "}", input);
|
|
9
|
+
}, params.template);
|
|
10
|
+
return { content };
|
|
11
|
+
};
|
|
12
|
+
exports.stringTemplateAgent = stringTemplateAgent;
|
|
13
|
+
const sampleInput = ["hello", "test"];
|
|
14
|
+
const sampleParams = { template: "${0}: ${1}" };
|
|
15
|
+
const sampleResult = { content: "hello: test" };
|
|
16
|
+
// for test and document
|
|
17
|
+
const stringTemplateAgentInfo = {
|
|
18
|
+
name: "stringTemplateAgent",
|
|
19
|
+
agent: exports.stringTemplateAgent,
|
|
20
|
+
mock: exports.stringTemplateAgent,
|
|
21
|
+
samples: [
|
|
22
|
+
{
|
|
23
|
+
inputs: sampleInput,
|
|
24
|
+
params: sampleParams,
|
|
25
|
+
result: sampleResult,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
description: "Template agent",
|
|
29
|
+
author: "Satoshi Nakajima",
|
|
30
|
+
repository: "https://github.com/receptron/graphai",
|
|
31
|
+
license: "MIT",
|
|
32
|
+
};
|
|
33
|
+
exports.default = stringTemplateAgentInfo;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bypassAgent = void 0;
|
|
4
|
+
const bypassAgent = async (context) => {
|
|
5
|
+
if (context.inputs.length === 1) {
|
|
6
|
+
return context.inputs[0];
|
|
7
|
+
}
|
|
8
|
+
return context.inputs;
|
|
9
|
+
};
|
|
10
|
+
exports.bypassAgent = bypassAgent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copy2ArrayAgent = void 0;
|
|
4
|
+
const copy2ArrayAgent = async ({ inputs }) => {
|
|
5
|
+
return new Array(10).fill(undefined).map(() => {
|
|
6
|
+
return inputs[0];
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
exports.copy2ArrayAgent = copy2ArrayAgent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyMessageAgent = void 0;
|
|
4
|
+
const copyMessageAgent = async ({ params }) => {
|
|
5
|
+
return {
|
|
6
|
+
messages: new Array(params.count).fill(undefined).map(() => {
|
|
7
|
+
return params.message;
|
|
8
|
+
}),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.copyMessageAgent = copyMessageAgent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.countingAgent = void 0;
|
|
4
|
+
const countingAgent = async ({ params }) => {
|
|
5
|
+
return {
|
|
6
|
+
list: new Array(params.count).fill(undefined).map((_, i) => {
|
|
7
|
+
return i;
|
|
8
|
+
}),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.countingAgent = countingAgent;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { bypassAgent } from "../../experimental_agents/test_agents/bypass_agent";
|
|
2
|
+
export { echoAgent } from "../../experimental_agents/test_agents/echo_agent";
|
|
3
|
+
export { copyMessageAgent } from "../../experimental_agents/test_agents/copy_message_agent";
|
|
4
|
+
export { mergeNodeIdAgent } from "../../experimental_agents/test_agents/merge_node_id_agent";
|
|
5
|
+
export { countingAgent } from "../../experimental_agents/test_agents/counting_agent";
|
|
6
|
+
export { copy2ArrayAgent } from "../../experimental_agents/test_agents/copy2array_agent";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copy2ArrayAgent = exports.countingAgent = exports.mergeNodeIdAgent = exports.copyMessageAgent = exports.echoAgent = exports.bypassAgent = void 0;
|
|
4
|
+
var bypass_agent_1 = require("../../experimental_agents/test_agents/bypass_agent");
|
|
5
|
+
Object.defineProperty(exports, "bypassAgent", { enumerable: true, get: function () { return bypass_agent_1.bypassAgent; } });
|
|
6
|
+
var echo_agent_1 = require("../../experimental_agents/test_agents/echo_agent");
|
|
7
|
+
Object.defineProperty(exports, "echoAgent", { enumerable: true, get: function () { return echo_agent_1.echoAgent; } });
|
|
8
|
+
var copy_message_agent_1 = require("../../experimental_agents/test_agents/copy_message_agent");
|
|
9
|
+
Object.defineProperty(exports, "copyMessageAgent", { enumerable: true, get: function () { return copy_message_agent_1.copyMessageAgent; } });
|
|
10
|
+
var merge_node_id_agent_1 = require("../../experimental_agents/test_agents/merge_node_id_agent");
|
|
11
|
+
Object.defineProperty(exports, "mergeNodeIdAgent", { enumerable: true, get: function () { return merge_node_id_agent_1.mergeNodeIdAgent; } });
|
|
12
|
+
var counting_agent_1 = require("../../experimental_agents/test_agents/counting_agent");
|
|
13
|
+
Object.defineProperty(exports, "countingAgent", { enumerable: true, get: function () { return counting_agent_1.countingAgent; } });
|
|
14
|
+
var copy2array_agent_1 = require("../../experimental_agents/test_agents/copy2array_agent");
|
|
15
|
+
Object.defineProperty(exports, "copy2ArrayAgent", { enumerable: true, get: function () { return copy2array_agent_1.copy2ArrayAgent; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeNodeIdAgent = void 0;
|
|
4
|
+
const mergeNodeIdAgent = async ({ debugInfo: { nodeId }, inputs }) => {
|
|
5
|
+
// console.log("executing", nodeId);
|
|
6
|
+
return inputs.reduce((tmp, input) => {
|
|
7
|
+
return { ...tmp, ...input };
|
|
8
|
+
}, { [nodeId]: "hello" });
|
|
9
|
+
};
|
|
10
|
+
exports.mergeNodeIdAgent = mergeNodeIdAgent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tokenBoundStringsAgent = void 0;
|
|
4
|
+
const tiktoken_1 = require("tiktoken");
|
|
5
|
+
const defaultMaxToken = 5000;
|
|
6
|
+
const encoder = (0, tiktoken_1.get_encoding)("cl100k_base");
|
|
7
|
+
// This agent generate a reference string from a sorted array of strings,
|
|
8
|
+
// adding one by one until the token count exceeds the specified limit.
|
|
9
|
+
// Parameters:
|
|
10
|
+
// limit?: number; // specifies the maximum token count. The default is 5000.
|
|
11
|
+
// Inputs:
|
|
12
|
+
// inputs[0]: Array<string>; // array of string sorted by relevance.
|
|
13
|
+
// Returns:
|
|
14
|
+
// { content: string } // reference text
|
|
15
|
+
const tokenBoundStringsAgent = async ({ params, inputs }) => {
|
|
16
|
+
const contents = inputs[0];
|
|
17
|
+
const limit = params?.limit ?? defaultMaxToken;
|
|
18
|
+
const addNext = (total, index) => {
|
|
19
|
+
const length = encoder.encode(contents[index] + "\n").length;
|
|
20
|
+
if (total + length < limit && index + 1 < contents.length) {
|
|
21
|
+
return addNext(total + length, index + 1);
|
|
22
|
+
}
|
|
23
|
+
return { endIndex: index + 1, tokenCount: total };
|
|
24
|
+
};
|
|
25
|
+
const { endIndex, tokenCount } = addNext(0, 0);
|
|
26
|
+
const content = contents
|
|
27
|
+
.filter((value, index) => {
|
|
28
|
+
return index < endIndex;
|
|
29
|
+
})
|
|
30
|
+
.join("\n");
|
|
31
|
+
return { content, tokenCount, endIndex };
|
|
32
|
+
};
|
|
33
|
+
exports.tokenBoundStringsAgent = tokenBoundStringsAgent;
|
package/lib/graphai.d.ts
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
1
|
export { AgentFunction, AgentFunctionDictonary, GraphData } from "./type";
|
|
2
|
-
import { AgentFunctionDictonary, GraphData, DataSource,
|
|
2
|
+
import { AgentFunctionDictonary, GraphData, DataSource, ResultDataDictonary, ResultData, DefaultResultData } from "./type";
|
|
3
|
+
import { TransactionLog } from "./transaction_log";
|
|
3
4
|
import { ComputedNode, StaticNode } from "./node";
|
|
5
|
+
import { TaskManager } from "./task_manager";
|
|
4
6
|
type GraphNodes = Record<string, ComputedNode | StaticNode>;
|
|
5
7
|
export declare class GraphAI {
|
|
6
|
-
private
|
|
8
|
+
private readonly graphId;
|
|
9
|
+
private readonly data;
|
|
10
|
+
private readonly loop?;
|
|
11
|
+
private readonly logs;
|
|
12
|
+
readonly callbackDictonary: AgentFunctionDictonary;
|
|
13
|
+
readonly taskManager: TaskManager;
|
|
7
14
|
nodes: GraphNodes;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
isRunning: boolean;
|
|
11
|
-
private runningNodes;
|
|
12
|
-
private nodeQueue;
|
|
15
|
+
onLogCallback: (__log: TransactionLog, __isUpdate: boolean) => void;
|
|
16
|
+
verbose: boolean;
|
|
13
17
|
private onComplete;
|
|
14
|
-
private concurrency;
|
|
15
|
-
private loop?;
|
|
16
18
|
private repeatCount;
|
|
17
|
-
verbose: boolean;
|
|
18
|
-
private logs;
|
|
19
19
|
private createNodes;
|
|
20
20
|
private getValueFromResults;
|
|
21
21
|
private initializeNodes;
|
|
22
|
-
constructor(data: GraphData, callbackDictonary:
|
|
22
|
+
constructor(data: GraphData, callbackDictonary: AgentFunctionDictonary, taskManager?: TaskManager | undefined);
|
|
23
23
|
getCallback(agentId?: string): import("./type").AgentFunction<any, any, any>;
|
|
24
24
|
asString(): string;
|
|
25
|
-
results(): ResultDataDictonary
|
|
25
|
+
results<T = DefaultResultData>(all: boolean): ResultDataDictonary<T>;
|
|
26
26
|
errors(): Record<string, Error>;
|
|
27
27
|
private pushReadyNodesIntoQueue;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
private pushQueueIfReady;
|
|
29
|
+
pushQueueIfReadyAndRunning(node: ComputedNode): void;
|
|
30
30
|
pushQueue(node: ComputedNode): void;
|
|
31
|
-
|
|
31
|
+
run<T = DefaultResultData>(all?: boolean): Promise<ResultDataDictonary<T>>;
|
|
32
|
+
isRunning(): boolean;
|
|
33
|
+
onExecutionComplete(node: ComputedNode): void;
|
|
34
|
+
private processLoopIfNecessary;
|
|
35
|
+
setLoopLog(log: TransactionLog): void;
|
|
32
36
|
appendLog(log: TransactionLog): void;
|
|
37
|
+
updateLog(log: TransactionLog): void;
|
|
33
38
|
transactionLogs(): TransactionLog[];
|
|
34
|
-
injectValue(nodeId: string, value: ResultData): void;
|
|
35
|
-
resultsOf(sources: Array<DataSource
|
|
39
|
+
injectValue(nodeId: string, value: ResultData, injectFrom?: string): void;
|
|
40
|
+
resultsOf(sources: Array<DataSource>, anyInput?: boolean): any[];
|
|
36
41
|
}
|