mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
Serving frontend from the forge agent server (#5252)
This commit is contained in:
@@ -45,7 +45,7 @@ if __name__ == "__main__":
|
|||||||
print(logo)
|
print(logo)
|
||||||
database_name = os.getenv("DATABASE_STRING")
|
database_name = os.getenv("DATABASE_STRING")
|
||||||
workspace = LocalWorkspace(os.getenv("AGENT_WORKSPACE"))
|
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)
|
database = forge.sdk.db.AgentDB(database_name, debug_enabled=True)
|
||||||
agent = forge.agent.ForgeAgent(database=database, workspace=workspace)
|
agent = forge.agent.ForgeAgent(database=database, workspace=workspace)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import os
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fastapi import APIRouter, FastAPI, UploadFile
|
from fastapi import APIRouter, FastAPI, UploadFile
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from hypercorn.asyncio import serve
|
from hypercorn.asyncio import serve
|
||||||
@@ -51,8 +53,14 @@ class Agent:
|
|||||||
allow_headers=["*"],
|
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.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}"]
|
||||||
|
|
||||||
|
|||||||
4
cli.py
4
cli.py
@@ -264,9 +264,13 @@ 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)
|
||||||
|
|
||||||
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):
|
||||||
|
|||||||
3
frontend/build.sh
Executable file
3
frontend/build.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
flutter build web --base-href /app/
|
||||||
@@ -36,7 +36,7 @@ void main() async {
|
|||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
Provider(
|
Provider(
|
||||||
create: (context) => RestApiUtility("http://127.0.0.1:8000"),
|
create: (context) => RestApiUtility("http://127.0.0.1:8000/api/v1"),
|
||||||
),
|
),
|
||||||
ProxyProvider<RestApiUtility, ChatService>(
|
ProxyProvider<RestApiUtility, ChatService>(
|
||||||
update: (context, restApiUtility, chatService) =>
|
update: (context, restApiUtility, chatService) =>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class ApiBaseUrlField extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
controller.text = 'http://127.0.0.1:8000';
|
controller.text = 'http://127.0.0.1:8000/api/v1';
|
||||||
apiSettingsViewModel.updateBaseURL(controller.text);
|
apiSettingsViewModel.updateBaseURL(controller.text);
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
|
|||||||
Reference in New Issue
Block a user