diff --git a/backend/spielberg/entrypoint/api/server.py b/backend/spielberg/entrypoint/api/server.py index 1ffb471..6d548db 100644 --- a/backend/spielberg/entrypoint/api/server.py +++ b/backend/spielberg/entrypoint/api/server.py @@ -37,33 +37,52 @@ class BaseAppConfig: + """Base configuration for the app.""" + DEBUG: bool = 1 + """Debug mode for the app.""" TESTING: bool = 1 + """Testing mode for the app.""" SECRET_KEY: str = "secret" + """Secret key for the app.""" LOGGING_CONFIG: dict = LOGGING_CONFIG + """Logging configuration for the app.""" DB_TYPE: str = "sqlite" + """Database type for the app.""" HOST: str = "0.0.0.0" + """Host for the app.""" PORT: int = 8000 + """Port for the app.""" ENV_PREFIX: str = "SERVER" class LocalAppConfig(BaseAppConfig): + """Local configuration for the app. All the default values can be change using environment variables. e.g. `SERVER_PORT=8001`""" + TESTING: bool = 0 + """Testing mode for the app.""" class ProductionAppConfig(BaseAppConfig): + """Production configuration for the app. All the default values can be change using environment variables. e.g. SERVER_PORT=8001""" + DEBUG: bool = 0 + """Debug mode for the app.""" TESTING: bool = 0 + """Testing mode for the app.""" SECRET_KEY: str = "production" + """Secret key for the app.""" configs = dict(local=LocalAppConfig, production=ProductionAppConfig) + +# By default, the server is configured to run in development mode. To run in production mode, set the `SERVER_ENV` environment variable to `production`. app = create_app(app_config=configs[os.getenv("SERVER_ENV", "local")]) if __name__ == "__main__": app.run( host=os.getenv("SERVER_HOST", app.config["HOST"]), port=os.getenv("SERVER_PORT", app.config["PORT"]), - reloader_type="stat" + reloader_type="stat", ) diff --git a/backend/spielberg/entrypoint/api/socket_io.py b/backend/spielberg/entrypoint/api/socket_io.py index 5ff2a70..58138df 100644 --- a/backend/spielberg/entrypoint/api/socket_io.py +++ b/backend/spielberg/entrypoint/api/socket_io.py @@ -8,7 +8,10 @@ class ChatNamespace(Namespace): + """Chat namespace for socket.io""" + def on_chat(self, message): + """Handle chat messages""" chat_handler = ChatHandler( db=load_db(os.getenv("SERVER_DB_TYPE", app.config["DB_TYPE"])) ) diff --git a/docs/server/api.md b/docs/server/api.md index b32a704..84a27ae 100644 --- a/docs/server/api.md +++ b/docs/server/api.md @@ -1,10 +1,11 @@ -## API Routes +# API Routes Routes are defined in the `routes` folder. ## Agent routes -## GET /agent + +### GET /agent Return the agent information @@ -19,7 +20,7 @@ Return the agent information "name": "download" }, { - "description": "Agent to get information about the pricing and usage of VideoDB, it is also helpful for running scenarios to get the estimates.", + "description": "Agent to get information about the VideoDB pricing and usage.", "name": "pricing" } ] @@ -27,27 +28,188 @@ Return the agent information ## Session routes -## GET /session +### GET /session Returns all the sessions ```json [ { - "collection_id": "c-890bd0a5-2ec3-47c0-86dc-685953995206", + "collection_id": "c-**", "created_at": 1729092742, "metadata": {}, "session_id": "52881f6b-7560-4844-ac35-52af41d07ab8", "updated_at": 1729092742, - "video_id": "m-138de44f-d963-4a4c-a239-a30df4dc496a" + "video_id": "m-**" }, { - "collection_id": "c-890bd0a5-2ec3-47c0-86dc-685953995206", + "collection_id": "c-**", "created_at": 1729092642, "metadata": {}, "session_id": "6bf075a7-e7d4-4aba-985c-4cf0d3dc6f5b", "updated_at": 1729092642, - "video_id": "m-13d436a6-ad61-410d-b51c-5ebd80e87066" + "video_id": "m-**" } ] ``` + +### GET /session/:session_id + +Returns the session + +```json +{ + "collection_id": "c-**", + "conversation": [ + { + "actions": [], + "agents": [], + "content": [ + { + "text": "No of video in my collection?", + "type": "text" + } + ], + "conv_id": "b36c0a31-3c95-4f48-a1aa-daad351a30c3", + "created_at": 1729852558, + "metadata": {}, + "msg_id": "1b753948-3672-446d-a7ab-ecd623d4244a", + "msg_type": "input", + "session_id": "33a41576-ffb3-4cec-993c-eedd728c21ac", + "status": "success", + "updated_at": 1729852558 + }, + { + "actions": [ + "Reasoning the message.." + ], + "agents": [], + "content": [ + { + "agent_name": null, + "status": "success", + "status_message": "Here is the summary of the response", + "text": "There are 36 videos in your collection.", + "type": "text" + } + ], + "conv_id": "b36c0a31-3c95-4f48-a1aa-daad351a30c3", + "created_at": 1729852562, + "metadata": {}, + "msg_id": "172985255862403.2", + "msg_type": "output", + "session_id": "33a41576-ffb3-4cec-993c-eedd728c21ac", + "status": "success", + "updated_at": 1729852562 + } + ], + "created_at": 1729852558, + "metadata": {}, + "session_id": "33a41576-ffb3-4cec-993c-eedd728c21ac", + "updated_at": 1729852558, + "video_id": null +} +``` + +### DELETE /session/:session_id + +Deletes the session + +```json +{ + "message": "Session deleted successfully." +} +``` + + +## VideoDB routes + +### GET /videodb/collection + +Returns all the collections + +```json +[ + { + "description": "Test collection", + "id": "c-**", + "name": "Ankit Raj's collection" + }, + { + "description": "Test1 collection", + "id": "c-**", + "name": "Ankit Raj's collection" + }, +] +``` + +### GET /videodb/collection/:collection_id + +Returns the collection + +```json +{ + "description": "Test collection", + "id": "c-**", + "name": "Ankit Raj's collection" +} +``` + + +### GET /videodb/collection/:collection_id/video + +Returns all the videos in the collection + +```json +[ + { + "collection_id": "c-**", + "description": null, + "id": "m-**", + "length": 1247.468844, + "name": "Test video", + "stream_url": "https://stream.videodb.io/v3/published/manifests/test.m3u8", + "thumbnail_url": null + }, + { + "collection_id": "c-**", + "description": null, + "id": "m-**", + "length": 155.620136, + "name": "Test video", + "stream_url": "https://stream.videodb.io/v3/published/manifests/test.m3u8", + "thumbnail_url": null + }, +] +``` + +### GET /videodb/collection/:collection_id/video/:video_id + +Returns the video + +```json +{ + "collection_id": "c-**", + "description": null, + "id": "m-**", + "length": 1247.468844, + "name": "Test video", + "stream_url": "https://stream.videodb.io/v3/published/manifests/test.m3u8", + "thumbnail_url": null +} +``` + + +## Config routes + +### GET /config/check + +Check the configuration + +```json +{ + "db_configured": true, + "llm_configured": true, + "videodb_configured": true +} +``` \ No newline at end of file diff --git a/docs/server/initialization.md b/docs/server/initialization.md index 98f0663..d29135b 100644 --- a/docs/server/initialization.md +++ b/docs/server/initialization.md @@ -5,7 +5,7 @@ Server is the entry point for the application. Implemented using Flask and Socke ## Server Config -::: spielberg.entrypoint.api.server.BaseAppConfig +By default, the server is configured to run in development mode. To run in production mode, set the `SERVER_ENV` environment variable to `production`. ::: spielberg.entrypoint.api.server.LocalAppConfig diff --git a/docs/server/socketio.md b/docs/server/socketio.md index ab2bcdb..07019db 100644 --- a/docs/server/socketio.md +++ b/docs/server/socketio.md @@ -5,4 +5,4 @@ WebSocket routes are defined in the `sockets` folder. ### Chat Namespace - +::: spielberg.entrypoint.api.socket_io.ChatNamespace