Updated forge to server the frontend again

This commit is contained in:
SwiftyOS
2023-09-19 13:24:06 +02:00
parent ccd0eb800b
commit aa1a65c59c
3 changed files with 14 additions and 12 deletions

View File

@@ -72,11 +72,11 @@
Your agent can started using the `./run agent start YOUR_AGENT_NAME` 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) ![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) ![Login](docs/content/imgs/quickstart/010_login.png)

View File

@@ -1,6 +1,7 @@
import asyncio import asyncio
import os import os
from uuid import uuid4 from uuid import uuid4
import pathlib
from fastapi import APIRouter, FastAPI, UploadFile from fastapi import APIRouter, FastAPI, UploadFile
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
@@ -56,12 +57,19 @@ class Agent:
) )
app.include_router(router, prefix="/ap/v1") 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.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.loglevel = "ERROR"
config.bind = [f"0.0.0.0:{port}"] config.bind = [f"0.0.0.0:{port}"]

6
cli.py
View File

@@ -264,15 +264,9 @@ def start(agent_name):
script_dir = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(os.path.realpath(__file__))
agent_dir = os.path.join(script_dir, f"autogpts/{agent_name}") 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") run_command = os.path.join(agent_dir, "run")
if os.path.exists(agent_dir) and os.path.isfile(run_command): if os.path.exists(agent_dir) and os.path.isfile(run_command):
subprocess.Popen([frontend_build], cwd=frontend_dir)
os.chdir(agent_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) subprocess.Popen(["./run"], cwd=agent_dir)
click.echo(f"Agent '{agent_name}' started") click.echo(f"Agent '{agent_name}' started")
elif not os.path.exists(agent_dir): elif not os.path.exists(agent_dir):