AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Serving frontend from the forge agent server (#5252)
Swifty8b3a915b2f20
diff --git a/autogpts/forge/forge/__main__.py b/autogpts/forge/forge/__main__.pyindex f20644b7da..7751f4ac86 100644--- a/autogpts/forge/forge/__main__.py+++ b/autogpts/forge/forge/__main__.py@@ -45,7 +45,7 @@ if __name__ == "__main__":print(logo)database_name = os.getenv("DATABASE_STRING")workspace = LocalWorkspace(os.getenv("AGENT_WORKSPACE"))- port = os.getenv("PORT")+ port = os.getenv("PORT", 8000)database = forge.sdk.db.AgentDB(database_name, debug_enabled=True)agent = forge.agent.ForgeAgent(database=database, workspace=workspace)diff --git a/autogpts/forge/forge/sdk/agent.py b/autogpts/forge/forge/sdk/agent.pyindex e96cd6435e..e5554f55f4 100644--- a/autogpts/forge/forge/sdk/agent.py+++ b/autogpts/forge/forge/sdk/agent.py@@ -3,6 +3,8 @@ import osfrom uuid import uuid4from fastapi import APIRouter, FastAPI, UploadFile+from fastapi.responses import RedirectResponse+from fastapi.staticfiles import StaticFilesfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import FileResponsefrom hypercorn.asyncio import serve@@ -51,8 +53,14 @@ class Agent:allow_headers=["*"],)- app.include_router(router)+ app.include_router(router, prefix="/api/v1")+ app.mount("/app", StaticFiles(directory="../../frontend/build/web"), name="app")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.pyindex 89630fd1eb..931fc2f153 100644--- a/cli.py+++ b/cli.py@@ -264,9 +264,13 @@ 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)+subprocess.Popen(["./run"], cwd=agent_dir)click.echo(f"Agent '{agent_name}' started")elif not os.path.exists(agent_dir):diff --git a/frontend/build.sh b/frontend/build.shnew file mode 100755index 0000000000..4c603088d5--- /dev/null+++ b/frontend/build.sh@@ -0,0 +1,3 @@+#!/bin/bash++flutter build web --base-href /app/\ No newline at end of filediff --git a/frontend/lib/main.dart b/frontend/lib/main.dartindex 89c4e52707..209faed662 100644--- a/frontend/lib/main.dart+++ b/frontend/lib/main.dart@@ -36,7 +36,7 @@ void main() async {MultiProvider(providers: [Provider(- create: (context) => RestApiUtility("http://127.0.0.1:8000"),+ create: (context) => RestApiUtility("http://127.0.0.1:8000/api/v1"),),ProxyProvider<RestApiUtility, ChatService>(update: (context, restApiUtility, chatService) =>diff --git a/frontend/lib/views/task/api_base_url_field.dart b/frontend/lib/views/task/api_base_url_field.dartindex a52bbedec4..5bd080164f 100644--- a/frontend/lib/views/task/api_base_url_field.dart+++ b/frontend/lib/views/task/api_base_url_field.dart@@ -39,7 +39,7 @@ class ApiBaseUrlField extends StatelessWidget {children: [ElevatedButton(onPressed: () {- controller.text = 'http://127.0.0.1:8000';+ controller.text = 'http://127.0.0.1:8000/api/v1';apiSettingsViewModel.updateBaseURL(controller.text);},style: ElevatedButton.styleFrom(