From 7aeac0648a000704361acf9082e24453d8718e1b Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 13 Feb 2023 17:22:16 -0300 Subject: [PATCH] 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);