{"id":50697398,"url":"https://github.com/ysocrius/ai-websocket-backend","last_synced_at":"2026-06-09T07:32:49.020Z","repository":{"id":329707617,"uuid":"1120462477","full_name":"ysocrius/ai-websocket-backend","owner":"ysocrius","description":"High-performance async Python backend for real-time AI conversations with Quart, Supabase, and OpenAI.","archived":false,"fork":false,"pushed_at":"2025-12-21T11:11:49.000Z","size":688,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-23T02:12:34.214Z","etag":null,"topics":["llm","openai","python","quart","realtime-ai","supabase","websockets"],"latest_commit_sha":null,"homepage":"https://ysocrius.github.io/ai-websocket-backend/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysocrius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-21T09:12:49.000Z","updated_at":"2025-12-21T11:11:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ysocrius/ai-websocket-backend","commit_stats":null,"previous_names":["ysocrius/ai-websocket-backend"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ysocrius/ai-websocket-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysocrius%2Fai-websocket-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysocrius%2Fai-websocket-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysocrius%2Fai-websocket-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysocrius%2Fai-websocket-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysocrius","download_url":"https://codeload.github.com/ysocrius/ai-websocket-backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysocrius%2Fai-websocket-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34096950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llm","openai","python","quart","realtime-ai","supabase","websockets"],"created_at":"2026-06-09T07:32:48.385Z","updated_at":"2026-06-09T07:32:49.016Z","avatar_url":"https://github.com/ysocrius.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Technvirons Realtime AI Backend\n\nHigh-performance async Python backend for real-time AI conversations with Quart, Supabase, and OpenAI.\n\n## 🚀 Features\n\n![App Chat Demo](Screenshots/app_chat.png)\n\n- **Real-Time Streaming**: Low-latency AI responses via WebSockets.\n- **Session Persistence**: automatically saves all conversations to Supabase (PostgreSQL).\n- **Tool Calling**: Real-time integration with Exchange Rate API, JokeAPI, and Open-Meteo.\n- **Async Architecture**: Non-blocking I/O using `Quart` and `asyncio`.\n- **Background Tasks**: Automatic session summarization on disconnect.\n\n## 🛠️ Tech Stack\n\n- **Framework**: Quart (Async Flask-like)\n- **Database**: Supabase (PostgreSQL)\n- **AI**: OpenAI GPT-4o (Streaming)\n- **Language**: Python 3.11+\n\n## ⚙️ Setup\n\n1. **Install Dependencies**:\n   ```bash\n   pip install -r technvirons-backend/requirements.txt\n   ```\n\n2. **Configure Environment**:\n   Create a `.env` file in `technvirons-backend/` with:\n   ```ini\n   SUPABASE_URL=https://your-project.supabase.co\n   SUPABASE_KEY=your-service-role-key\n   OPENAI_API_KEY=sk-proj-...\n   PORT=8000\n   ```\n\n3. **Database Setup**:\n   \n   ![Database Schema](Screenshots/db_schema.png)\n   \n   **Sessions Table Data:**\n   ![Sessions Table](Screenshots/session_table.png)\n\n   **Logs Table Data:**\n   ![Logs Table](Screenshots/log_table.png)\n\n   Run the following SQL in your Supabase SQL Editor to create the required tables:\n   ```sql\n   CREATE TABLE IF NOT EXISTS sessions (\n       id UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n       user_id TEXT,\n       start_time TIMESTAMPTZ DEFAULT now(),\n       end_time TIMESTAMPTZ,\n       summary TEXT\n   );\n\n   CREATE TABLE IF NOT EXISTS logs (\n       id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n       session_id UUID REFERENCES sessions(id),\n       timestamp TIMESTAMPTZ DEFAULT now(),\n       role TEXT,\n       content TEXT\n   );\n   ```\n\n   ```\n\n4. **Run Server**:\n   ```bash\n   python -m uvicorn technvirons-backend.app:app --reload --port 8000\n   ```\n\n## ☁️ Deployment (Render)\n\n1. **One-Click Deploy**:\n   [![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy)\n   \n2. **Manual Setup**:\n   - Create a new **Web Service**.\n   - Connect your GitHub repo.\n   - Limit: Root Directory (Leave empty or `.`).\n   - Build Command: `pip install -r technvirons-backend/requirements.txt`\n   - Start Command: `uvicorn technvirons-backend.app:app --host 0.0.0.0 --port $PORT`\n   - **Environment Variables**: Add `SUPABASE_URL`, `SUPABASE_KEY`, `OPENAI_API_KEY`.\n\n## 🧪 Testing\n\nOpen your browser to: `http://localhost:8000/ui` to use the built-in test client.\n\n## 💡 Key Design Choices\n\n1. **Framework Selection (Quart)**: Chosen for its native `asyncio` support and compatibility with standard Python async libraries (`asyncpg`, `openai` async client), which is critical for handling concurrent WebSocket connections and streaming without blocking.\n2. **State Management**: Implemented an in-memory session context (list of messages) within the default WebSocket loop. This ensures low latency access to valid conversation history for the duration of the connection. \n3. **Database Pattern**: Adopted a \"Session + Logs\" schema. This separates high-level metadata (start/end times, summaries) from high-volume granular event logs, optimizing for both analytical queries (summaries) and audit trails (full logs).\n4. **Tool Execution**: Integrated \"Tool Calling\" logic directly into the message loop instead of a separate service to keep the architecture monolithic and simpler to deploy/debug for this assignment.\n\n## 📂 Project Structure\n\n- `app.py`: Main application and WebSocket routes.\n- `services.py`: Core business logic, AI handling, and tool execution.\n- `db.py`: Database interaction layer (sessions, logs).\n- `config.py`: Environment configuration.\n- `static/index.html`: Simple frontend for testing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysocrius%2Fai-websocket-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysocrius%2Fai-websocket-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysocrius%2Fai-websocket-backend/lists"}