-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from isamu/filterParams
Filter params
- Loading branch information
Showing
4 changed files
with
244 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"]; | ||
|
||
export const computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority", "if"]; | ||
export const computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority", "if", "filterParams"]; | ||
export const staticNodeAttributeKeys = ["value", "update", "isResult"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import { GraphAI } from "@/graphai"; | ||
import { AgentFilterFunction } from "@/type"; | ||
|
||
import { defaultTestAgents } from "@/utils/test_agents"; | ||
|
||
import test from "node:test"; | ||
import assert from "node:assert"; | ||
|
||
const httpAgentFilter: AgentFilterFunction = async (context, next) => { | ||
return next(context); | ||
}; | ||
|
||
const callbackDictonary = {}; | ||
|
||
test("test filterParams on agent filter", async () => { | ||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
echo: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
}, | ||
bypassAgent: { | ||
agent: "bypassAgent", | ||
inputs: [":echo"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
const agentFilters = [ | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8085/agentFilters/", | ||
stream: true, | ||
}, | ||
}, | ||
agentIds: ["echoAgent"], | ||
}, | ||
]; | ||
|
||
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters }); | ||
|
||
const result = await graph.run(); | ||
// console.log(JSON.stringify(result)); | ||
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8085/agentFilters/", stream: true } }] }); | ||
}); | ||
|
||
test("test filterParams on node", async () => { | ||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
echo: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8081/nodeParameter/", | ||
}, | ||
}, | ||
}, | ||
bypassAgent: { | ||
agent: "bypassAgent", | ||
inputs: [":echo"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
const agentFilters = [ | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
agentIds: ["echoAgent"], | ||
}, | ||
]; | ||
|
||
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters }); | ||
|
||
const result = await graph.run(); | ||
// console.log(JSON.stringify(result)); | ||
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }] }); | ||
}); | ||
|
||
test("test filterParams on agent filter and node. Then node.ts use filterParams on node", async () => { | ||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
echo: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8081/nodeParameter/", | ||
}, | ||
}, | ||
}, | ||
bypassAgent: { | ||
agent: "bypassAgent", | ||
inputs: [":echo"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
const agentFilters = [ | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8085/agentFilters/", | ||
stream: true, | ||
}, | ||
}, | ||
agentIds: ["echoAgent"], | ||
}, | ||
]; | ||
|
||
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters }); | ||
|
||
const result = await graph.run(); | ||
console.log(JSON.stringify(result)); | ||
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }] }); | ||
}); | ||
|
||
test("test filterParams on each agent", async () => { | ||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
echo: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8081/nodeParameter/", | ||
}, | ||
}, | ||
}, | ||
echo2: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8081/nodeParameter2/", | ||
}, | ||
}, | ||
}, | ||
bypassAgent: { | ||
agent: "bypassAgent", | ||
inputs: [":echo", ":echo2"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
const agentFilters = [ | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
agentIds: ["echoAgent"], | ||
}, | ||
]; | ||
|
||
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters }); | ||
|
||
const result = await graph.run(); | ||
// console.log(JSON.stringify(result)); | ||
assert.deepStrictEqual(result, { | ||
bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }, { agentServer: { baseUrl: "http://localhost:8081/nodeParameter2/" } }], | ||
}); | ||
}); | ||
|
||
|
||
test("test filterParams on agent filter", async () => { | ||
const graph_data = { | ||
version: 0.3, | ||
nodes: { | ||
echo: { | ||
agent: "echoAgent", | ||
params: { | ||
filterParams: true, | ||
}, | ||
}, | ||
bypassAgent: { | ||
agent: "bypassAgent", | ||
inputs: [":echo"], | ||
isResult: true, | ||
}, | ||
}, | ||
}; | ||
const agentFilters = [ | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8085/agentFilters/", | ||
stream: true, | ||
}, | ||
}, | ||
agentIds: ["echoAgent"], | ||
}, | ||
{ | ||
name: "httpAgentFilter", | ||
agent: httpAgentFilter, | ||
filterParams: { | ||
agentServer: { | ||
baseUrl: "http://localhost:8085/agentFilters2/", | ||
stream: true, | ||
}, | ||
}, | ||
agentIds: ["echoAgent"], | ||
}, | ||
]; | ||
|
||
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters }); | ||
|
||
const result = await graph.run(); | ||
// console.log(JSON.stringify(result)); | ||
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8085/agentFilters/", stream: true } }] }); | ||
}); |