From 72afbb834c50e15dadbd083054baf1db1701cdb7 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 6 Jun 2023 23:29:42 -0300 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=90=9B=20fix(=5F=5Fmain=5F=5F.py):=20?= =?UTF-8?q?fix=20typo=20in=20sendAll=20function=20URL=20=E2=9C=A8=20feat(?= =?UTF-8?q?=5F=5Fmain=5F=5F.py):=20add=20banner=20with=20title=20and=20inf?= =?UTF-8?q?o=20text=20to=20be=20displayed=20on=20server=20start=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(App.tsx):=20fix=20API=20endpoint=20URL=20The?= =?UTF-8?q?=20sendAll=20function=20URL=20had=20an=20extra=20forward=20slas?= =?UTF-8?q?h.=20The=20API=20endpoint=20URL=20in=20App.tsx=20was=20incorrec?= =?UTF-8?q?t=20and=20has=20been=20fixed.=20A=20banner=20with=20a=20title?= =?UTF-8?q?=20and=20info=20text=20has=20been=20added=20to=20be=20displayed?= =?UTF-8?q?=20on=20server=20start=20to=20provide=20users=20with=20more=20i?= =?UTF-8?q?nformation=20about=20the=20application.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 83 +++++++++++++++++++---- src/frontend/src/App.tsx | 2 +- src/frontend/src/controllers/API/index.ts | 4 +- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index af57ed381..8b3e9f773 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -1,20 +1,28 @@ -import multiprocessing +import sys +import time +import httpx +from multiprocess import Process, cpu_count import platform from pathlib import Path +from rich.panel import Panel +from rich import box +from rich import print as rprint import typer from fastapi.staticfiles import StaticFiles from langflow.main import create_app from langflow.settings import settings -from langflow.utils.logger import configure +from langflow.utils.logger import configure, logger +import webbrowser + app = typer.Typer() def get_number_of_workers(workers=None): if workers == -1: - workers = (multiprocessing.cpu_count() * 2) + 1 + workers = (cpu_count() * 2) + 1 return workers @@ -77,7 +85,7 @@ def serve( timeout: int = typer.Option(60, help="Worker timeout in seconds."), port: int = typer.Option(7860, help="Port to listen on."), config: str = typer.Option("config.yaml", help="Path to the configuration file."), - log_level: str = typer.Option("info", help="Logging level."), + log_level: str = typer.Option("critical", help="Logging level."), log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file."), jcloud: bool = typer.Option(False, help="Deploy on Jina AI Cloud"), dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"), @@ -107,17 +115,66 @@ def serve( "timeout": timeout, } - if platform.system() in ["Darwin", "Windows"]: - # Run using uvicorn on MacOS and Windows - # Windows doesn't support gunicorn - # MacOS requires an env variable to be set to use gunicorn - import uvicorn + webapp_process = Process( + target=run_langflow, args=(host, port, log_level, options, app) + ) + webapp_process.start() + status_code = 0 + while status_code != 200: + try: + status_code = httpx.get(f"http://{host}:{port}").status_code + except Exception: + time.sleep(1) - uvicorn.run(app, host=host, port=port, log_level=log_level) - else: - from langflow.server import LangflowApplication + print_banner(host, port) + webbrowser.open(f"http://{host}:{port}") - LangflowApplication(app, options).run() + +def print_banner(host, port): + # console = Console() + + # Title with emojis and gradient text + title = ( + "[bold yellow]:chains: Welcome to Langflow :chains:[/bold yellow]\n\n" + f"Access [link=http://{host}:{port}]http://{host}:{port}[/link]" + ) + + # Info with gradient text + info_text = ( + "Access, collaborate, contribute, and explore at our " + "[bold magenta][link=https://github.com/logspace-ai/langflow]GitHub Repo[/link][/bold magenta] :rocket:" + ) + + # Create a panel with the title and the info text, and a border around it + panel = Panel( + f"{title}\n{info_text}", box=box.ROUNDED, border_style="blue", expand=False + ) + + # Print the banner with a separator line before and after + rprint(panel) + + +def run_langflow(host, port, log_level, options, app): + """ + Run Langflow server on localhost + """ + try: + if platform.system() in ["Darwin", "Windows"]: + # Run using uvicorn on MacOS and Windows + # Windows doesn't support gunicorn + # MacOS requires an env variable to be set to use gunicorn + import uvicorn + + uvicorn.run(app, host=host, port=port, log_level=log_level) + else: + from langflow.server import LangflowApplication + + LangflowApplication(app, options).run() + except KeyboardInterrupt: + pass + except Exception as e: + logger.error(e) + sys.exit(1) def main(): diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index e00019822..f8c11c508 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -49,7 +49,7 @@ export default function App() { // Initialize state variable for the version const [version, setVersion] = useState(""); useEffect(() => { - fetch("/version") + fetch("api/v1/version") .then((res) => res.json()) .then((data) => { setVersion(data.version); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 0cffd04bf..dbac43dbd 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -4,11 +4,11 @@ import axios, { AxiosResponse } from "axios"; import { FlowType } from "../../types/flow"; export async function getAll(): Promise> { - return await axios.get(`/all`); + return await axios.get(`api/v1/all`); } export async function sendAll(data: sendAllProps) { - return await axios.post(`/predict`, data); + return await axios.post(`api/v1//predict`, data); } export async function checkCode( From 7b40e8bafa9f2f07ed12a4a9b0182e10efb79a19 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 6 Jun 2023 23:30:21 -0300 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=A6=20chore(pyproject.toml):=20add?= =?UTF-8?q?=20multiprocess=20dependency=20to=20dev=20dependencies=20The=20?= =?UTF-8?q?multiprocess=20library=20is=20added=20to=20the=20dev=20dependen?= =?UTF-8?q?cies=20to=20support=20parallel=20processing=20in=20the=20develo?= =?UTF-8?q?pment=20environment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- poetry.lock | 29 ++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 58498c4d1..595cb8d9d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2953,6 +2953,33 @@ files = [ {file = "multidict-6.0.4.tar.gz", hash = "sha256:3666906492efb76453c0e7b97f2cf459b0682e7402c0489a95484965dbc1da49"}, ] +[[package]] +name = "multiprocess" +version = "0.70.14" +description = "better multiprocessing and multithreading in python" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "multiprocess-0.70.14-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:560a27540daef4ce8b24ed3cc2496a3c670df66c96d02461a4da67473685adf3"}, + {file = "multiprocess-0.70.14-pp37-pypy37_pp73-manylinux_2_24_i686.whl", hash = "sha256:bfbbfa36f400b81d1978c940616bc77776424e5e34cb0c94974b178d727cfcd5"}, + {file = "multiprocess-0.70.14-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl", hash = "sha256:89fed99553a04ec4f9067031f83a886d7fdec5952005551a896a4b6a59575bb9"}, + {file = "multiprocess-0.70.14-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:40a5e3685462079e5fdee7c6789e3ef270595e1755199f0d50685e72523e1d2a"}, + {file = "multiprocess-0.70.14-pp38-pypy38_pp73-manylinux_2_24_i686.whl", hash = "sha256:44936b2978d3f2648727b3eaeab6d7fa0bedf072dc5207bf35a96d5ee7c004cf"}, + {file = "multiprocess-0.70.14-pp38-pypy38_pp73-manylinux_2_24_x86_64.whl", hash = "sha256:e628503187b5d494bf29ffc52d3e1e57bb770ce7ce05d67c4bbdb3a0c7d3b05f"}, + {file = "multiprocess-0.70.14-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:0d5da0fc84aacb0e4bd69c41b31edbf71b39fe2fb32a54eaedcaea241050855c"}, + {file = "multiprocess-0.70.14-pp39-pypy39_pp73-manylinux_2_24_i686.whl", hash = "sha256:6a7b03a5b98e911a7785b9116805bd782815c5e2bd6c91c6a320f26fd3e7b7ad"}, + {file = "multiprocess-0.70.14-pp39-pypy39_pp73-manylinux_2_24_x86_64.whl", hash = "sha256:cea5bdedd10aace3c660fedeac8b087136b4366d4ee49a30f1ebf7409bce00ae"}, + {file = "multiprocess-0.70.14-py310-none-any.whl", hash = "sha256:7dc1f2f6a1d34894c8a9a013fbc807971e336e7cc3f3ff233e61b9dc679b3b5c"}, + {file = "multiprocess-0.70.14-py37-none-any.whl", hash = "sha256:93a8208ca0926d05cdbb5b9250a604c401bed677579e96c14da3090beb798193"}, + {file = "multiprocess-0.70.14-py38-none-any.whl", hash = "sha256:6725bc79666bbd29a73ca148a0fb5f4ea22eed4a8f22fce58296492a02d18a7b"}, + {file = "multiprocess-0.70.14-py39-none-any.whl", hash = "sha256:63cee628b74a2c0631ef15da5534c8aedbc10c38910b9c8b18dcd327528d1ec7"}, + {file = "multiprocess-0.70.14.tar.gz", hash = "sha256:3eddafc12f2260d27ae03fe6069b12570ab4764ab59a75e81624fac453fbf46a"}, +] + +[package.dependencies] +dill = ">=0.3.6" + [[package]] name = "mypy" version = "1.3.0" @@ -6234,4 +6261,4 @@ deploy = ["langchain-serve"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "4cac7dea0c1222711ba7eed82d5716d5e361d454edb6e0299b387fbb115d2c3d" +content-hash = "9b426f403d0e2f6507e1fe410d51e83beeb678c5e2393181681f78920e1ec450" diff --git a/pyproject.toml b/pyproject.toml index 87843198b..177575202 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ ctransformers = "^0.2.2" cohere = "^4.6.0" faiss-cpu = "^1.7.4" anthropic = "^0.2.9" +multiprocess = "^0.70.14" [tool.poetry.group.dev.dependencies] From e7e510a21899ea2e778b39f5995f3ab9a41f05db Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 6 Jun 2023 23:31:06 -0300 Subject: [PATCH 3/8] fix: this commit tries to fix issue of blank UI --- src/frontend/src/contexts/tabsContext.tsx | 69 ++++++++++++----------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index acc7011bc..a8dbfe2e5 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -89,39 +89,44 @@ export function TabsProvider({ children }: { children: ReactNode }) { let cookie = window.localStorage.getItem("tabsData"); if (cookie && Object.keys(templates).length > 0) { let cookieObject: LangFlowState = JSON.parse(cookie); - cookieObject.flows.forEach((flow) => { - flow.data.edges.forEach((edge) => { - edge.className = ""; - edge.style = { stroke: "#555555" }; + try { + cookieObject.flows.forEach((flow) => { + flow.data.edges.forEach((edge) => { + edge.className = ""; + edge.style = { stroke: "#555555" }; + }); + + flow.data.nodes.forEach((node) => { + const template = templates[node.data.type]; + if (!template) { + setErrorData({ title: `Unknown node type: ${node.data.type}` }); + return; + } + if (Object.keys(template["template"]).length > 0) { + node.data.node.base_classes = template["base_classes"]; + flow.data.edges.forEach((edge) => { + if (edge.source === node.id) { + edge.sourceHandle = edge.sourceHandle + .split("|") + .slice(0, 2) + .concat(template["base_classes"]) + .join("|"); + } + }); + node.data.node.description = template["description"]; + node.data.node.template = updateTemplate( + template["template"] as unknown as APITemplateType, + node.data.node.template as APITemplateType + ); + } + }); }); - flow.data.nodes.forEach((node) => { - const template = templates[node.data.type]; - if (!template) { - setErrorData({ title: `Unknown node type: ${node.data.type}` }); - return; - } - if (Object.keys(template["template"]).length > 0) { - node.data.node.base_classes = template["base_classes"]; - flow.data.edges.forEach((edge) => { - if (edge.source === node.id) { - edge.sourceHandle = edge.sourceHandle - .split("|") - .slice(0, 2) - .concat(template["base_classes"]) - .join("|"); - } - }); - node.data.node.description = template["description"]; - node.data.node.template = updateTemplate( - template["template"] as unknown as APITemplateType, - node.data.node.template as APITemplateType - ); - } - }); - }); - setTabIndex(cookieObject.tabIndex); - setFlows(cookieObject.flows); - setId(cookieObject.id); + setTabIndex(cookieObject.tabIndex); + setFlows(cookieObject.flows); + setId(cookieObject.id); + } catch (e) { + console.log(e); + } } }, [templates]); From 4ee9b044bde5da9cbcfb78e8716089425f9ac72c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 6 Jun 2023 23:32:05 -0300 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=9A=80=20feat(Makefile):=20add=20buil?= =?UTF-8?q?d=5Fand=5Frun=20target=20to=20build=20and=20run=20the=20applica?= =?UTF-8?q?tion=20The=20new=20build=5Fand=5Frun=20target=20removes=20the?= =?UTF-8?q?=20dist=20folder,=20builds=20the=20application,=20installs=20it?= =?UTF-8?q?,=20and=20runs=20it.=20This=20target=20is=20useful=20for=20quic?= =?UTF-8?q?kly=20building=20and=20running=20the=20application=20in=20a=20d?= =?UTF-8?q?evelopment=20environment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index baf4220ff..3a00218fc 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,12 @@ backend: make install_backend poetry run uvicorn langflow.main:app --port 7860 --reload --log-level debug +build_and_run: + echo 'Removing dist folder' + rm -rf dist + make build && poetry run pip install dist/*.tar.gz && poetry run langflow + + build_frontend: cd src/frontend && CI='' npm run build cp -r src/frontend/build src/backend/langflow/frontend From 0cfc0b016e4081e3bdc304d589c0c74d6606324b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 12:25:00 -0300 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=9A=80=20feat(=5F=5Fmain=5F=5F.py):?= =?UTF-8?q?=20add=20optional=20path=20argument=20to=20serve=20function=20t?= =?UTF-8?q?o=20specify=20path=20to=20frontend=20directory=20=F0=9F=9A=80?= =?UTF-8?q?=20feat(=5F=5Fmain=5F=5F.py):=20add=20optional=20open=5Fbrowser?= =?UTF-8?q?=20argument=20to=20serve=20function=20to=20specify=20whether=20?= =?UTF-8?q?to=20open=20browser=20after=20starting=20server=20The=20serve?= =?UTF-8?q?=20function=20now=20accepts=20an=20optional=20path=20argument?= =?UTF-8?q?=20to=20specify=20the=20path=20to=20the=20frontend=20directory?= =?UTF-8?q?=20containing=20build=20files.=20This=20is=20useful=20for=20dev?= =?UTF-8?q?elopment=20purposes=20only.=20The=20function=20also=20accepts?= =?UTF-8?q?=20an=20optional=20open=5Fbrowser=20argument=20to=20specify=20w?= =?UTF-8?q?hether=20to=20open=20the=20browser=20after=20starting=20the=20s?= =?UTF-8?q?erver.=20This=20is=20useful=20when=20running=20the=20server=20l?= =?UTF-8?q?ocally.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 8b3e9f773..8c9281862 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -89,6 +89,13 @@ def serve( log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file."), jcloud: bool = typer.Option(False, help="Deploy on Jina AI Cloud"), dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"), + path: str = typer.Option( + None, + help="Path to the frontend directory containing build files. This is for development purposes only.", + ), + open_browser: bool = typer.Option( + True, help="Open the browser after starting the server." + ), ): """ Run the Langflow server. @@ -101,8 +108,11 @@ def serve( update_settings(config, dev=dev) app = create_app() # get the directory of the current file - path = Path(__file__).parent - static_files_dir = path / "frontend" + if not path: + path = Path(__file__).parent + static_files_dir = path / "frontend" + else: + static_files_dir = Path(path) app.mount( "/", StaticFiles(directory=static_files_dir, html=True), @@ -127,22 +137,30 @@ def serve( time.sleep(1) print_banner(host, port) - webbrowser.open(f"http://{host}:{port}") + if open_browser: + webbrowser.open(f"http://{host}:{port}") def print_banner(host, port): # console = Console() + word = "LangFlow" + colors = ["#690080", "#660099", "#4d00b3", "#3300cc", "#1a00e6", "#0000ff"] + + styled_word = "" + + for i, char in enumerate(word): + color = colors[i % len(colors)] + styled_word += f"[{color}]{char}[/]" + # Title with emojis and gradient text title = ( - "[bold yellow]:chains: Welcome to Langflow :chains:[/bold yellow]\n\n" + f"[bold]Welcome to :chains: {styled_word} [/bold]\n\n" f"Access [link=http://{host}:{port}]http://{host}:{port}[/link]" ) - - # Info with gradient text info_text = ( - "Access, collaborate, contribute, and explore at our " - "[bold magenta][link=https://github.com/logspace-ai/langflow]GitHub Repo[/link][/bold magenta] :rocket:" + "Collaborate, and contribute at our " + "[bold][link=https://github.com/logspace-ai/langflow]GitHub Repo[/link][/bold] :rocket:" ) # Create a panel with the title and the info text, and a border around it From 2482a230bb2cb643907e6f3ae088aaa2578959fc Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 12:29:29 -0300 Subject: [PATCH 6/8] update lock --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 5882c07fc..6f77c6b19 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6323,4 +6323,4 @@ deploy = ["langchain-serve"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "94e4a4ca5ec150ef6f673d4a3ab4964a876ce795ae398b78c76719695c63758e" +content-hash = "3cefd738bb8466d22b1403d9b40c92420ec7f248705a2604b21d96e58d5db990" From 58fa3b8dc021da5054073fe68d208ad18f9ebc6f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 17:17:27 -0300 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=90=9B=20fix(=5F=5Fmain=5F=5F.py):=20?= =?UTF-8?q?ignore=20type=20error=20for=20multiprocess=20import=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(=5F=5Fmain=5F=5F.py):=20rename=20path=20vari?= =?UTF-8?q?able=20to=20frontend=5Fpath=20for=20clarity=20The=20first=20cha?= =?UTF-8?q?nge=20fixes=20a=20type=20error=20for=20the=20multiprocess=20imp?= =?UTF-8?q?ort.=20The=20second=20change=20renames=20the=20path=20variable?= =?UTF-8?q?=20to=20frontend=5Fpath=20to=20improve=20clarity=20and=20readab?= =?UTF-8?q?ility=20of=20the=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 8c9281862..4a00802c9 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -1,7 +1,7 @@ import sys import time import httpx -from multiprocess import Process, cpu_count +from multiprocess import Process, cpu_count # type: ignore import platform from pathlib import Path @@ -109,8 +109,8 @@ def serve( app = create_app() # get the directory of the current file if not path: - path = Path(__file__).parent - static_files_dir = path / "frontend" + frontend_path = Path(__file__).parent + static_files_dir = frontend_path / "frontend" else: static_files_dir = Path(path) app.mount( From 7ed19c739bc03cb618cdb90eb3934003ceff908d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 17:51:06 -0300 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=90=9B=20fix(tabsContext.tsx):=20add?= =?UTF-8?q?=20try-catch=20block=20to=20handle=20JSON=20parsing=20errors=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(API/index.ts):=20remove=20duplicate=20forwar?= =?UTF-8?q?d=20slash=20in=20API=20routes=20The=20try-catch=20block=20was?= =?UTF-8?q?=20added=20to=20handle=20JSON=20parsing=20errors=20that=20may?= =?UTF-8?q?=20occur=20when=20parsing=20the=20cookieObject.=20This=20ensure?= =?UTF-8?q?s=20that=20the=20application=20does=20not=20crash=20when=20such?= =?UTF-8?q?=20errors=20occur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The duplicate forward slash in the API routes was removed to ensure that the routes are correctly formed and the API requests are sent to the correct endpoints. --- src/frontend/src/contexts/tabsContext.tsx | 9 ++++++--- src/frontend/src/controllers/API/index.ts | 12 +++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index fe53e277e..1907a5590 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -89,10 +89,11 @@ export function TabsProvider({ children }: { children: ReactNode }) { let cookie = window.localStorage.getItem("tabsData"); if (cookie && Object.keys(templates).length > 0) { let cookieObject: LangFlowState = JSON.parse(cookie); + try { cookieObject.flows.forEach((flow) => { - if (!flow.data) { - return; - } + if (!flow.data) { + return; + } flow.data.edges.forEach((edge) => { edge.className = ""; edge.style = { stroke: "#555555" }; @@ -126,6 +127,8 @@ export function TabsProvider({ children }: { children: ReactNode }) { setTabIndex(cookieObject.tabIndex); setFlows(cookieObject.flows); setId(cookieObject.id); + } catch (e) { + console.log(e); } } }, [templates]); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index dbac43dbd..ffa9eef72 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -4,23 +4,23 @@ import axios, { AxiosResponse } from "axios"; import { FlowType } from "../../types/flow"; export async function getAll(): Promise> { - return await axios.get(`api/v1/all`); + return await axios.get(`/all`); } export async function sendAll(data: sendAllProps) { - return await axios.post(`api/v1//predict`, data); + return await axios.post(`/predict`, data); } export async function checkCode( code: string ): Promise> { - return await axios.post("api/v1/validate/code", { code }); + return await axios.post("/validate/code", { code }); } export async function checkPrompt( template: string ): Promise> { - return await axios.post("api/v1/validate/prompt", { template }); + return await axios.post("/validate/prompt", { template }); } export async function getExamples(): Promise { @@ -37,7 +37,5 @@ export async function getExamples(): Promise { return contentResponse.data; }); - const contents = await Promise.all(contentsPromises); - - return contents; + return await Promise.all(contentsPromises); }