-
Notifications
You must be signed in to change notification settings - Fork 43.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
940 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import uvicorn | ||
from fastapi import FastAPI | ||
from fastapi import FastAPI, APIRouter | ||
|
||
from autogpt_server.data import ExecutionQueue | ||
|
||
app = FastAPI( | ||
title="AutoGPT Agent Server", | ||
description=( | ||
"This server is used to execute agents that are created by the AutoGPT system." | ||
), | ||
summary="AutoGPT Agent Server", | ||
version="0.1", | ||
) | ||
|
||
execution_queue: ExecutionQueue = None | ||
class AgentServer: | ||
|
||
def __init__(self, queue: ExecutionQueue): | ||
self.app = FastAPI( | ||
title="AutoGPT Agent Server", | ||
description=( | ||
"This server is used to execute agents that are created by the " | ||
"AutoGPT system." | ||
), | ||
summary="AutoGPT Agent Server", | ||
version="0.1", | ||
) | ||
self.execution_queue = queue | ||
|
||
@app.post("/agents/{agent_id}/execute") | ||
def execute_agent(agent_id: str): | ||
execution_id = execution_queue.add(agent_id) | ||
return {"execution_id": execution_id, "agent_id": agent_id} | ||
# Define the API routes | ||
self.router = APIRouter() | ||
self.router.add_api_route( | ||
path="/agents/{agent_id}/execute", | ||
endpoint=self.execute_agent, | ||
methods=["POST"], | ||
) | ||
self.app.include_router(self.router) | ||
|
||
def execute_agent(self, agent_id: str): | ||
execution_id = self.execution_queue.add(agent_id) | ||
return {"execution_id": execution_id, "agent_id": agent_id} | ||
|
||
|
||
def start_server(queue: ExecutionQueue, use_uvicorn: bool = True): | ||
global execution_queue | ||
execution_queue = queue | ||
app = AgentServer(queue).app | ||
if use_uvicorn: | ||
uvicorn.run(app) | ||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.