From aa1a65c59c4a2d316aa2a35b6b054eb6563dc0f2 Mon Sep 17 00:00:00 2001 From: SwiftyOS Date: Tue, 19 Sep 2023 13:24:06 +0200 Subject: [PATCH] Updated forge to server the frontend again --- QUICKSTART.md | 4 ++-- autogpts/forge/forge/sdk/agent.py | 16 ++++++++++++---- cli.py | 6 ------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/QUICKSTART.md b/QUICKSTART.md index 5bc210cd..e112a20c 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -72,11 +72,11 @@ Your agent can started using the `./run agent start YOUR_AGENT_NAME` -This will build the frontend, install the dependencies and then start the agent on `http://localhost:8000/` +This start the agent on `http://localhost:8000/` ![Start the Agent](docs/content/imgs/quickstart/009_start_agent.png) -The frontend can be accessed from `http://localhost:5000/`(follow the README.md in the frontend folder to spin up the UI), you will first need to login using either a google account or your github account. +The frontend can be accessed from `http://localhost:8000/`, you will first need to login using either a google account or your github account. ![Login](docs/content/imgs/quickstart/010_login.png) diff --git a/autogpts/forge/forge/sdk/agent.py b/autogpts/forge/forge/sdk/agent.py index 739fd495..a0b4d33f 100644 --- a/autogpts/forge/forge/sdk/agent.py +++ b/autogpts/forge/forge/sdk/agent.py @@ -1,6 +1,7 @@ import asyncio import os from uuid import uuid4 +import pathlib from fastapi import APIRouter, FastAPI, UploadFile from fastapi.responses import RedirectResponse @@ -56,12 +57,19 @@ class Agent: ) app.include_router(router, prefix="/ap/v1") - # app.mount("/app", StaticFiles(directory="../../frontend/build/web"), name="app") + script_dir = os.path.dirname(os.path.realpath(__file__)) + frontend_path = pathlib.Path(os.path.join(script_dir, "../../../../frontend/build/web")).resolve() + + if os.path.exists(frontend_path): + app.mount("/app", StaticFiles(directory=frontend_path), name="app") + @app.get("/", include_in_schema=False) + async def root(): + return RedirectResponse(url='/app/index.html', status_code=307) + else: + LOG.warning(f"Frontend not found. {frontend_path} does not exist. The frontend will not be served") app.add_middleware(AgentMiddleware, agent=self) - @app.get("/", include_in_schema=False) - async def root(): - return RedirectResponse(url='/app/index.html', status_code=307) + config.loglevel = "ERROR" config.bind = [f"0.0.0.0:{port}"] diff --git a/cli.py b/cli.py index 508ac6ec..845a7b5c 100644 --- a/cli.py +++ b/cli.py @@ -264,15 +264,9 @@ def start(agent_name): script_dir = os.path.dirname(os.path.realpath(__file__)) agent_dir = os.path.join(script_dir, f"autogpts/{agent_name}") - frontend_dir = os.path.join(script_dir, "frontend") - frontend_build = os.path.join(frontend_dir, "build.sh") run_command = os.path.join(agent_dir, "run") if os.path.exists(agent_dir) and os.path.isfile(run_command): - subprocess.Popen([frontend_build], cwd=frontend_dir) os.chdir(agent_dir) - if os.name == 'nt': - click.echo(click.style("😞 The script cannot be run on Windows.", fg="red")) - return subprocess.Popen(["./run"], cwd=agent_dir) click.echo(f"Agent '{agent_name}' started") elif not os.path.exists(agent_dir):