refactor(arch): modular package structure — split monolithic app.py into config/db/auth/memory/search/rag/gpu + routers/
- config.py: all constants, env vars, limits, skill registry, profiles - db.py: schema init, connection factory, skill state helpers - security.py: PIN hashing, audit logging, rate limiting, CSRF, request helpers - auth.py: session management, PIN verify, auth routes - memory.py: FTS5 CRUD + remember/forget command processing - search.py: SearXNG integration, perplexity scoring, refusal/hedge detection - gpu.py: rocm-smi stats - rag.py: Qdrant vector search + system prompt assembly - routers/: conversations, memories, models, presets, profile, settings, skills, chat, search - app.py: slim entry point, middleware, router registration only Bumps to v1.9.0
This commit is contained in:
31
gpu.py
Normal file
31
gpu.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
JarvisChat - AMD GPU stats via rocm-smi.
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
log = logging.getLogger("jarvischat")
|
||||
|
||||
|
||||
def get_gpu_stats() -> dict:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["rocm-smi", "--showuse", "--showmemuse", "--json"],
|
||||
capture_output=True, text=True, timeout=5,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
data = json.loads(result.stdout)
|
||||
gpu_info = data.get("card0", {})
|
||||
gpu_use = gpu_info.get("GPU use (%)", 0)
|
||||
vram_use = gpu_info.get("GPU Memory Allocated (VRAM%)", 0)
|
||||
if isinstance(gpu_use, str):
|
||||
gpu_use = int(gpu_use.replace("%", "").strip() or 0)
|
||||
if isinstance(vram_use, str):
|
||||
vram_use = int(vram_use.replace("%", "").strip() or 0)
|
||||
return {"gpu_percent": gpu_use, "vram_percent": vram_use, "available": True}
|
||||
except (subprocess.TimeoutExpired, FileNotFoundError, json.JSONDecodeError):
|
||||
pass
|
||||
except Exception as e:
|
||||
log.warning(f"GPU stats error: {e}")
|
||||
return {"gpu_percent": 0, "vram_percent": 0, "available": False}
|
||||
Reference in New Issue
Block a user