From 3721bbb52d579974e55e88749d7d37f9109227ad Mon Sep 17 00:00:00 2001 From: isamu Date: Thu, 20 Jun 2024 19:12:50 +0900 Subject: [PATCH] is result --- src/utils/toGraphAi.ts | 12 ++++++++---- src/views/Home.vue | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/utils/toGraphAi.ts b/src/utils/toGraphAi.ts index 6eab50a..b158733 100644 --- a/src/utils/toGraphAi.ts +++ b/src/utils/toGraphAi.ts @@ -3,14 +3,14 @@ import { serializedLGraph, LGraphNode } from "litegraph.js"; const liteGraph2GraphData = ( liteGraph: serializedLGraph, - ret: { + lite2graph: { lite2agent: Record; lite2inputs: Record; lite2output: Record; lite2params: Record; }, ) => { - const { lite2agent, lite2inputs, lite2output, lite2params } = ret; + const { lite2agent, lite2inputs, lite2output, lite2params } = lite2graph; const inputTypes = liteGraph.nodes.reduce((tmp: Record, node: ReturnType) => { tmp[node.id] = lite2inputs[node.type ?? ""]; return tmp; @@ -20,11 +20,15 @@ const liteGraph2GraphData = ( tmp[node.id] = lite2output[node.type ?? ""]; return tmp; }, {}); - + const resultNodes = liteGraph.nodes.reduce((tmp: Set, node: ReturnType) => { + tmp.add(node.id); + return tmp; + }, new Set()); // [link index, out node, out position, in node, in position] const linkObj = liteGraph.links.reduce((tmp: Record, 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] : ""; @@ -71,7 +75,6 @@ const liteGraph2GraphData = ( const nodes = liteGraph.nodes.reduce((tmp: Record, node: ReturnType) => { // [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] ?? "" : "", @@ -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; diff --git a/src/views/Home.vue b/src/views/Home.vue index 0d0cae5..418f24f 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -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); @@ -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); @@ -83,7 +83,7 @@ export default defineComponent({ const download = () => { const data = graph.serialize(); - const graphData = liteGraph2GraphData(data, ret); + const graphData = liteGraph2GraphData(data, lite2graph); console.log(graphData); console.log(JSON.stringify(graphData, 2, null)); };