graphai 0.0.9 → 0.0.10

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.
@@ -0,0 +1,2 @@
1
+ export * from "./string_agent";
2
+ export * from "./slashgpt_agent";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./string_agent"), exports);
18
+ __exportStar(require("./slashgpt_agent"), exports);
@@ -0,0 +1,9 @@
1
+ import { AgentFunction } from "../graphai";
2
+ import { ManifestData } from "slashgpt";
3
+ export declare const slashGPTAgent: AgentFunction<{
4
+ manifest: ManifestData;
5
+ query?: string;
6
+ function_result?: boolean;
7
+ }, {
8
+ content: string;
9
+ }>;
@@ -0,0 +1,30 @@
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.slashGPTAgent = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const slashgpt_1 = require("slashgpt");
9
+ const config = new slashgpt_1.ChatConfig(path_1.default.resolve(__dirname));
10
+ const slashGPTAgent = async (context) => {
11
+ console.log("executing", context.nodeId, context.params);
12
+ const session = new slashgpt_1.ChatSession(config, context.params.manifest ?? {});
13
+ const query = context.params?.query ? [context.params.query] : [];
14
+ const contents = query.concat(context.inputs.map((input) => {
15
+ return input.content;
16
+ }));
17
+ session.append_user_question(contents.join("\n"));
18
+ await session.call_loop(() => { });
19
+ const message = (() => {
20
+ if (context.params?.function_result) {
21
+ return session.history.messages().find((m) => m.role === "function_result");
22
+ }
23
+ return session.history.last_message();
24
+ })();
25
+ if (message === undefined) {
26
+ throw new Error("No message in the history");
27
+ }
28
+ return message;
29
+ };
30
+ exports.slashGPTAgent = slashGPTAgent;
@@ -0,0 +1,7 @@
1
+ import { AgentFunction } from "../graphai";
2
+ export declare const stringTemplateAgent: AgentFunction<{
3
+ template: string;
4
+ inputKey?: string;
5
+ }, {
6
+ content: string;
7
+ }>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringTemplateAgent = void 0;
4
+ const stringTemplateAgent = async (context) => {
5
+ console.log("executing", context.nodeId, context.params);
6
+ const content = context.inputs.reduce((template, input, index) => {
7
+ return template.replace("${" + index + "}", input[context.params.inputKey ?? "content"]);
8
+ }, context.params.template);
9
+ return { content };
10
+ };
11
+ exports.stringTemplateAgent = stringTemplateAgent;
package/lib/graphai.d.ts CHANGED
@@ -89,7 +89,7 @@ export declare class GraphAI {
89
89
  asString(): string;
90
90
  results(): ResultDataDictonary<Record<string, any>>;
91
91
  errors(): Record<string, Error>;
92
- run(): Promise<unknown>;
92
+ run(): Promise<ResultDataDictonary>;
93
93
  private runNode;
94
94
  pushQueue(node: Node): void;
95
95
  removeRunning(node: Node): void;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const graphai_1 = require("./graphai");
8
+ const experimental_agents_1 = require("./experimental_agents");
8
9
  const fs_1 = __importDefault(require("fs"));
9
10
  const path_1 = __importDefault(require("path"));
10
11
  const yaml_1 = __importDefault(require("yaml"));
@@ -25,7 +26,7 @@ const main = async () => {
25
26
  try {
26
27
  const graph_data_file = fs_1.default.readFileSync(file_path, "utf8");
27
28
  const graph_data = yaml_1.default.parse(graph_data_file);
28
- const graph = new graphai_1.GraphAI(graph_data, { test: testAgent });
29
+ const graph = new graphai_1.GraphAI(graph_data, { testAgent, slashGPTAgent: experimental_agents_1.slashGPTAgent, stringTemplateAgent: experimental_agents_1.stringTemplateAgent });
29
30
  const results = await graph.run();
30
31
  console.log(results);
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Asynchronous data flow execution engine to make it simple to build LLM apps.",
5
5
  "main": "lib/index.js",
6
6
  "bin": "lib/graphai_cli.js",
@@ -34,12 +34,12 @@ export const arxivAgent: AgentFunction<{ keywords: string[]; limit: number }, ar
34
34
  return result;
35
35
  };
36
36
 
37
- export const arxiv2TextAgent: AgentFunction<{}, string, string[]> = async (context) => {
37
+ export const arxiv2TextAgent: AgentFunction<{}, Record<string, any>, string[]> = async (context) => {
38
38
  const result = (context.inputs[0] || [])
39
39
  .map((r: any) => {
40
40
  const { id, title, summary } = r;
41
41
  return ["id:", id, "title:", title, "summary:", summary].join("\n");
42
42
  })
43
43
  .join("\n\n\n");
44
- return result;
44
+ return { content: result };
45
45
  };
@@ -6,7 +6,7 @@ const config = new ChatConfig(path.resolve(__dirname));
6
6
 
7
7
  export const slashGPTFuncitons2TextAgent: AgentFunction<
8
8
  { function_data_key: string; result_key: number },
9
- string,
9
+ Record<string, string>,
10
10
  { function_data: { [key: string]: string[] } }
11
11
  > = async (context) => {
12
12
  const { params } = context;
@@ -15,36 +15,5 @@ export const slashGPTFuncitons2TextAgent: AgentFunction<
15
15
  return ["title:", title, "description:", description].join("\n");
16
16
  });
17
17
 
18
- return result[context.forkIndex ?? 0];
19
- };
20
-
21
- export const slashGPTAgent: AgentFunction<
22
- { manifest: ManifestData; prompt: string; function_result?: boolean; debug?: boolean },
23
- { answer: string },
24
- string
25
- > = async (context) => {
26
- const { params } = context;
27
- if (params.debug) {
28
- console.log("executing", context.nodeId, context);
29
- }
30
- const session = new ChatSession(config, params?.manifest ?? {});
31
-
32
- const prompt = params?.prompt ?? [context.inputs].filter((a) => a !== undefined).join("\n\n");
33
- // console.log(prompt);
34
- session.append_user_question(prompt);
35
-
36
- await session.call_loop(() => {});
37
-
38
- // console.log(session.history)
39
- const message = (() => {
40
- if (params.function_result) {
41
- return session.history.messages().find((m) => m.role === "function_result");
42
- }
43
- return session.history.last_message();
44
- })();
45
- if (message === undefined) {
46
- throw new Error("No message in the history");
47
- }
48
- const result = { answer: message.content, function_data: message.function_data };
49
- return result;
18
+ return { content: result[context.forkIndex ?? 0] };
50
19
  };
@@ -13,7 +13,7 @@ nodes:
13
13
  inputs: [arxiv2TextAgent]
14
14
  agentId: slashGPTAgent
15
15
  params:
16
- prompt: |
16
+ query: |
17
17
  与えられたそれぞれの論文の要点をまとめ、以下の項目で日本語で出力せよ。それぞれの項目は最大でも180文字以内に要約せよ。
18
18
  ```
19
19
  論文名:タイトルの日本語訳
@@ -1,19 +1,28 @@
1
1
  nodes:
2
2
  node1:
3
+ agentId: slashgpt
3
4
  params:
4
- prompt: Come up with ten business ideas for AI startup
5
+ query: Come up with ten business ideas for AI startup
5
6
  node2:
7
+ agentId: stringTemplate
6
8
  inputs: [node1]
7
9
  params:
8
- prompt: |
10
+ template: |
9
11
  Please evaluate following business ideas.
10
12
  ${0}
11
13
  node3:
12
- inputs: [node1, node2]
14
+ agentId: slashgpt
15
+ inputs: [node2]
16
+ node4:
17
+ agentId: stringTemplate
18
+ inputs: [node1, node3]
13
19
  params:
14
- prompt: |
20
+ template: |
15
21
  Please pick the winner of this business idea contest.
16
22
  [ideas]
17
23
  ${0}
18
24
  [evalutations]
19
25
  ${1}
26
+ node5:
27
+ agentId: slashgpt
28
+ inputs: [node4]
@@ -0,0 +1,112 @@
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
+ ]
@@ -0,0 +1,51 @@
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();
@@ -1,8 +1,7 @@
1
1
  import { GraphAI, GraphData } from "@/graphai";
2
2
  import * as readline from "readline";
3
- import path from "path";
4
- import * as fs from "fs";
5
3
  import { testAgent } from "~/agents/agents";
4
+ import { graphDataTestRunner } from "~/utils/runner";
6
5
 
7
6
  const getUserInput = async (question: string): Promise<string> => {
8
7
  return new Promise((resolve, reject) => {
@@ -29,20 +28,14 @@ const graph_data: GraphData = {
29
28
  },
30
29
  };
31
30
 
32
- const runAgent = async (query: string) => {
31
+ const main = async () => {
32
+ const query = await getUserInput("Please enter your question: ");
33
33
  console.log("query=", query);
34
34
  graph_data.nodes.node1.result = { query };
35
- const graph = new GraphAI(graph_data, testAgent);
36
- // graph.injectResult("node1", { query });
37
- const result = await graph.run();
38
- const log_path = path.resolve(__dirname) + "/../tests/logs/interaction.log";
39
- fs.writeFileSync(log_path, JSON.stringify(graph.transactionLogs(), null, 2));
35
+
36
+ const result = await graphDataTestRunner("interaction.yaml", graph_data, testAgent);
40
37
  console.log(result);
41
- };
42
38
 
43
- const main = async () => {
44
- const query = await getUserInput("Please enter your question: ");
45
- await runAgent(query);
46
39
  console.log("COMPLETE 1");
47
40
  };
48
41
 
@@ -0,0 +1,15 @@
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
+ };
@@ -1,7 +1,7 @@
1
- import { GraphAI, AgentFunction } from "@/graphai";
2
- import { readGraphaiData } from "~/utils/file_utils";
1
+ import { slashGPTFuncitons2TextAgent } from "./agents/slashgpt_agent";
2
+ import { slashGPTAgent } from "@/experimental_agents";
3
3
 
4
- import { slashGPTAgent, slashGPTFuncitons2TextAgent } from "./agents/slashgpt_agent";
4
+ import { graphDataTestRunner } from "~/utils/runner";
5
5
 
6
6
  const graph_data = {
7
7
  nodes: {
@@ -9,7 +9,7 @@ const graph_data = {
9
9
  agentId: "slashGPTAgent",
10
10
  params: {
11
11
  function_result: true,
12
- prompt: "世界で協力してco2を減らす方法を教えて下さい",
12
+ query: "世界で協力してco2を減らす方法を教えて下さい",
13
13
  manifest: {
14
14
  prompt: "あなたは世界経済の専門家です。ユーザの問い合わせについて考え、10この結果をfunctionsの結果に返してください。",
15
15
  skip_function_result: true,
@@ -72,14 +72,9 @@ const graph_data = {
72
72
  },
73
73
  },
74
74
  };
75
- const runAgent = async () => {
76
- const graph = new GraphAI(graph_data, { slashGPTAgent, slashGPTFuncitons2TextAgent });
77
- const result = await graph.run();
78
- console.log(result);
79
- };
80
75
 
81
76
  const main = async () => {
82
- await runAgent();
77
+ const result = await graphDataTestRunner("sample_co2.yaml", graph_data, { slashGPTAgent, slashGPTFuncitons2TextAgent });
83
78
  console.log("COMPLETE 1");
84
79
  };
85
80
  main();
@@ -1,40 +1,8 @@
1
- import path from "path";
2
- import * as fs from "fs";
3
- import { GraphAI, AgentFunction } from "@/graphai";
4
- import { ChatSession, ChatConfig, ManifestData } from "slashgpt";
5
- import { readGraphaiData } from "~/utils/file_utils";
1
+ import { fileTestRunner } from "./runner";
6
2
 
7
- const config = new ChatConfig(path.resolve(__dirname));
8
-
9
- const slashGPTAgent: AgentFunction<{ manifest: ManifestData; prompt: string }, { content: string }> = async (context) => {
10
- console.log("executing", context.nodeId, context.params);
11
- const session = new ChatSession(config, context.params.manifest ?? {});
12
- const prompt = context.inputs.reduce((prompt, input, index) => {
13
- return prompt.replace("${" + index + "}", input["content"]);
14
- }, context.params.prompt);
15
- session.append_user_question(prompt);
16
-
17
- await session.call_loop(() => {});
18
- const message = session.history.last_message();
19
- if (message === undefined) {
20
- throw new Error("No message in the history");
21
- }
22
- return message;
23
- };
24
-
25
- const runAgent = async (file: string) => {
26
- const file_path = path.resolve(__dirname) + file;
27
- const graph_data = readGraphaiData(file_path);
28
- const graph = new GraphAI(graph_data, slashGPTAgent);
29
- const results = (await graph.run()) as Record<string, any>;
30
-
31
- const log_path = path.resolve(__dirname) + "/../tests/logs/" + path.basename(file_path).replace(/\.yml$/, ".log");
32
- console.log(log_path);
33
- fs.writeFileSync(log_path, JSON.stringify(graph.transactionLogs(), null, 2));
34
- console.log(results["node3"]["content"]);
35
- };
3
+ import { stringTemplateAgent, slashGPTAgent } from "@/experimental_agents";
36
4
 
37
5
  const main = async () => {
38
- await runAgent("/graphs/slash_gpt.yml");
6
+ await fileTestRunner("/graphs/slash_gpt.yml", { slashgpt: slashGPTAgent, stringTemplate: stringTemplateAgent });
39
7
  };
40
8
  main();
@@ -1,22 +1,10 @@
1
- import path from "path";
2
- import search from "arXiv-api-ts";
1
+ import { fileTestRunner } from "./runner";
3
2
 
4
- import { GraphAI, AgentFunction } from "@/graphai";
5
- import { readGraphaiData } from "~/utils/file_utils";
6
-
7
- import { slashGPTAgent } from "./agents/slashgpt_agent";
3
+ import { slashGPTAgent } from "@/experimental_agents";
8
4
  import { arxivAgent, arxiv2TextAgent } from "./agents/arxiv_agent";
9
5
 
10
- const runAgent = async (file: string) => {
11
- const file_path = path.resolve(__dirname) + file;
12
- const graph_data = readGraphaiData(file_path);
13
- const graph = new GraphAI(graph_data, { arxivAgent: arxivAgent, arxiv2TextAgent, slashGPTAgent });
14
- const result = await graph.run();
15
- console.log(result);
16
- };
17
-
18
6
  const main = async () => {
19
- await runAgent("/graphs/arxiv.yml");
7
+ await fileTestRunner("/graphs/arxiv.yml", { arxivAgent: arxivAgent, arxiv2TextAgent, slashGPTAgent });
20
8
  console.log("COMPLETE 1");
21
9
  };
22
10
  main();
@@ -0,0 +1,2 @@
1
+ export * from "./string_agent";
2
+ export * from "./slashgpt_agent";
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
package/src/graphai.ts CHANGED
@@ -341,7 +341,7 @@ export class GraphAI {
341
341
  }, {});
342
342
  }
343
343
 
344
- public async run() {
344
+ public async run(): Promise<ResultDataDictonary> {
345
345
  if (this.isRunning) {
346
346
  console.error("-- Already Running");
347
347
  }
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { GraphAI, AgentFunction } from "./graphai";
4
+ import { slashGPTAgent, stringTemplateAgent } from "./experimental_agents";
5
+
4
6
  import fs from "fs";
5
7
  import path from "path";
6
8
  import YAML from "yaml";
@@ -24,7 +26,7 @@ const main = async () => {
24
26
  const graph_data_file = fs.readFileSync(file_path, "utf8");
25
27
  const graph_data = YAML.parse(graph_data_file);
26
28
 
27
- const graph = new GraphAI(graph_data, { test: testAgent });
29
+ const graph = new GraphAI(graph_data, { testAgent, slashGPTAgent, stringTemplateAgent });
28
30
  const results = await graph.run();
29
31
  console.log(results);
30
32
  } catch (e) {
@@ -0,0 +1,28 @@
1
+ import { stringTemplateAgent } from "@/experimental_agents";
2
+
3
+ import test from "node:test";
4
+ import assert from "node:assert";
5
+
6
+ test("test stringTemplateAgent simple", async () => {
7
+ const result = await stringTemplateAgent({
8
+ nodeId: "test",
9
+ retry: 0,
10
+ params: { template: "${0}: ${1}" },
11
+ inputs: [{ content: "hello" }, { content: "test" }] as any,
12
+ });
13
+ assert.deepStrictEqual(result, {
14
+ content: "hello: test",
15
+ });
16
+ });
17
+
18
+ test("test stringTemplateAgent simple", async () => {
19
+ const result = await stringTemplateAgent({
20
+ nodeId: "test",
21
+ retry: 0,
22
+ params: { template: "${0}: ${1}", inputKey: "key" },
23
+ inputs: [{ key: "hello" }, { key: "test" }],
24
+ });
25
+ assert.deepStrictEqual(result, {
26
+ content: "hello: test",
27
+ });
28
+ });