Skip to content

Commit

Permalink
is result
Browse files Browse the repository at this point in the history
  • Loading branch information
isamu committed Jun 20, 2024
1 parent cc9763c commit 3721bbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/utils/toGraphAi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { serializedLGraph, LGraphNode } from "litegraph.js";

const liteGraph2GraphData = (
liteGraph: serializedLGraph,
ret: {
lite2graph: {
lite2agent: Record<string, AgentFunctionInfo>;
lite2inputs: Record<string, string[]>;
lite2output: Record<string, string[]>;
lite2params: Record<string, any[]>;
},
) => {
const { lite2agent, lite2inputs, lite2output, lite2params } = ret;
const { lite2agent, lite2inputs, lite2output, lite2params } = lite2graph;
const inputTypes = liteGraph.nodes.reduce((tmp: Record<string, string[]>, node: ReturnType<LGraphNode["serialize"]>) => {
tmp[node.id] = lite2inputs[node.type ?? ""];
return tmp;
Expand All @@ -20,11 +20,15 @@ const liteGraph2GraphData = (
tmp[node.id] = lite2output[node.type ?? ""];
return tmp;
}, {});

const resultNodes = liteGraph.nodes.reduce((tmp: Set<number>, node: ReturnType<LGraphNode["serialize"]>) => {
tmp.add(node.id);
return tmp;
}, new Set<number>());
// [link index, out node, out position, in node, in position]

const linkObj = liteGraph.links.reduce((tmp: Record<string, string[] | any>, link: [number, number, number, number, number, string]) => {
const [, outNodeId, outPositionIndex, inNodeId, inPositionIndex] = link;
resultNodes.delete(outNodeId);

const pos = outTypes[outNodeId] && outTypes[outNodeId].length > 0 ? "." + outTypes[outNodeId][outPositionIndex] : "";

Expand Down Expand Up @@ -71,7 +75,6 @@ const liteGraph2GraphData = (
const nodes = liteGraph.nodes.reduce((tmp: Record<string, NodeData>, node: ReturnType<LGraphNode["serialize"]>) => {
// [link index, out node, out position, in node, in position]
const inputs = linkObj[node.id];

if ((node.type || "").startsWith("static/")) {
tmp[`node_${node.id}`] = {
value: node.widgets_values ? node.widgets_values[0] ?? "" : "",
Expand All @@ -82,6 +85,7 @@ const liteGraph2GraphData = (
agent: agent ? agent.name : node.type || "",
inputs: inputs ? inputs : undefined,
params: widgets2Params(node),
isResult: resultNodes.has(node.id),
};
}
return tmp;
Expand Down
16 changes: 8 additions & 8 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ export default defineComponent({
setup() {
const canvasRef = ref();
let ret = {};
let lite2graph = {};
const graph = new LGraph();
onMounted(() => {
const a = agentlist.agents.reduce((tmp: any, agent) => {
const agents = agentlist.agents.reduce((tmp: any, agent) => {
tmp[agent.agentId] = agent;
return tmp;
}, {});
ret = setAgentToLiteGraph(a);
lite2graph = setAgentToLiteGraph(agents);
new LGraphCanvas(canvasRef.value, graph);
Expand All @@ -52,15 +52,15 @@ export default defineComponent({
graph.add(openai_node);
openai_node.pos = [700, 200];
const string_node = LiteGraph.createNode("string/stringTemplate");
const string_node = LiteGraph.createNode("static/string");
graph.add(string_node);
string_node.pos = [200, 200];
string_node.connect(0, openai_node, 3);
string_node.connect(0, openai_node, 10);
const string_node2 = LiteGraph.createNode("string/stringTemplate");
const string_node2 = LiteGraph.createNode("static/string");
graph.add(string_node2);
string_node2.pos = [200, 300];
string_node2.connect(0, openai_node, 0);
string_node2.connect(0, openai_node, 1);
const pop_node = LiteGraph.createNode("array/pop");
graph.add(pop_node);
Expand All @@ -83,7 +83,7 @@ export default defineComponent({
const download = () => {
const data = graph.serialize();
const graphData = liteGraph2GraphData(data, ret);
const graphData = liteGraph2GraphData(data, lite2graph);

Check failure on line 86 in src/views/Home.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

Argument of type '{}' is not assignable to parameter of type '{ lite2agent: Record<string, AgentFunctionInfo>; lite2inputs: Record<string, string[]>; lite2output: Record<string, string[]>; lite2params: Record<...>; }'.
console.log(graphData);
console.log(JSON.stringify(graphData, 2, null));

Check failure on line 88 in src/views/Home.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

No overload matches this call.
};
Expand Down

0 comments on commit 3721bbb

Please sign in to comment.