Skip to content

Commit

Permalink
feat: created AIOS runtime template (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
BRama10 authored Jul 9, 2024
1 parent d884d23 commit 0737541
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Pympler==1.0.1
click==8.1.7
ollama
pyopenagi
fastapi
45 changes: 45 additions & 0 deletions runtime/exec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import uvicorn
import threading
import asyncio
import logging
from server import app

server = None

logging.getLogger("uvicorn.error").disabled = True
logging.getLogger("uvicorn.access").disabled = True

def start_server():
global server
config = uvicorn.Config(app, host="0.0.0.0", port=8000, log_level="critical")
server = uvicorn.Server(config)
thread = threading.Thread(target=server.run)
thread.start()
print("Server started")

def stop_server():
global server
if server:
server.should_exit = True
server.force_exit = True
try:
asyncio.run(server.shutdown())
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(server.shutdown())
loop.close()
except asyncio.CancelledError:
pass
print("Server stopped")
else:
print("Server is not running")

if __name__ == "__main__":
start_server()

# Example: Stop the server after 10 seconds
import time
time.sleep(10)

stop_server()
22 changes: 22 additions & 0 deletions runtime/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from starlette.requests import Request
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.post("/run_agent")
async def run_agent(*args, **kwargs):
pass

@app.get("/get_all_agents")
async def get_all_agents(*args, **kwargs):
pass

0 comments on commit 0737541

Please sign in to comment.