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:
25
bot/api.py
25
bot/api.py
@@ -72,18 +72,10 @@ api_requests_logger = get_logger('api.requests')
|
|||||||
# ========== GPU Selection Helper ==========
|
# ========== GPU Selection Helper ==========
|
||||||
def get_current_gpu_url():
|
def get_current_gpu_url():
|
||||||
"""Get the URL for the currently selected GPU"""
|
"""Get the URL for the currently selected GPU"""
|
||||||
gpu_state_file = os.path.join(os.path.dirname(__file__), "memory", "gpu_state.json")
|
from config_manager import config_manager
|
||||||
try:
|
if config_manager.get_gpu() == "amd":
|
||||||
with open(gpu_state_file, "r") as f:
|
return globals.LLAMA_AMD_URL
|
||||||
state = json.load(f)
|
return globals.LLAMA_URL
|
||||||
current_gpu = state.get("current_gpu", "nvidia")
|
|
||||||
if current_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()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -697,13 +689,8 @@ def cleanup_bipolar_webhooks():
|
|||||||
@app.get("/gpu-status")
|
@app.get("/gpu-status")
|
||||||
def get_gpu_status():
|
def get_gpu_status():
|
||||||
"""Get current GPU selection"""
|
"""Get current GPU selection"""
|
||||||
gpu_state_file = os.path.join(os.path.dirname(__file__), "memory", "gpu_state.json")
|
from config_manager import config_manager
|
||||||
try:
|
return {"gpu": config_manager.get_gpu()}
|
||||||
with open(gpu_state_file, "r") as f:
|
|
||||||
state = json.load(f)
|
|
||||||
return {"gpu": state.get("current_gpu", "nvidia")}
|
|
||||||
except:
|
|
||||||
return {"gpu": "nvidia"}
|
|
||||||
|
|
||||||
@app.post("/gpu-select")
|
@app.post("/gpu-select")
|
||||||
async def select_gpu(request: Request):
|
async def select_gpu(request: Request):
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ Uses Pydantic for type-safe configuration loading from:
|
|||||||
- config.yaml (all other configuration)
|
- config.yaml (all other configuration)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ Handles:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional, Union
|
from typing import Any, Dict, Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|||||||
|
|
||||||
scheduler = AsyncIOScheduler()
|
scheduler = AsyncIOScheduler()
|
||||||
|
|
||||||
GUILD_SETTINGS = {}
|
|
||||||
|
|
||||||
# Stores last 5 exchanges per user (as deque)
|
# Stores last 5 exchanges per user (as deque)
|
||||||
conversation_history = defaultdict(lambda: deque(maxlen=5))
|
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.cron import CronTrigger
|
||||||
from apscheduler.triggers.date import DateTrigger
|
from apscheduler.triggers.date import DateTrigger
|
||||||
import random
|
import random
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from utils.logger import get_logger
|
from utils.logger import get_logger
|
||||||
|
|
||||||
logger = get_logger('server')
|
logger = get_logger('server')
|
||||||
|
|||||||
Reference in New Issue
Block a user