Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
majdyz committed Jun 3, 2024
1 parent b7e7b1c commit 9d880ca
Show file tree
Hide file tree
Showing 5 changed files with 940 additions and 23 deletions.
42 changes: 26 additions & 16 deletions rnd/autogpt_server/autogpt_server/agent_api/server.py
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
4 changes: 3 additions & 1 deletion rnd/autogpt_server/autogpt_server/agent_executor/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def start_executor(pool_size: int, queue: ExecutionQueue) -> None:
time.sleep(1)
continue
executor.submit(
AgentExecutor.__execute, execution.execution_id, execution.data
AgentExecutor.__execute,
execution.execution_id,
execution.data,
)


Expand Down
Loading

0 comments on commit 9d880ca

Please sign in to comment.