cleanup: remove dead code + deduplicate GPU state reads
Dead code removed: - globals.py: GUILD_SETTINGS (empty dict, zero consumers) - config.py: unused 'import os' - config_manager.py: unused 'import os' and 'Union' - server_manager.py: duplicate 'from datetime import datetime, timedelta' GPU deduplication: - get_current_gpu_url() now delegates to config_manager.get_gpu() - get_gpu_status() endpoint now delegates to config_manager.get_gpu() - Both previously re-read memory/gpu_state.json directly
This commit is contained in:
21
bot/api.py
21
bot/api.py
@@ -72,17 +72,9 @@ api_requests_logger = get_logger('api.requests')
|
||||
# ========== GPU Selection Helper ==========
|
||||
def get_current_gpu_url():
|
||||
"""Get the URL for the currently selected GPU"""
|
||||
gpu_state_file = os.path.join(os.path.dirname(__file__), "memory", "gpu_state.json")
|
||||
try:
|
||||
with open(gpu_state_file, "r") as f:
|
||||
state = json.load(f)
|
||||
current_gpu = state.get("current_gpu", "nvidia")
|
||||
if current_gpu == "amd":
|
||||
from config_manager import config_manager
|
||||
if config_manager.get_gpu() == "amd":
|
||||
return globals.LLAMA_AMD_URL
|
||||
else:
|
||||
return globals.LLAMA_URL
|
||||
except:
|
||||
# Default to NVIDIA if state file doesn't exist
|
||||
return globals.LLAMA_URL
|
||||
|
||||
app = FastAPI()
|
||||
@@ -697,13 +689,8 @@ def cleanup_bipolar_webhooks():
|
||||
@app.get("/gpu-status")
|
||||
def get_gpu_status():
|
||||
"""Get current GPU selection"""
|
||||
gpu_state_file = os.path.join(os.path.dirname(__file__), "memory", "gpu_state.json")
|
||||
try:
|
||||
with open(gpu_state_file, "r") as f:
|
||||
state = json.load(f)
|
||||
return {"gpu": state.get("current_gpu", "nvidia")}
|
||||
except:
|
||||
return {"gpu": "nvidia"}
|
||||
from config_manager import config_manager
|
||||
return {"gpu": config_manager.get_gpu()}
|
||||
|
||||
@app.post("/gpu-select")
|
||||
async def select_gpu(request: Request):
|
||||
|
||||
@@ -5,7 +5,6 @@ Uses Pydantic for type-safe configuration loading from:
|
||||
- config.yaml (all other configuration)
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -10,9 +10,8 @@ Handles:
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any, Dict, Optional
|
||||
from datetime import datetime
|
||||
import yaml
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
scheduler = AsyncIOScheduler()
|
||||
|
||||
GUILD_SETTINGS = {}
|
||||
|
||||
# Stores last 5 exchanges per user (as deque)
|
||||
conversation_history = defaultdict(lambda: deque(maxlen=5))
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ from apscheduler.triggers.interval import IntervalTrigger
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from apscheduler.triggers.date import DateTrigger
|
||||
import random
|
||||
from datetime import datetime, timedelta
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger('server')
|
||||
|
||||
Reference in New Issue
Block a user