From 7aeac0648a000704361acf9082e24453d8718e1b Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 13 Feb 2023 17:22:16 -0300 Subject: [PATCH 1/4] added api consuming for generating sidebar based on json --- space_flow/package-lock.json | 29 +++++++++ space_flow/package.json | 1 + .../src/controllers/jsonConverter/index.ts | 61 +++++++++++++++++++ space_flow/src/entities/apiEnum.ts | 4 ++ space_flow/src/pages/FlowPage/index.tsx | 7 +++ 5 files changed, 102 insertions(+) create mode 100644 space_flow/src/controllers/jsonConverter/index.ts create mode 100644 space_flow/src/entities/apiEnum.ts diff --git a/space_flow/package-lock.json b/space_flow/package-lock.json index 6cb2a5861..855da05d1 100644 --- a/space_flow/package-lock.json +++ b/space_flow/package-lock.json @@ -17,6 +17,7 @@ "@types/node": "^16.18.12", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", + "axios": "^1.3.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.7.1", @@ -5061,6 +5062,29 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.2.tgz", + "integrity": "sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/axobject-query": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.1.1.tgz", @@ -14139,6 +14163,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", diff --git a/space_flow/package.json b/space_flow/package.json index 6c2b2e1eb..d83da829d 100644 --- a/space_flow/package.json +++ b/space_flow/package.json @@ -12,6 +12,7 @@ "@types/node": "^16.18.12", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", + "axios": "^1.3.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.7.1", diff --git a/space_flow/src/controllers/jsonConverter/index.ts b/space_flow/src/controllers/jsonConverter/index.ts new file mode 100644 index 000000000..3984c9b28 --- /dev/null +++ b/space_flow/src/controllers/jsonConverter/index.ts @@ -0,0 +1,61 @@ +import axios from "axios"; + +export async function getPrompts() { + const jsons = []; + let prompts = await axios.get("http://localhost:5003/list/prompts"); + (prompts.data as Array).forEach((value, index) => { + axios + .get("http://localhost:5003/templates/prompt", { + params: { name: value }, + }) + .then((prompt) => { + jsons.push({ name: value, type: "promptNode", ...prompt.data }); + }); + }); + return jsons; +} + +export async function getChains() { + const jsons = []; + let chains = await axios.get("http://localhost:5003/list/chains"); + (chains.data as Array).forEach((value, index) => { + axios + .get("http://localhost:5003/templates/chain", { + params: { name: value }, + }) + .then((chain) => { + jsons.push({ name: value, type: "chainNode", ...chain.data }); + }); + }); + return jsons; +} + +export async function getAgents() { + const jsons = []; + let chains = await axios.get("http://localhost:5003/list/agents"); + (chains.data as Array).forEach((value, index) => { + axios + .get("http://localhost:5003/templates/agent", { + params: { name: value }, + }) + .then((chain) => { + jsons.push({ name: value, type: "agentNode", ...chain.data }); + }); + }); + return jsons; +} + +export async function getMemories() { + const jsons = []; + let memories = await axios.get("http://localhost:5003/list/memories"); + (memories.data as Array).forEach((value, index) => { + axios + .get("http://localhost:5003/templates/memory", { + params: { name: value }, + }) + .then((memory) => { + jsons.push({ name: value, type: "memoryNode", ...memory.data }); + }); + }); + return jsons; +} diff --git a/space_flow/src/entities/apiEnum.ts b/space_flow/src/entities/apiEnum.ts new file mode 100644 index 000000000..f33f1a5f8 --- /dev/null +++ b/space_flow/src/entities/apiEnum.ts @@ -0,0 +1,4 @@ +export enum apiEnum +{ + PromptTemplate="PromptTemplate" +} \ No newline at end of file diff --git a/space_flow/src/pages/FlowPage/index.tsx b/space_flow/src/pages/FlowPage/index.tsx index 00832f384..8277a00a1 100644 --- a/space_flow/src/pages/FlowPage/index.tsx +++ b/space_flow/src/pages/FlowPage/index.tsx @@ -14,6 +14,8 @@ import AgentNode from "../../CustomNodes/AgentNode"; import ChainNode from "../../CustomNodes/ChainNode"; import ValidatorNode from "../../CustomNodes/ValidatorNode"; import MemoryNode from "../../CustomNodes/MemoryNode"; +import axios from "axios"; +import {getPrompts, getChains,getAgents,getMemories} from "../../controllers/jsonConverter"; const nodeTypes = { promptNode: PromptNode, @@ -25,6 +27,11 @@ const nodeTypes = { }; export default function FlowPage() { + getPrompts().then(result=>console.log(result)) + getChains().then(result=>console.log(result)) + getAgents().then(result=>console.log(result)) + getMemories().then(result=>console.log(result)) + // outside component to avoid render trigger const reactFlowWrapper = useRef(null); From f432fd6c3f0ff5d9453434338392257096095ea1 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 13 Feb 2023 20:54:18 -0300 Subject: [PATCH 2/4] getting tabs from the api --- .../{ValidatorNode => ToolsNode}/index.tsx | 6 +- .../src/controllers/NodesServices/index.ts | 51 ++++++++++++++++ .../src/controllers/UiGenerator/index.ts | 11 ++++ .../src/controllers/jsonConverter/index.ts | 61 ------------------- .../extraSidebarComponent/index.tsx | 10 +-- space_flow/src/pages/FlowPage/index.tsx | 15 ++--- 6 files changed, 78 insertions(+), 76 deletions(-) rename space_flow/src/CustomNodes/{ValidatorNode => ToolsNode}/index.tsx (86%) create mode 100644 space_flow/src/controllers/NodesServices/index.ts create mode 100644 space_flow/src/controllers/UiGenerator/index.ts delete mode 100644 space_flow/src/controllers/jsonConverter/index.ts diff --git a/space_flow/src/CustomNodes/ValidatorNode/index.tsx b/space_flow/src/CustomNodes/ToolsNode/index.tsx similarity index 86% rename from space_flow/src/CustomNodes/ValidatorNode/index.tsx rename to space_flow/src/CustomNodes/ToolsNode/index.tsx index 0bb1e71fe..90048e9fe 100644 --- a/space_flow/src/CustomNodes/ValidatorNode/index.tsx +++ b/space_flow/src/CustomNodes/ToolsNode/index.tsx @@ -1,7 +1,7 @@ import { Transition } from "@headlessui/react"; import { Handle, Position } from "reactflow"; -export default function ValidatorNode({ data }) { +export default function ToolsNode({ data }) { console.log(data); return ( -
validator data
+
Tools data
diff --git a/space_flow/src/controllers/NodesServices/index.ts b/space_flow/src/controllers/NodesServices/index.ts new file mode 100644 index 000000000..169c1d2ae --- /dev/null +++ b/space_flow/src/controllers/NodesServices/index.ts @@ -0,0 +1,51 @@ +import axios from "axios"; + +export async function getPrompts() { + const promises = (await axios.get("http://localhost:5003/list/prompts")).data.map(async (value, index) => { + const prompt = await axios.get("http://localhost:5003/templates/prompt", { + params: { name: value }, + }); + return { name: value, type: "promptNode", ...prompt.data }; + }); + return Promise.all(promises); +} + +export async function getChains() { + const promises = (await axios.get("http://localhost:5003/list/chains")).data.map(async (value, index) => { + const chain = await axios.get("http://localhost:5003/templates/chain", { + params: { name: value }, + }); + return { name: value, type: "chainNode", ...chain.data }; + }); + return Promise.all(promises); +} + +export async function getAgents() { + const promises = (await axios.get("http://localhost:5003/list/agents")).data.map(async (value, index) => { + const chain = await axios.get("http://localhost:5003/templates/agent", { + params: { name: value }, + }); + return { name: value, type: "agentNode", ...chain.data }; + }); + return Promise.all(promises); +} + +export async function getMemories() { + const promises = (await axios.get("http://localhost:5003/list/memories")).data.map(async (value, index) => { + const chain = await axios.get("http://localhost:5003/templates/memory", { + params: { name: value }, + }); + return { name: value, type: "memoryNode", ...chain.data }; + }); + return Promise.all(promises); +} + +export async function getTools() { + const promises = (await axios.get("http://localhost:5003/list/tools")).data.map(async (value, index) => { + const prompt = await axios.get("http://localhost:5003/templates/tool", { + params: { name: value }, + }); + return { name: value, type: "toolNode", ...prompt.data }; + }); + return Promise.all(promises); +} diff --git a/space_flow/src/controllers/UiGenerator/index.ts b/space_flow/src/controllers/UiGenerator/index.ts new file mode 100644 index 000000000..21a8bd4c1 --- /dev/null +++ b/space_flow/src/controllers/UiGenerator/index.ts @@ -0,0 +1,11 @@ +import axios from "axios"; + +export function generateUiNode(data: Object) { + const fields = []; + Object.keys(data).forEach((field) => { + if (data[field].required) { + fields.push(data[field]) + } + }); + return fields +} diff --git a/space_flow/src/controllers/jsonConverter/index.ts b/space_flow/src/controllers/jsonConverter/index.ts deleted file mode 100644 index 3984c9b28..000000000 --- a/space_flow/src/controllers/jsonConverter/index.ts +++ /dev/null @@ -1,61 +0,0 @@ -import axios from "axios"; - -export async function getPrompts() { - const jsons = []; - let prompts = await axios.get("http://localhost:5003/list/prompts"); - (prompts.data as Array).forEach((value, index) => { - axios - .get("http://localhost:5003/templates/prompt", { - params: { name: value }, - }) - .then((prompt) => { - jsons.push({ name: value, type: "promptNode", ...prompt.data }); - }); - }); - return jsons; -} - -export async function getChains() { - const jsons = []; - let chains = await axios.get("http://localhost:5003/list/chains"); - (chains.data as Array).forEach((value, index) => { - axios - .get("http://localhost:5003/templates/chain", { - params: { name: value }, - }) - .then((chain) => { - jsons.push({ name: value, type: "chainNode", ...chain.data }); - }); - }); - return jsons; -} - -export async function getAgents() { - const jsons = []; - let chains = await axios.get("http://localhost:5003/list/agents"); - (chains.data as Array).forEach((value, index) => { - axios - .get("http://localhost:5003/templates/agent", { - params: { name: value }, - }) - .then((chain) => { - jsons.push({ name: value, type: "agentNode", ...chain.data }); - }); - }); - return jsons; -} - -export async function getMemories() { - const jsons = []; - let memories = await axios.get("http://localhost:5003/list/memories"); - (memories.data as Array).forEach((value, index) => { - axios - .get("http://localhost:5003/templates/memory", { - params: { name: value }, - }) - .then((memory) => { - jsons.push({ name: value, type: "memoryNode", ...memory.data }); - }); - }); - return jsons; -} diff --git a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index ba5d5c7ef..f1b53b07f 100644 --- a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -1,4 +1,4 @@ -import { Bars2Icon, CommandLineIcon, CpuChipIcon, LightBulbIcon, LinkIcon, RocketLaunchIcon, ShieldCheckIcon, ViewColumnsIcon } from "@heroicons/react/24/outline"; +import { Bars2Icon, CommandLineIcon, CpuChipIcon, LightBulbIcon, LinkIcon, RocketLaunchIcon, WrenchScrewdriverIcon, ViewColumnsIcon } from "@heroicons/react/24/outline"; import { llm_chain } from "../../../../data_assets/llm_chain"; import { prompt } from "../../../../data_assets/prompt"; import DisclosureComponent from "../DisclosureComponent"; @@ -20,7 +20,7 @@ export function ExtraSidebar() { if (nodeType === "agentNode") { json = JSON.stringify({ content: "" }); } - if (nodeType === "validatorNode") { + if (nodeType === "toolNode") { json = JSON.stringify({ content: "" }); } if (nodeType === "memoryNode") { @@ -72,14 +72,14 @@ export function ExtraSidebar() {
onDragStart(event, "validatorNode")} + onDragStart={(event) => onDragStart(event, "toolNode")} > - Validator + tools
diff --git a/space_flow/src/pages/FlowPage/index.tsx b/space_flow/src/pages/FlowPage/index.tsx index 8277a00a1..1bcae460a 100644 --- a/space_flow/src/pages/FlowPage/index.tsx +++ b/space_flow/src/pages/FlowPage/index.tsx @@ -12,25 +12,26 @@ import { locationContext } from "../../contexts/locationContext"; import { ExtraSidebar } from "./components/extraSidebarComponent"; import AgentNode from "../../CustomNodes/AgentNode"; import ChainNode from "../../CustomNodes/ChainNode"; -import ValidatorNode from "../../CustomNodes/ValidatorNode"; +import ToolsNode from "../../CustomNodes/ToolsNode"; import MemoryNode from "../../CustomNodes/MemoryNode"; import axios from "axios"; -import {getPrompts, getChains,getAgents,getMemories} from "../../controllers/jsonConverter"; +import {getPrompts, getChains,getAgents,getMemories} from "../../controllers/NodesServices"; +import { generateUiNode } from "../../controllers/UiGenerator"; const nodeTypes = { promptNode: PromptNode, modelNode: ModelNode, chainNode: ChainNode, agentNode: AgentNode, - validatorNode: ValidatorNode, + toolNode: ToolsNode, memoryNode:MemoryNode }; export default function FlowPage() { - getPrompts().then(result=>console.log(result)) - getChains().then(result=>console.log(result)) - getAgents().then(result=>console.log(result)) - getMemories().then(result=>console.log(result)) + getPrompts().then(result=>result.forEach(prompt=>console.log(generateUiNode(prompt)))) + // getChains().then(result=>console.log(result)) + // getAgents().then(result=>console.log(result)) + // getMemories().then(result=>console.log(result)) // outside component to avoid render trigger From 9d9eab5db0a563c419136b4ce60fc8f8065206ca Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 13 Feb 2023 21:02:20 -0300 Subject: [PATCH 3/4] getting tools and model --- space_flow/src/controllers/NodesServices/index.ts | 10 ++++++++++ space_flow/src/pages/FlowPage/index.tsx | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/space_flow/src/controllers/NodesServices/index.ts b/space_flow/src/controllers/NodesServices/index.ts index 169c1d2ae..883415d74 100644 --- a/space_flow/src/controllers/NodesServices/index.ts +++ b/space_flow/src/controllers/NodesServices/index.ts @@ -49,3 +49,13 @@ export async function getTools() { }); return Promise.all(promises); } + +export async function getModels() { + const promises = (await axios.get("http://localhost:5003/list/llms")).data.map(async (value, index) => { + const prompt = await axios.get("http://localhost:5003/templates/llm", { + params: { name: value }, + }); + return { name: value, type: "modelNode", ...prompt.data }; + }); + return Promise.all(promises); +} diff --git a/space_flow/src/pages/FlowPage/index.tsx b/space_flow/src/pages/FlowPage/index.tsx index 1bcae460a..6a3938075 100644 --- a/space_flow/src/pages/FlowPage/index.tsx +++ b/space_flow/src/pages/FlowPage/index.tsx @@ -15,7 +15,7 @@ import ChainNode from "../../CustomNodes/ChainNode"; import ToolsNode from "../../CustomNodes/ToolsNode"; import MemoryNode from "../../CustomNodes/MemoryNode"; import axios from "axios"; -import {getPrompts, getChains,getAgents,getMemories} from "../../controllers/NodesServices"; +import {getPrompts, getChains,getAgents,getMemories, getModels,getTools} from "../../controllers/NodesServices"; import { generateUiNode } from "../../controllers/UiGenerator"; const nodeTypes = { @@ -28,10 +28,12 @@ const nodeTypes = { }; export default function FlowPage() { - getPrompts().then(result=>result.forEach(prompt=>console.log(generateUiNode(prompt)))) + // getPrompts().then(result=>result.forEach(prompt=>console.log(prompt))) // getChains().then(result=>console.log(result)) // getAgents().then(result=>console.log(result)) // getMemories().then(result=>console.log(result)) + // getModels().then(result=>result.forEach(model=>console.log(model))) + getTools().then(result=>result.forEach(tool=>console.log(tool))) // outside component to avoid render trigger From 391a357d16e0a57373021c51f6afa5817d3d79fb Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 14 Feb 2023 16:34:20 -0300 Subject: [PATCH 4/4] changed endpoint for new version of the api --- space_flow/src/controllers/NodesServices/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/space_flow/src/controllers/NodesServices/index.ts b/space_flow/src/controllers/NodesServices/index.ts index 883415d74..e52d2bbf4 100644 --- a/space_flow/src/controllers/NodesServices/index.ts +++ b/space_flow/src/controllers/NodesServices/index.ts @@ -2,7 +2,7 @@ import axios from "axios"; export async function getPrompts() { const promises = (await axios.get("http://localhost:5003/list/prompts")).data.map(async (value, index) => { - const prompt = await axios.get("http://localhost:5003/templates/prompt", { + const prompt = await axios.get("http://localhost:5003/signatures/prompt", { params: { name: value }, }); return { name: value, type: "promptNode", ...prompt.data }; @@ -12,7 +12,7 @@ export async function getPrompts() { export async function getChains() { const promises = (await axios.get("http://localhost:5003/list/chains")).data.map(async (value, index) => { - const chain = await axios.get("http://localhost:5003/templates/chain", { + const chain = await axios.get("http://localhost:5003/signatures/chain", { params: { name: value }, }); return { name: value, type: "chainNode", ...chain.data }; @@ -22,7 +22,7 @@ export async function getChains() { export async function getAgents() { const promises = (await axios.get("http://localhost:5003/list/agents")).data.map(async (value, index) => { - const chain = await axios.get("http://localhost:5003/templates/agent", { + const chain = await axios.get("http://localhost:5003/signatures/agent", { params: { name: value }, }); return { name: value, type: "agentNode", ...chain.data }; @@ -32,7 +32,7 @@ export async function getAgents() { export async function getMemories() { const promises = (await axios.get("http://localhost:5003/list/memories")).data.map(async (value, index) => { - const chain = await axios.get("http://localhost:5003/templates/memory", { + const chain = await axios.get("http://localhost:5003/signatures/memory", { params: { name: value }, }); return { name: value, type: "memoryNode", ...chain.data }; @@ -42,7 +42,7 @@ export async function getMemories() { export async function getTools() { const promises = (await axios.get("http://localhost:5003/list/tools")).data.map(async (value, index) => { - const prompt = await axios.get("http://localhost:5003/templates/tool", { + const prompt = await axios.get("http://localhost:5003/signatures/tool", { params: { name: value }, }); return { name: value, type: "toolNode", ...prompt.data }; @@ -52,7 +52,7 @@ export async function getTools() { export async function getModels() { const promises = (await axios.get("http://localhost:5003/list/llms")).data.map(async (value, index) => { - const prompt = await axios.get("http://localhost:5003/templates/llm", { + const prompt = await axios.get("http://localhost:5003/signatures/llm", { params: { name: value }, }); return { name: value, type: "modelNode", ...prompt.data };