graphai 0.0.10 → 0.0.11
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 +58 -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 +3 -0
- package/lib/experimental_agents/index.js +3 -0
- package/lib/experimental_agents/nested_agent.d.ts +6 -0
- package/lib/experimental_agents/nested_agent.js +22 -0
- package/lib/experimental_agents/slashgpt_agent.js +8 -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 +6 -1
- package/lib/graphai.js +3 -0
- package/lib/utils/utils.d.ts +1 -0
- package/lib/utils/utils.js +7 -0
- package/package.json +13 -3
- 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/samples/home.json
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"name": "fill_bath",
|
|
4
|
-
"description": "Fill the bath tub",
|
|
5
|
-
"parameters": {
|
|
6
|
-
"type": "object",
|
|
7
|
-
"properties": {
|
|
8
|
-
"temperature": {
|
|
9
|
-
"type": "number",
|
|
10
|
-
"description": "Water temperature in celsius. If omitted, 41 degree"
|
|
11
|
-
},
|
|
12
|
-
"at": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"description": "Time to fill. If omitted immediately."
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"required": []
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"name": "set_temperature",
|
|
22
|
-
"description": "Set the temperature",
|
|
23
|
-
"parameters": {
|
|
24
|
-
"type": "object",
|
|
25
|
-
"properties": {
|
|
26
|
-
"temperature": {
|
|
27
|
-
"type": "number",
|
|
28
|
-
"description": "Room temperature in celsius."
|
|
29
|
-
},
|
|
30
|
-
"location": {
|
|
31
|
-
"type": "string",
|
|
32
|
-
"enum": ["kitchen", "living room", "master bedroom", "bedroom 2", "bedroom 3", "all bedrooms"],
|
|
33
|
-
"description": "The room to set the temperature."
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"required": ["temperature", "location"]
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"name": "start_sprinkler",
|
|
41
|
-
"description": "Start the sprinkler system",
|
|
42
|
-
"parameters": {
|
|
43
|
-
"type": "object",
|
|
44
|
-
"properties": {
|
|
45
|
-
"location": {
|
|
46
|
-
"type": "string",
|
|
47
|
-
"enum": ["all", "lawn", "vegetable garden", "front yard"],
|
|
48
|
-
"description": "Specify the location to water."
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"required": ["location"]
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "take_picture",
|
|
56
|
-
"description": "Take a picture and send it",
|
|
57
|
-
"parameters": {
|
|
58
|
-
"type": "object",
|
|
59
|
-
"properties": {
|
|
60
|
-
"location": {
|
|
61
|
-
"type": "string",
|
|
62
|
-
"enum": ["entrance", "backyard", "kitchen", "living room"],
|
|
63
|
-
"description": "Specify the camera location to use."
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
"required": ["location"]
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"name": "play_music",
|
|
71
|
-
"description": "Play music",
|
|
72
|
-
"parameters": {
|
|
73
|
-
"type": "object",
|
|
74
|
-
"properties": {
|
|
75
|
-
"location": {
|
|
76
|
-
"type": "string",
|
|
77
|
-
"enum": ["living room", "master bedroom"],
|
|
78
|
-
"description": "Location to play a music."
|
|
79
|
-
},
|
|
80
|
-
"music": {
|
|
81
|
-
"type": "string",
|
|
82
|
-
"description": "Music to play, such as artist, title and playlist."
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
"required": ["location"]
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"name": "control_light",
|
|
90
|
-
"description": "Turn on/off various lights",
|
|
91
|
-
"parameters": {
|
|
92
|
-
"type": "object",
|
|
93
|
-
"properties": {
|
|
94
|
-
"location": {
|
|
95
|
-
"type": "string",
|
|
96
|
-
"enum": ["kitchen", "living room", "master bedroom", "bedroom 2", "bedroom 3", "front gate"],
|
|
97
|
-
"description": "Specify the location to control the light."
|
|
98
|
-
},
|
|
99
|
-
"switch": {
|
|
100
|
-
"type": "string",
|
|
101
|
-
"enum": ["on", "off"],
|
|
102
|
-
"description": "Specify the light switch."
|
|
103
|
-
},
|
|
104
|
-
"dim": {
|
|
105
|
-
"type": "number",
|
|
106
|
-
"description": "Specify the dim level between 0 and 1.0. The 'switch' parameter must be 'on'."
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
"required": ["location", "switch"]
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
package/samples/home.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { GraphAI, GraphData } from "@/graphai";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { slashGPTAgent } from "@/experimental_agents";
|
|
5
|
-
|
|
6
|
-
const home_actions = {
|
|
7
|
-
fill_bath: { type: "message_template", message: "Success. I started filling the bath tab." },
|
|
8
|
-
set_temperature: { type: "message_template", message: "Success. I set the temperature to {temperature} for {location}" },
|
|
9
|
-
start_sprinkler: { type: "message_template", message: "Success. I started the sprinkler for {location}" },
|
|
10
|
-
take_picture: { type: "message_template", message: "Success. I took a picture of {location}" },
|
|
11
|
-
play_music: { type: "message_template", message: "Success. I started playing {music} in {location}" },
|
|
12
|
-
control_light: { type: "message_template", message: "Success. The light switch of {location} is now {switch}." },
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const fileName = path.resolve(__dirname) + "/home.json";
|
|
16
|
-
const json_file = fs.readFileSync(fileName, "utf8");
|
|
17
|
-
const home_functions = JSON.parse(json_file);
|
|
18
|
-
|
|
19
|
-
const graph_data: GraphData = {
|
|
20
|
-
nodes: {
|
|
21
|
-
node1: {
|
|
22
|
-
source: true,
|
|
23
|
-
result: { content: "Turn on the light in the kitchen" },
|
|
24
|
-
},
|
|
25
|
-
node2: {
|
|
26
|
-
inputs: ["node1"],
|
|
27
|
-
params: {
|
|
28
|
-
manifest: {
|
|
29
|
-
skip_function_result: true,
|
|
30
|
-
actions: home_actions,
|
|
31
|
-
functions: home_functions,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const runAgent = async () => {
|
|
39
|
-
const graph = new GraphAI(graph_data, slashGPTAgent);
|
|
40
|
-
const result = await graph.run();
|
|
41
|
-
const log_path = path.resolve(__dirname) + "/../tests/logs/home.log";
|
|
42
|
-
fs.writeFileSync(log_path, JSON.stringify(graph.transactionLogs(), null, 2));
|
|
43
|
-
console.log(result["node2"]!.content);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const main = async () => {
|
|
47
|
-
await runAgent();
|
|
48
|
-
console.log("COMPLETE 1");
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
main();
|
package/samples/interaction.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { GraphAI, GraphData } from "@/graphai";
|
|
2
|
-
import * as readline from "readline";
|
|
3
|
-
import { testAgent } from "~/agents/agents";
|
|
4
|
-
import { graphDataTestRunner } from "~/utils/runner";
|
|
5
|
-
|
|
6
|
-
const getUserInput = async (question: string): Promise<string> => {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const rl = readline.createInterface({
|
|
9
|
-
input: process.stdin,
|
|
10
|
-
output: process.stdout,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
rl.question(question, (answer) => {
|
|
14
|
-
rl.close();
|
|
15
|
-
resolve(answer);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const graph_data: GraphData = {
|
|
21
|
-
nodes: {
|
|
22
|
-
node1: {
|
|
23
|
-
source: true,
|
|
24
|
-
},
|
|
25
|
-
node2: {
|
|
26
|
-
inputs: ["node1"],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const main = async () => {
|
|
32
|
-
const query = await getUserInput("Please enter your question: ");
|
|
33
|
-
console.log("query=", query);
|
|
34
|
-
graph_data.nodes.node1.result = { query };
|
|
35
|
-
|
|
36
|
-
const result = await graphDataTestRunner("interaction.yaml", graph_data, testAgent);
|
|
37
|
-
console.log(result);
|
|
38
|
-
|
|
39
|
-
console.log("COMPLETE 1");
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
main();
|
package/samples/runner.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
|
|
3
|
-
import { GraphAI, AgentFunctionDictonary, AgentFunction } from "@/graphai";
|
|
4
|
-
import { readGraphaiData } from "~/utils/file_utils";
|
|
5
|
-
import { graphDataTestRunner } from "~/utils/runner";
|
|
6
|
-
|
|
7
|
-
export const fileTestRunner = async (
|
|
8
|
-
file: string,
|
|
9
|
-
callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>,
|
|
10
|
-
callback: (graph: GraphAI) => void = () => {},
|
|
11
|
-
) => {
|
|
12
|
-
const file_path = path.resolve(__dirname) + file;
|
|
13
|
-
const graph_data = readGraphaiData(file_path);
|
|
14
|
-
return await graphDataTestRunner(file, graph_data, callbackDictonary, callback);
|
|
15
|
-
};
|
package/samples/sample_co2.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { slashGPTFuncitons2TextAgent } from "./agents/slashgpt_agent";
|
|
2
|
-
import { slashGPTAgent } from "@/experimental_agents";
|
|
3
|
-
|
|
4
|
-
import { graphDataTestRunner } from "~/utils/runner";
|
|
5
|
-
|
|
6
|
-
const graph_data = {
|
|
7
|
-
nodes: {
|
|
8
|
-
slashGPTAgent: {
|
|
9
|
-
agentId: "slashGPTAgent",
|
|
10
|
-
params: {
|
|
11
|
-
function_result: true,
|
|
12
|
-
query: "世界で協力してco2を減らす方法を教えて下さい",
|
|
13
|
-
manifest: {
|
|
14
|
-
prompt: "あなたは世界経済の専門家です。ユーザの問い合わせについて考え、10この結果をfunctionsの結果に返してください。",
|
|
15
|
-
skip_function_result: true,
|
|
16
|
-
actions: {
|
|
17
|
-
your_ideas: {
|
|
18
|
-
type: "message_template",
|
|
19
|
-
message: "dummy",
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
functions: [
|
|
23
|
-
{
|
|
24
|
-
name: "your_ideas",
|
|
25
|
-
description: "Your answer to a user's inquiry",
|
|
26
|
-
parameters: {
|
|
27
|
-
type: "object",
|
|
28
|
-
properties: {
|
|
29
|
-
methods: {
|
|
30
|
-
type: "array",
|
|
31
|
-
items: {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {
|
|
34
|
-
title: {
|
|
35
|
-
type: "string",
|
|
36
|
-
description: "title",
|
|
37
|
-
},
|
|
38
|
-
description: {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "description",
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
required: ["title", "description"],
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
function2prompt0: {
|
|
54
|
-
fork: 10,
|
|
55
|
-
params: {
|
|
56
|
-
function_data_key: "methods",
|
|
57
|
-
result_key: 0,
|
|
58
|
-
},
|
|
59
|
-
inputs: ["slashGPTAgent"],
|
|
60
|
-
agentId: "slashGPTFuncitons2TextAgent",
|
|
61
|
-
},
|
|
62
|
-
slashGPTAgent0: {
|
|
63
|
-
agentId: "slashGPTAgent",
|
|
64
|
-
fork: 10,
|
|
65
|
-
params: {
|
|
66
|
-
debug: true,
|
|
67
|
-
manifest: {
|
|
68
|
-
prompt: "ユーザの問い合わせにある文章の専門家です。専門家として、ユーザのアイデアに対して実現可能なシナリオを800文字で書いてください。",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
inputs: ["function2prompt0"],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const main = async () => {
|
|
77
|
-
const result = await graphDataTestRunner("sample_co2.yaml", graph_data, { slashGPTAgent, slashGPTFuncitons2TextAgent });
|
|
78
|
-
console.log("COMPLETE 1");
|
|
79
|
-
};
|
|
80
|
-
main();
|
package/samples/sample_gpt.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { fileTestRunner } from "./runner";
|
|
2
|
-
|
|
3
|
-
import { stringTemplateAgent, slashGPTAgent } from "@/experimental_agents";
|
|
4
|
-
|
|
5
|
-
const main = async () => {
|
|
6
|
-
await fileTestRunner("/graphs/slash_gpt.yml", { slashgpt: slashGPTAgent, stringTemplate: stringTemplateAgent });
|
|
7
|
-
};
|
|
8
|
-
main();
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { fileTestRunner } from "./runner";
|
|
2
|
-
|
|
3
|
-
import { slashGPTAgent } from "@/experimental_agents";
|
|
4
|
-
import { arxivAgent, arxiv2TextAgent } from "./agents/arxiv_agent";
|
|
5
|
-
|
|
6
|
-
const main = async () => {
|
|
7
|
-
await fileTestRunner("/graphs/arxiv.yml", { arxivAgent: arxivAgent, arxiv2TextAgent, slashGPTAgent });
|
|
8
|
-
console.log("COMPLETE 1");
|
|
9
|
-
};
|
|
10
|
-
main();
|
|
@@ -1,30 +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 slashGPTAgent: AgentFunction<{ manifest: ManifestData; query?: string; function_result?: boolean }, { content: string }> = async (context) => {
|
|
8
|
-
console.log("executing", context.nodeId, context.params);
|
|
9
|
-
const session = new ChatSession(config, context.params.manifest ?? {});
|
|
10
|
-
|
|
11
|
-
const query = context.params?.query ? [context.params.query] : [];
|
|
12
|
-
const contents = query.concat(
|
|
13
|
-
context.inputs.map((input) => {
|
|
14
|
-
return input.content;
|
|
15
|
-
}),
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
session.append_user_question(contents.join("\n"));
|
|
19
|
-
await session.call_loop(() => {});
|
|
20
|
-
const message = (() => {
|
|
21
|
-
if (context.params?.function_result) {
|
|
22
|
-
return session.history.messages().find((m) => m.role === "function_result");
|
|
23
|
-
}
|
|
24
|
-
return session.history.last_message();
|
|
25
|
-
})();
|
|
26
|
-
if (message === undefined) {
|
|
27
|
-
throw new Error("No message in the history");
|
|
28
|
-
}
|
|
29
|
-
return message;
|
|
30
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AgentFunction } from "@/graphai";
|
|
2
|
-
|
|
3
|
-
export const stringTemplateAgent: AgentFunction<{ template: string; inputKey?: string }, { content: string }> = async (context) => {
|
|
4
|
-
console.log("executing", context.nodeId, context.params);
|
|
5
|
-
const content = context.inputs.reduce((template, input, index) => {
|
|
6
|
-
return template.replace("${" + index + "}", input[context.params.inputKey ?? "content"]);
|
|
7
|
-
}, context.params.template);
|
|
8
|
-
|
|
9
|
-
return { content };
|
|
10
|
-
};
|