From 9e95e9a08403a7a35e88a1a2112db0a06dfa60e9 Mon Sep 17 00:00:00 2001 From: Alex Dixon Date: Tue, 6 Aug 2024 18:30:03 -0700 Subject: [PATCH] reload server working except for db watcher --- src/ell/studio/__main__.py | 14 ++++++++++---- src/ell/studio/data_server.py | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ell/studio/__main__.py b/src/ell/studio/__main__.py index d1b53285..8d04042c 100644 --- a/src/ell/studio/__main__.py +++ b/src/ell/studio/__main__.py @@ -17,9 +17,9 @@ def main(): parser.add_argument("--dev", action="store_true", help="Run in development mode") args = parser.parse_args() - app = create_app(args.storage_dir) if not args.dev: + app = create_app() # In production mode, serve the built React app static_dir = os.path.join(os.path.dirname(__file__), "static") app.mount("/", StaticFiles(directory=static_dir, html=True), name="static") @@ -68,9 +68,15 @@ async def db_watcher(db_path, app): # Start the database watcher loop = asyncio.new_event_loop() - config = uvicorn.Config(app=app, port=args.port, loop=loop) - server = uvicorn.Server(config) - loop.create_task(server.serve()) + # config = uvicorn.Config(app=app, port=args.port, loop=loop,reload=True,#if args.dev else False, + # reload_delay=1) + # server = uvicorn.Server(config) + uvicorn.run("ell.studio.data_server:create_app", + reload=True, + reload_delay=5, + host=args.host, + port=args.port) + # loop.create_task(server.serve()) loop.create_task(db_watcher(db_path, app)) loop.run_forever() diff --git a/src/ell/studio/data_server.py b/src/ell/studio/data_server.py index 8fbefce0..55960c0a 100644 --- a/src/ell/studio/data_server.py +++ b/src/ell/studio/data_server.py @@ -8,6 +8,7 @@ import logging import asyncio import json +from argparse import ArgumentParser logger = logging.getLogger(__name__) @@ -28,9 +29,13 @@ async def broadcast(self, message: str): print(f"Broadcasting message to {connection} {message}") await connection.send_text(message) +def create_app(): + parser = ArgumentParser(description="ELL Studio Data Server") + parser.add_argument("--storage-dir", default=os.getcwd(), + help="Directory for filesystem serializer storage (default: current directory)") + args, _ = parser.parse_known_args() -def create_app(storage_dir: Optional[str] = None): - storage_path = storage_dir or os.environ.get("ELL_STORAGE_DIR") or os.getcwd() + storage_path = args.storage_dir or os.environ.get("ELL_STORAGE_DIR") or os.getcwd() assert storage_path, "ELL_STORAGE_DIR must be set" serializer = SQLiteStore(storage_path)