-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created AIOS runtime template (#164)
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ Pympler==1.0.1 | |
click==8.1.7 | ||
ollama | ||
pyopenagi | ||
fastapi |
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 |
---|---|---|
@@ -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() |
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 |
---|---|---|
@@ -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 | ||
|