graphai 0.3.0 → 0.3.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 +27 -8
- package/lib/experimental_agent_filters/stream.d.ts +2 -0
- package/lib/experimental_agent_filters/stream.js +13 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +43 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +22 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +15 -0
- package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +109 -8
- package/lib/experimental_agents/data_agents/property_filter_agent.js +60 -9
- package/lib/experimental_agents/data_agents/total_agent.d.ts +13 -0
- package/lib/experimental_agents/data_agents/total_agent.js +29 -0
- package/lib/experimental_agents/graph_agents/map_agent.js +2 -2
- package/lib/experimental_agents/graph_agents/nested_agent.js +9 -12
- package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +42 -0
- package/lib/experimental_agents/llm_agents/groq_stream_agent.js +84 -0
- package/lib/experimental_agents/llm_agents/index.d.ts +2 -0
- package/lib/experimental_agents/llm_agents/index.js +2 -0
- package/lib/experimental_agents/llm_agents/openai_agent.d.ts +58 -0
- package/lib/experimental_agents/llm_agents/openai_agent.js +87 -0
- package/lib/experimental_agents/llm_agents/packages.d.ts +3 -1
- package/lib/experimental_agents/llm_agents/packages.js +5 -1
- package/lib/experimental_agents/llm_agents/slashgpt_agent.js +6 -2
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +4 -4
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +15 -4
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +13 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +20 -1
- package/lib/experimental_agents/service_agents/fetch_agent.js +1 -1
- package/lib/experimental_agents/service_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/service_agents/packages.js +3 -1
- package/lib/experimental_agents/service_agents/wikipedia.d.ts +1 -0
- package/lib/experimental_agents/service_agents/wikipedia.js +1 -0
- package/lib/experimental_agents/test_agents/stream_mock_agent.js +6 -6
- package/lib/experimental_agents/token_agent.d.ts +11 -1
- package/lib/experimental_agents/token_agent.js +30 -1
- package/lib/graphai.d.ts +3 -3
- package/lib/graphai.js +16 -15
- package/lib/node.d.ts +2 -1
- package/lib/node.js +18 -11
- package/lib/task_manager.js +3 -6
- package/lib/transaction_log.d.ts +1 -1
- package/lib/transaction_log.js +2 -1
- package/lib/type.d.ts +7 -1
- package/lib/utils/test_agents.js +2 -0
- package/lib/utils/test_utils.js +2 -2
- package/lib/validators/agent_validator.js +1 -1
- package/lib/validators/common.js +1 -1
- package/lib/validators/nodeValidator.js +2 -2
- package/package.json +13 -12
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groqStreamAgent = void 0;
|
|
4
|
+
const groq_sdk_1 = require("groq-sdk");
|
|
5
|
+
const utils_1 = require("../../utils/utils");
|
|
6
|
+
const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined;
|
|
7
|
+
//
|
|
8
|
+
// This agent takes two optional inputs, and following parameters.
|
|
9
|
+
// inputs:
|
|
10
|
+
// - [0]: query string (typically from the user), optional
|
|
11
|
+
// - [1]: array of messages from previous conversation, optional
|
|
12
|
+
//
|
|
13
|
+
// params:
|
|
14
|
+
// - model: LLM model (Llama3-8b-8192, Llama3-70b-8192, Mixtral-8x7b-32768), required.
|
|
15
|
+
// - query: Additional query string from the app to prepend the query from the user, optional.
|
|
16
|
+
// - system: System prompt (ignored if inputs[1] is specified), optional
|
|
17
|
+
// - tools: Function definitions, optional
|
|
18
|
+
// - tool_choice: Tool choice parameter, optional (default = "auto")
|
|
19
|
+
// - temperature: Controls randomness of responses, optional (default = 0.7)
|
|
20
|
+
// - max_tokens: The maximum number of tokens that the model can process in a single response, optional.
|
|
21
|
+
// - verbose: dumps the message array to the debug console, before sending it the LLM.
|
|
22
|
+
//
|
|
23
|
+
// https://console.groq.com/docs/quickstart
|
|
24
|
+
//
|
|
25
|
+
const groqStreamAgent = async ({ params, inputs, filterParams }) => {
|
|
26
|
+
(0, utils_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing.");
|
|
27
|
+
const { verbose, query, system, tools, tool_choice, max_tokens, temperature } = params;
|
|
28
|
+
const [input_query, previous_messages] = inputs;
|
|
29
|
+
// Notice that we ignore params.system if previous_message exists.
|
|
30
|
+
const messages = previous_messages && Array.isArray(previous_messages) ? previous_messages : system ? [{ role: "system", content: system }] : [];
|
|
31
|
+
const content = (query ? [query] : []).concat(input_query && typeof input_query === "string" ? [input_query] : []).join("\n");
|
|
32
|
+
if (content) {
|
|
33
|
+
messages.push({
|
|
34
|
+
role: "user",
|
|
35
|
+
content,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (verbose) {
|
|
39
|
+
console.log(messages);
|
|
40
|
+
}
|
|
41
|
+
const options = {
|
|
42
|
+
messages,
|
|
43
|
+
model: params.model,
|
|
44
|
+
temperature: temperature ?? 0.7,
|
|
45
|
+
stream: true,
|
|
46
|
+
};
|
|
47
|
+
if (max_tokens) {
|
|
48
|
+
options.max_tokens = max_tokens;
|
|
49
|
+
}
|
|
50
|
+
if (tools) {
|
|
51
|
+
options.tools = tools;
|
|
52
|
+
options.tool_choice = tool_choice ?? "auto";
|
|
53
|
+
}
|
|
54
|
+
const stream = await groq.chat.completions.create(options);
|
|
55
|
+
let lastMessage = null;
|
|
56
|
+
const contents = [];
|
|
57
|
+
for await (const message of stream) {
|
|
58
|
+
const token = message.choices[0].delta.content;
|
|
59
|
+
if (token) {
|
|
60
|
+
if (filterParams && filterParams.streamTokenCallback) {
|
|
61
|
+
filterParams.streamTokenCallback(token);
|
|
62
|
+
}
|
|
63
|
+
contents.push(token);
|
|
64
|
+
}
|
|
65
|
+
lastMessage = message;
|
|
66
|
+
}
|
|
67
|
+
if (lastMessage) {
|
|
68
|
+
lastMessage.choices[0]["message"] = [{ role: "assistant", content: contents.join("") }];
|
|
69
|
+
}
|
|
70
|
+
return lastMessage;
|
|
71
|
+
};
|
|
72
|
+
exports.groqStreamAgent = groqStreamAgent;
|
|
73
|
+
const groqStreamAgentInfo = {
|
|
74
|
+
name: "groqStreamAgent",
|
|
75
|
+
agent: exports.groqStreamAgent,
|
|
76
|
+
mock: exports.groqStreamAgent,
|
|
77
|
+
samples: [],
|
|
78
|
+
description: "Groq Stream Agent",
|
|
79
|
+
category: ["llm"],
|
|
80
|
+
author: "Receptron team",
|
|
81
|
+
repository: "https://github.com/receptron/graphai",
|
|
82
|
+
license: "MIT",
|
|
83
|
+
};
|
|
84
|
+
exports.default = groqStreamAgentInfo;
|
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./openai_agent"), exports);
|
|
17
18
|
__exportStar(require("./slashgpt_agent"), exports);
|
|
18
19
|
__exportStar(require("./groq_agent"), exports);
|
|
20
|
+
__exportStar(require("./groq_stream_agent"), exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const openAIAgent: AgentFunction<{
|
|
3
|
+
model?: string;
|
|
4
|
+
query?: string;
|
|
5
|
+
system?: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
}, Record<string, any> | string, string | Array<any>>;
|
|
9
|
+
export declare const openAIMockAgent: AgentFunction<{
|
|
10
|
+
model?: string;
|
|
11
|
+
query?: string;
|
|
12
|
+
system?: string;
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
temperature?: number;
|
|
15
|
+
}, Record<string, any> | string, string | Array<any>>;
|
|
16
|
+
declare const openaiAgentInfo: {
|
|
17
|
+
name: string;
|
|
18
|
+
agent: AgentFunction<{
|
|
19
|
+
model?: string | undefined;
|
|
20
|
+
query?: string | undefined;
|
|
21
|
+
system?: string | undefined;
|
|
22
|
+
verbose?: boolean | undefined;
|
|
23
|
+
temperature?: number | undefined;
|
|
24
|
+
}, string | Record<string, any>, string | any[]>;
|
|
25
|
+
mock: AgentFunction<{
|
|
26
|
+
model?: string | undefined;
|
|
27
|
+
query?: string | undefined;
|
|
28
|
+
system?: string | undefined;
|
|
29
|
+
verbose?: boolean | undefined;
|
|
30
|
+
temperature?: number | undefined;
|
|
31
|
+
}, string | Record<string, any>, string | any[]>;
|
|
32
|
+
samples: {
|
|
33
|
+
inputs: string[];
|
|
34
|
+
params: {};
|
|
35
|
+
result: {
|
|
36
|
+
object: string;
|
|
37
|
+
id: string;
|
|
38
|
+
choices: {
|
|
39
|
+
message: {
|
|
40
|
+
role: string;
|
|
41
|
+
content: string;
|
|
42
|
+
};
|
|
43
|
+
finish_reason: string;
|
|
44
|
+
index: number;
|
|
45
|
+
logprobs: null;
|
|
46
|
+
}[];
|
|
47
|
+
created: number;
|
|
48
|
+
model: string;
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
skipTest: boolean;
|
|
52
|
+
description: string;
|
|
53
|
+
category: string[];
|
|
54
|
+
author: string;
|
|
55
|
+
repository: string;
|
|
56
|
+
license: string;
|
|
57
|
+
};
|
|
58
|
+
export default openaiAgentInfo;
|
|
@@ -0,0 +1,87 @@
|
|
|
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.openAIMockAgent = exports.openAIAgent = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const utils_1 = require("../../utils/utils");
|
|
9
|
+
const openAIAgent = async ({ filterParams, params, inputs }) => {
|
|
10
|
+
const { verbose, query, system, temperature } = params;
|
|
11
|
+
const [input_query, previous_messages] = inputs;
|
|
12
|
+
// Notice that we ignore params.system if previous_message exists.
|
|
13
|
+
const messages = previous_messages && Array.isArray(previous_messages) ? previous_messages : system ? [{ role: "system", content: system }] : [];
|
|
14
|
+
const content = (query ? [query] : []).concat(input_query ? [input_query] : []).join("\n");
|
|
15
|
+
if (content) {
|
|
16
|
+
messages.push({
|
|
17
|
+
role: "user",
|
|
18
|
+
content,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (verbose) {
|
|
22
|
+
console.log(messages);
|
|
23
|
+
}
|
|
24
|
+
const openai = new openai_1.default();
|
|
25
|
+
const chatStream = await openai.beta.chat.completions.stream({
|
|
26
|
+
model: params.model || "gpt-3.5-turbo",
|
|
27
|
+
messages,
|
|
28
|
+
temperature: temperature ?? 0.7,
|
|
29
|
+
stream: true,
|
|
30
|
+
});
|
|
31
|
+
for await (const message of chatStream) {
|
|
32
|
+
const token = message.choices[0].delta.content;
|
|
33
|
+
if (filterParams && filterParams.streamTokenCallback && token) {
|
|
34
|
+
filterParams.streamTokenCallback(token);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const chatCompletion = await chatStream.finalChatCompletion();
|
|
38
|
+
return chatCompletion;
|
|
39
|
+
};
|
|
40
|
+
exports.openAIAgent = openAIAgent;
|
|
41
|
+
const input_sample = "this is response result";
|
|
42
|
+
const result_sample = {
|
|
43
|
+
object: "chat.completion",
|
|
44
|
+
id: "chatcmpl-9N7HxXYbwjmdbdiQE94MHoVluQhyt",
|
|
45
|
+
choices: [
|
|
46
|
+
{
|
|
47
|
+
message: {
|
|
48
|
+
role: "assistant",
|
|
49
|
+
content: input_sample,
|
|
50
|
+
},
|
|
51
|
+
finish_reason: "stop",
|
|
52
|
+
index: 0,
|
|
53
|
+
logprobs: null,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
created: 1715296589,
|
|
57
|
+
model: "gpt-3.5-turbo-0125",
|
|
58
|
+
};
|
|
59
|
+
const openAIMockAgent = async ({ filterParams }) => {
|
|
60
|
+
for await (const token of input_sample.split("")) {
|
|
61
|
+
if (filterParams && filterParams.streamTokenCallback && token) {
|
|
62
|
+
await (0, utils_1.sleep)(100);
|
|
63
|
+
filterParams.streamTokenCallback(token);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result_sample;
|
|
67
|
+
};
|
|
68
|
+
exports.openAIMockAgent = openAIMockAgent;
|
|
69
|
+
const openaiAgentInfo = {
|
|
70
|
+
name: "openAIAgent",
|
|
71
|
+
agent: exports.openAIAgent,
|
|
72
|
+
mock: exports.openAIMockAgent,
|
|
73
|
+
samples: [
|
|
74
|
+
{
|
|
75
|
+
inputs: [input_sample],
|
|
76
|
+
params: {},
|
|
77
|
+
result: result_sample,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
skipTest: true,
|
|
81
|
+
description: "Openai Agent",
|
|
82
|
+
category: ["llm"],
|
|
83
|
+
author: "Receptron team",
|
|
84
|
+
repository: "https://github.com/receptron/graphai",
|
|
85
|
+
license: "MIT",
|
|
86
|
+
};
|
|
87
|
+
exports.default = openaiAgentInfo;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import groqAgent from "../../experimental_agents/llm_agents/groq_agent";
|
|
2
|
+
import groqStreamAgent from "../../experimental_agents/llm_agents/groq_stream_agent";
|
|
2
3
|
import slashGPTAgent from "../../experimental_agents/llm_agents/slashgpt_agent";
|
|
3
|
-
|
|
4
|
+
import openAIAgent from "../../experimental_agents/llm_agents/openai_agent";
|
|
5
|
+
export { groqAgent, groqStreamAgent, slashGPTAgent, openAIAgent };
|
|
@@ -3,8 +3,12 @@ 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.slashGPTAgent = exports.groqAgent = void 0;
|
|
6
|
+
exports.openAIAgent = exports.slashGPTAgent = exports.groqStreamAgent = exports.groqAgent = void 0;
|
|
7
7
|
const groq_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/groq_agent"));
|
|
8
8
|
exports.groqAgent = groq_agent_1.default;
|
|
9
|
+
const groq_stream_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/groq_stream_agent"));
|
|
10
|
+
exports.groqStreamAgent = groq_stream_agent_1.default;
|
|
9
11
|
const slashgpt_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/slashgpt_agent"));
|
|
10
12
|
exports.slashGPTAgent = slashgpt_agent_1.default;
|
|
13
|
+
const openai_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/openai_agent"));
|
|
14
|
+
exports.openAIAgent = openai_agent_1.default;
|
|
@@ -7,7 +7,7 @@ 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 ({ params, inputs, debugInfo: { verbose, nodeId } }) => {
|
|
10
|
+
const slashGPTAgent = async ({ params, inputs, debugInfo: { verbose, nodeId }, filterParams }) => {
|
|
11
11
|
if (verbose) {
|
|
12
12
|
console.log("executing", nodeId, params);
|
|
13
13
|
}
|
|
@@ -15,7 +15,11 @@ const slashGPTAgent = async ({ params, inputs, debugInfo: { verbose, nodeId } })
|
|
|
15
15
|
const query = params?.query ? [params.query] : [];
|
|
16
16
|
const contents = query.concat(inputs);
|
|
17
17
|
session.append_user_question(contents.join("\n"));
|
|
18
|
-
await session.call_loop(() => { })
|
|
18
|
+
await session.call_loop(() => { }, (token) => {
|
|
19
|
+
if (filterParams && filterParams.streamTokenCallback && token) {
|
|
20
|
+
filterParams.streamTokenCallback(token);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
19
23
|
return session.history.messages();
|
|
20
24
|
};
|
|
21
25
|
exports.slashGPTAgent = slashGPTAgent;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AgentFunction } from "../../graphai";
|
|
2
|
-
export declare const dotProductAgent: AgentFunction<Record<never, never>, Array<number>, Array<Array<number
|
|
2
|
+
export declare const dotProductAgent: AgentFunction<Record<never, never>, Array<number>, Array<Array<number>> | Array<number>>;
|
|
3
3
|
declare const dotProductAgentInfo: {
|
|
4
4
|
name: string;
|
|
5
|
-
agent: AgentFunction<Record<never, never>, number[], number[][]>;
|
|
6
|
-
mock: AgentFunction<Record<never, never>, number[], number[][]>;
|
|
5
|
+
agent: AgentFunction<Record<never, never>, number[], number[] | number[][]>;
|
|
6
|
+
mock: AgentFunction<Record<never, never>, number[], number[] | number[][]>;
|
|
7
7
|
samples: {
|
|
8
|
-
inputs: number[][][];
|
|
8
|
+
inputs: (number[] | number[][])[];
|
|
9
9
|
params: {};
|
|
10
10
|
result: number[];
|
|
11
11
|
}[];
|
|
@@ -5,14 +5,14 @@ exports.dotProductAgent = void 0;
|
|
|
5
5
|
// typically used to calculate cosine similarity of embedding vectors.
|
|
6
6
|
// Inputs:
|
|
7
7
|
// inputs[0]: Two dimentional array of numbers.
|
|
8
|
-
// inputs[1]:
|
|
8
|
+
// inputs[1]: One dimentional array of numbers.
|
|
9
9
|
// Outputs:
|
|
10
10
|
// { contents: Array<number> } // array of docProduct of each vector (A[]) and vector B
|
|
11
11
|
const dotProductAgent = async ({ inputs }) => {
|
|
12
12
|
const embeddings = inputs[0];
|
|
13
|
-
const reference = inputs[1]
|
|
13
|
+
const reference = inputs[1];
|
|
14
14
|
if (embeddings[0].length != reference.length) {
|
|
15
|
-
throw new Error(
|
|
15
|
+
throw new Error(`dotProduct: Length of vectors do not match. ${embeddings[0].length}, ${reference.length}`);
|
|
16
16
|
}
|
|
17
17
|
const contents = embeddings.map((embedding) => {
|
|
18
18
|
return embedding.reduce((dotProduct, value, index) => {
|
|
@@ -34,11 +34,22 @@ const dotProductAgentInfo = {
|
|
|
34
34
|
[3, 4],
|
|
35
35
|
[5, 6],
|
|
36
36
|
],
|
|
37
|
-
[
|
|
37
|
+
[3, 2],
|
|
38
38
|
],
|
|
39
39
|
params: {},
|
|
40
40
|
result: [7, 17, 27],
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
inputs: [
|
|
44
|
+
[
|
|
45
|
+
[1, 2],
|
|
46
|
+
[2, 3],
|
|
47
|
+
],
|
|
48
|
+
[1, 2],
|
|
49
|
+
],
|
|
50
|
+
params: {},
|
|
51
|
+
result: [5, 8],
|
|
52
|
+
},
|
|
42
53
|
],
|
|
43
54
|
description: "dotProduct Agent",
|
|
44
55
|
category: [],
|
|
@@ -10,7 +10,19 @@ declare const sortByValuesAgentInfo: {
|
|
|
10
10
|
mock: AgentFunction<{
|
|
11
11
|
assendant?: boolean | undefined;
|
|
12
12
|
}, any[], any[]>;
|
|
13
|
-
samples:
|
|
13
|
+
samples: ({
|
|
14
|
+
inputs: (string[] | number[])[];
|
|
15
|
+
params: {
|
|
16
|
+
assendant?: undefined;
|
|
17
|
+
};
|
|
18
|
+
result: string[];
|
|
19
|
+
} | {
|
|
20
|
+
inputs: (string[] | number[])[];
|
|
21
|
+
params: {
|
|
22
|
+
assendant: boolean;
|
|
23
|
+
};
|
|
24
|
+
result: string[];
|
|
25
|
+
})[];
|
|
14
26
|
description: string;
|
|
15
27
|
category: never[];
|
|
16
28
|
author: string;
|
|
@@ -31,7 +31,26 @@ const sortByValuesAgentInfo = {
|
|
|
31
31
|
name: "sortByValuesAgent",
|
|
32
32
|
agent: exports.sortByValuesAgent,
|
|
33
33
|
mock: exports.sortByValuesAgent,
|
|
34
|
-
samples: [
|
|
34
|
+
samples: [
|
|
35
|
+
{
|
|
36
|
+
inputs: [
|
|
37
|
+
["banana", "orange", "lemon", "apple"],
|
|
38
|
+
[2, 5, 6, 4],
|
|
39
|
+
],
|
|
40
|
+
params: {},
|
|
41
|
+
result: ["lemon", "orange", "apple", "banana"],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
inputs: [
|
|
45
|
+
["banana", "orange", "lemon", "apple"],
|
|
46
|
+
[2, 5, 6, 4],
|
|
47
|
+
],
|
|
48
|
+
params: {
|
|
49
|
+
assendant: true,
|
|
50
|
+
},
|
|
51
|
+
result: ["banana", "apple", "orange", "lemon"],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
35
54
|
description: "sortByValues Agent",
|
|
36
55
|
category: [],
|
|
37
56
|
author: "Receptron team",
|
|
@@ -3,6 +3,8 @@ 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.fetchAgent = void 0;
|
|
6
|
+
exports.wikipediaAgent = exports.fetchAgent = void 0;
|
|
7
|
+
const wikipedia_1 = __importDefault(require("../../experimental_agents/service_agents/wikipedia"));
|
|
8
|
+
exports.wikipediaAgent = wikipedia_1.default;
|
|
7
9
|
const fetch_agent_1 = __importDefault(require("../../experimental_agents/service_agents/fetch_agent"));
|
|
8
10
|
exports.fetchAgent = fetch_agent_1.default;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.streamMockAgent = void 0;
|
|
4
4
|
const utils_1 = require("../../utils/utils");
|
|
5
|
-
const streamMockAgent = async ({ params }) => {
|
|
6
|
-
const message = params.message;
|
|
5
|
+
const streamMockAgent = async ({ params, filterParams }) => {
|
|
6
|
+
const message = params.message || "";
|
|
7
7
|
for await (const token of message.split("")) {
|
|
8
|
-
if (
|
|
9
|
-
|
|
8
|
+
if (filterParams.streamTokenCallback) {
|
|
9
|
+
filterParams.streamTokenCallback(token);
|
|
10
10
|
}
|
|
11
11
|
await (0, utils_1.sleep)(params.sleep || 100);
|
|
12
12
|
}
|
|
@@ -19,9 +19,9 @@ const streamMockAgentInfo = {
|
|
|
19
19
|
agent: exports.streamMockAgent,
|
|
20
20
|
mock: exports.streamMockAgent,
|
|
21
21
|
samples: [],
|
|
22
|
-
description: "
|
|
22
|
+
description: "Stream mock agent",
|
|
23
23
|
category: [],
|
|
24
|
-
author: "
|
|
24
|
+
author: "Isamu Arimoto",
|
|
25
25
|
repository: "https://github.com/receptron/graphai",
|
|
26
26
|
license: "MIT",
|
|
27
27
|
};
|
|
@@ -16,7 +16,17 @@ declare const tokenBoundStringsAgentInfo: {
|
|
|
16
16
|
}, {
|
|
17
17
|
content: string;
|
|
18
18
|
}, string[]>;
|
|
19
|
-
samples:
|
|
19
|
+
samples: {
|
|
20
|
+
inputs: string[][];
|
|
21
|
+
params: {
|
|
22
|
+
limit: number;
|
|
23
|
+
};
|
|
24
|
+
result: {
|
|
25
|
+
content: string;
|
|
26
|
+
tokenCount: number;
|
|
27
|
+
endIndex: number;
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
20
30
|
description: string;
|
|
21
31
|
category: never[];
|
|
22
32
|
author: string;
|
|
@@ -35,7 +35,36 @@ const tokenBoundStringsAgentInfo = {
|
|
|
35
35
|
name: "tokenBoundStringsAgent",
|
|
36
36
|
agent: exports.tokenBoundStringsAgent,
|
|
37
37
|
mock: exports.tokenBoundStringsAgent,
|
|
38
|
-
samples: [
|
|
38
|
+
samples: [
|
|
39
|
+
{
|
|
40
|
+
inputs: [
|
|
41
|
+
[
|
|
42
|
+
"Here's to the crazy ones. The misfits. The rebels. The troublemakers.",
|
|
43
|
+
"The round pegs in the square holes. The ones who see things differently.",
|
|
44
|
+
"They're not fond of rules. And they have no respect for the status quo.",
|
|
45
|
+
"You can quote them, disagree with them, glorify or vilify them.",
|
|
46
|
+
"About the only thing you can't do is ignore them.",
|
|
47
|
+
"Because they change things.",
|
|
48
|
+
"They push the human race forward.",
|
|
49
|
+
"And while some may see them as the crazy ones, we see genius.",
|
|
50
|
+
"Because the people who are crazy enough to think they can change the world, are the ones who do.",
|
|
51
|
+
],
|
|
52
|
+
],
|
|
53
|
+
params: {
|
|
54
|
+
limit: 80,
|
|
55
|
+
},
|
|
56
|
+
result: {
|
|
57
|
+
content: "Here's to the crazy ones. The misfits. The rebels. The troublemakers.\n" +
|
|
58
|
+
"The round pegs in the square holes. The ones who see things differently.\n" +
|
|
59
|
+
"They're not fond of rules. And they have no respect for the status quo.\n" +
|
|
60
|
+
"You can quote them, disagree with them, glorify or vilify them.\n" +
|
|
61
|
+
"About the only thing you can't do is ignore them.\n" +
|
|
62
|
+
"Because they change things.",
|
|
63
|
+
tokenCount: 79,
|
|
64
|
+
endIndex: 6,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
39
68
|
description: "token bound Agent",
|
|
40
69
|
category: [],
|
|
41
70
|
author: "Receptron team",
|
package/lib/graphai.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class GraphAI {
|
|
|
10
10
|
private readonly data;
|
|
11
11
|
private readonly loop?;
|
|
12
12
|
private readonly logs;
|
|
13
|
-
readonly
|
|
13
|
+
readonly agentFunctionDictionary: AgentFunctionDictonary;
|
|
14
14
|
readonly taskManager: TaskManager;
|
|
15
15
|
readonly agentFilters: AgentFilterInfo[];
|
|
16
16
|
readonly retryLimit?: number;
|
|
@@ -22,11 +22,11 @@ export declare class GraphAI {
|
|
|
22
22
|
private createNodes;
|
|
23
23
|
private getValueFromResults;
|
|
24
24
|
private initializeNodes;
|
|
25
|
-
constructor(data: GraphData,
|
|
25
|
+
constructor(data: GraphData, agentFunctionDictionary: AgentFunctionDictonary, options?: {
|
|
26
26
|
agentFilters?: AgentFilterInfo[] | undefined;
|
|
27
27
|
taskManager?: TaskManager | undefined;
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
getAgentFunction(agentId?: string): import("./type").AgentFunction<any, any, any>;
|
|
30
30
|
asString(): string;
|
|
31
31
|
results<T = DefaultResultData>(all: boolean): ResultDataDictonary<T>;
|
|
32
32
|
errors(): Record<string, Error>;
|
package/lib/graphai.js
CHANGED
|
@@ -6,6 +6,7 @@ const utils_1 = require("./utils/utils");
|
|
|
6
6
|
const validator_1 = require("./validator");
|
|
7
7
|
const task_manager_1 = require("./task_manager");
|
|
8
8
|
const defaultConcurrency = 8;
|
|
9
|
+
const latestVersion = 0.3;
|
|
9
10
|
class GraphAI {
|
|
10
11
|
// This method is called when either the GraphAI obect was created,
|
|
11
12
|
// or we are about to start n-th iteration (n>2).
|
|
@@ -39,8 +40,7 @@ class GraphAI {
|
|
|
39
40
|
});
|
|
40
41
|
return nodes;
|
|
41
42
|
}
|
|
42
|
-
getValueFromResults(
|
|
43
|
-
const source = (0, utils_1.parseNodeName)(key, this.version);
|
|
43
|
+
getValueFromResults(source, results) {
|
|
44
44
|
return (0, utils_1.getDataFromSource)(source.nodeId ? results[source.nodeId] : undefined, source);
|
|
45
45
|
}
|
|
46
46
|
// for static
|
|
@@ -58,26 +58,26 @@ class GraphAI {
|
|
|
58
58
|
const update = node?.update;
|
|
59
59
|
if (update && previousResults) {
|
|
60
60
|
const result = this.getValueFromResults(update, previousResults);
|
|
61
|
-
this.injectValue(nodeId, result, update);
|
|
61
|
+
this.injectValue(nodeId, result, update.nodeId);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
constructor(data,
|
|
66
|
+
constructor(data, agentFunctionDictionary, options = { taskManager: undefined, agentFilters: [] }) {
|
|
67
67
|
this.logs = [];
|
|
68
68
|
this.onLogCallback = (__log, __isUpdate) => { };
|
|
69
69
|
this.repeatCount = 0;
|
|
70
|
-
if (!data.version) {
|
|
71
|
-
console.log("------------
|
|
70
|
+
if (!data.version && !options.taskManager) {
|
|
71
|
+
console.log("------------ missing version number");
|
|
72
72
|
}
|
|
73
|
-
this.version = data.version ??
|
|
74
|
-
if (this.version <
|
|
75
|
-
console.log(
|
|
73
|
+
this.version = data.version ?? latestVersion;
|
|
74
|
+
if (this.version < latestVersion) {
|
|
75
|
+
console.log(`------------ upgrade to ${latestVersion}!`);
|
|
76
76
|
}
|
|
77
77
|
this.retryLimit = data.retry; // optional
|
|
78
78
|
this.graphId = URL.createObjectURL(new Blob()).slice(-36);
|
|
79
79
|
this.data = data;
|
|
80
|
-
this.
|
|
80
|
+
this.agentFunctionDictionary = agentFunctionDictionary;
|
|
81
81
|
this.taskManager = options.taskManager ?? new task_manager_1.TaskManager(data.concurrency ?? defaultConcurrency);
|
|
82
82
|
this.agentFilters = options.agentFilters ?? [];
|
|
83
83
|
this.loop = data.loop;
|
|
@@ -85,13 +85,13 @@ class GraphAI {
|
|
|
85
85
|
this.onComplete = () => {
|
|
86
86
|
console.error("-- SOMETHING IS WRONG: onComplete is called without run()");
|
|
87
87
|
};
|
|
88
|
-
(0, validator_1.validateGraphData)(data, Object.keys(
|
|
88
|
+
(0, validator_1.validateGraphData)(data, Object.keys(agentFunctionDictionary));
|
|
89
89
|
this.nodes = this.createNodes(data);
|
|
90
90
|
this.initializeNodes();
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
if (agentId && this.
|
|
94
|
-
return this.
|
|
92
|
+
getAgentFunction(agentId) {
|
|
93
|
+
if (agentId && this.agentFunctionDictionary[agentId]) {
|
|
94
|
+
return this.agentFunctionDictionary[agentId];
|
|
95
95
|
}
|
|
96
96
|
throw new Error("No agent: " + agentId);
|
|
97
97
|
}
|
|
@@ -198,7 +198,8 @@ class GraphAI {
|
|
|
198
198
|
this.initializeNodes(results);
|
|
199
199
|
// Notice that we need to check the while condition *after* calling initializeNodes.
|
|
200
200
|
if (loop.while) {
|
|
201
|
-
const
|
|
201
|
+
const source = (0, utils_1.parseNodeName)(loop.while, this.version);
|
|
202
|
+
const value = this.getValueFromResults(source, this.results(true));
|
|
202
203
|
// NOTE: We treat an empty array as false.
|
|
203
204
|
if (Array.isArray(value) ? value.length === 0 : !value) {
|
|
204
205
|
return false; // while condition is not met
|
package/lib/node.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class ComputedNode extends Node {
|
|
|
16
16
|
readonly graphId: string;
|
|
17
17
|
readonly isResult: boolean;
|
|
18
18
|
readonly params: NodeDataParams;
|
|
19
|
+
private readonly filterParams;
|
|
19
20
|
private readonly dynamicParams;
|
|
20
21
|
readonly nestedGraph?: GraphData;
|
|
21
22
|
readonly retryLimit: number;
|
|
@@ -49,7 +50,7 @@ export declare class ComputedNode extends Node {
|
|
|
49
50
|
}
|
|
50
51
|
export declare class StaticNode extends Node {
|
|
51
52
|
value?: ResultData;
|
|
52
|
-
readonly update?:
|
|
53
|
+
readonly update?: DataSource;
|
|
53
54
|
readonly isResult: boolean;
|
|
54
55
|
readonly isStaticNode = true;
|
|
55
56
|
readonly isComputedNode = false;
|