diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index c0acbe30a..853417c7f 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -6,7 +6,7 @@ from multiprocess import Process, cpu_count # type: ignore import platform from pathlib import Path from typing import Optional - +import socket from rich.panel import Panel from rich import box from rich import print as rprint @@ -168,9 +168,13 @@ def serve( ) webapp_process.start() status_code = 0 + # check if port is being used + if is_port_in_use(port, host): + port = get_free_port(port) while status_code != 200: try: - status_code = httpx.get(f"http://{host}:{port}").status_code + status_code = httpx.get(f"http://{host}:{port}/health").status_code + except Exception: time.sleep(1) @@ -179,7 +183,7 @@ def serve( webbrowser.open(f"http://{host}:{port}") -def setup_static_files(app: FastAPI, static_files_dir: str): +def setup_static_files(app: FastAPI, static_files_dir: Path): """ Setup the static files directory. @@ -194,6 +198,36 @@ def setup_static_files(app: FastAPI, static_files_dir: str): ) +def is_port_in_use(port, host="localhost"): + """ + Check if a port is in use. + + Args: + port (int): The port number to check. + host (str): The host to check the port on. Defaults to 'localhost'. + + Returns: + bool: True if the port is in use, False otherwise. + """ + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + return s.connect_ex((host, port)) == 0 + + +def get_free_port(port): + """ + Given a used port, find a free port. + + Args: + port (int): The port number to check. + + Returns: + int: A free port number. + """ + while is_port_in_use(port): + port += 1 + return port + + def print_banner(host, port): # console = Console() diff --git a/src/backend/langflow/main.py b/src/backend/langflow/main.py index f1eae916a..6018c1a48 100644 --- a/src/backend/langflow/main.py +++ b/src/backend/langflow/main.py @@ -6,9 +6,10 @@ from fastapi.middleware.cors import CORSMiddleware from langflow.api import router from langflow.database.base import create_db_and_tables +from pathlib import Path -def create_app(static_path: str = "static"): +def create_app(static_path: Path = Path("src/frontend")): """Create the FastAPI app and include the router.""" app = FastAPI() diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 105f68111..564cfed6a 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -48,7 +48,7 @@ export default function BuildTrigger({ if(!allNodesValid) { setErrorData({ title: "Oops! Looks like you missed something", - list: ["Check nodes and retry. Hover over 🔴 node for status."], + list: ["Check components and retry. Hover over component status icon 🔴 to inspect."], }); } } catch (error) { diff --git a/src/frontend/src/constants.tsx b/src/frontend/src/constants.tsx index 8dc05e7d9..32bcfe5be 100644 --- a/src/frontend/src/constants.tsx +++ b/src/frontend/src/constants.tsx @@ -66,7 +66,7 @@ export const getPythonApiCode = (flow: FlowType): string => { BASE_API_URL = "${window.location.protocol}//${ window.location.host - }/ap1/v1/predict" + }/api/v1/predict" FLOW_ID = "${flowId}" # You can tweak the flow by adding a tweaks dictionary # e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}} diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 7bec0517c..2aab4d0e3 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -124,7 +124,7 @@ export default function ExtraSidebar() { type="text" name="search" id="search" - placeholder="Search Nodes" + placeholder="Search" className={ INPUT_STYLE + "w-full border-1 dark:border-slate-600 dark:border-0.5 dark:ring-0 focus-visible:dark:ring-0 focus-visible:dark:ring-offset-1 rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50" diff --git a/src/frontend/src/pages/MainPage/index.tsx b/src/frontend/src/pages/MainPage/index.tsx index 0657000c1..bdf5156ba 100644 --- a/src/frontend/src/pages/MainPage/index.tsx +++ b/src/frontend/src/pages/MainPage/index.tsx @@ -16,7 +16,7 @@ export default function HomePage() {