Files
miku-discord/bot/globals.py
koko210Serve 1fc3d74a5b Add dual GPU support with web UI selector
Features:
- Built custom ROCm container for AMD RX 6800 GPU
- Added GPU selection toggle in web UI (NVIDIA/AMD)
- Unified model names across both GPUs for seamless switching
- Vision model always uses NVIDIA GPU (optimal performance)
- Text models (llama3.1, darkidol) can use either GPU
- Added /gpu-status and /gpu-select API endpoints
- Implemented GPU state persistence in memory/gpu_state.json

Technical details:
- Multi-stage Dockerfile.llamaswap-rocm with ROCm 6.2.4
- llama.cpp compiled with GGML_HIP=ON for gfx1030 (RX 6800)
- Proper GPU permissions without root (groups 187/989)
- AMD container on port 8091, NVIDIA on port 8090
- Updated bot/utils/llm.py with get_current_gpu_url() and get_vision_gpu_url()
- Modified bot/utils/image_handling.py to always use NVIDIA for vision
- Enhanced web UI with GPU selector button (blue=NVIDIA, red=AMD)

Files modified:
- docker-compose.yml (added llama-swap-amd service)
- bot/globals.py (added LLAMA_AMD_URL)
- bot/api.py (added GPU selection endpoints and helper function)
- bot/utils/llm.py (GPU routing for text models)
- bot/utils/image_handling.py (GPU routing for vision models)
- bot/static/index.html (GPU selector UI)
- llama-swap-rocm-config.yaml (unified model names)

New files:
- Dockerfile.llamaswap-rocm
- bot/memory/gpu_state.json
- bot/utils/gpu_router.py (load balancing utility)
- setup-dual-gpu.sh (setup verification script)
- DUAL_GPU_*.md (documentation files)
2026-01-09 00:03:59 +02:00

99 lines
3.3 KiB
Python

# globals.py
import os
from collections import defaultdict, deque
import discord
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))
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
# Autonomous V2 Debug Mode (set to True to see detailed decision logging)
AUTONOMOUS_DEBUG = os.getenv("AUTONOMOUS_DEBUG", "false").lower() == "true"
# Llama.cpp server settings (via llama-swap)
LLAMA_URL = os.getenv("LLAMA_URL", "http://llama-swap:8080")
LLAMA_AMD_URL = os.getenv("LLAMA_AMD_URL", "http://llama-swap-amd:8080") # Secondary AMD GPU
TEXT_MODEL = os.getenv("TEXT_MODEL", "llama3.1")
VISION_MODEL = os.getenv("VISION_MODEL", "vision")
EVIL_TEXT_MODEL = os.getenv("EVIL_TEXT_MODEL", "darkidol") # Uncensored model for evil mode
OWNER_USER_ID = int(os.getenv("OWNER_USER_ID", "209381657369772032")) # Bot owner's Discord user ID for reports
# Fish.audio TTS settings
FISH_API_KEY = os.getenv("FISH_API_KEY", "478d263d8c094e0c8993aae3e9cf9159")
MIKU_VOICE_ID = os.getenv("MIKU_VOICE_ID", "b28b79555e8c4904ac4d048c36e716b7")
# Set up Discord client
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.presences = True
client = discord.Client(intents=intents)
# Note: llama-swap handles model loading/unloading automatically
# No need to track current_model anymore
KINDNESS_KEYWORDS = [
"thank you", "love you", "luv u", "you're the best", "so cute",
"adorable", "amazing", "sweet", "kind", "great job", "well done",
"precious", "good girl", "cutie", "angel", "my favorite", "so helpful"
]
HEART_REACTIONS = ["💙", "💝", "💖", "💕", "💜", "❤️‍🔥", "☺️"]
kindness_reacted_messages = set()
# DM Mood System (simple, auto-rotating only)
DM_MOOD = "neutral"
DM_MOOD_DESCRIPTION = "I'm feeling neutral and balanced today."
AVAILABLE_MOODS = [
"bubbly", "sleepy", "curious", "shy", "serious", "excited", "silly",
"melancholy", "flirty", "romantic", "irritated", "angry", "neutral", "asleep"
]
# Evil Mode System
EVIL_MODE = False
EVIL_DM_MOOD = "evil_neutral"
EVIL_DM_MOOD_DESCRIPTION = "Evil Miku is calculating and cold."
EVIL_AVAILABLE_MOODS = ["aggressive", "cunning", "sarcastic", "evil_neutral"]
EVIL_MOOD_EMOJIS = {
"aggressive": "👿",
"cunning": "🐍",
"sarcastic": "😈",
"evil_neutral": ""
}
# Bipolar Mode System (both Mikus can argue via webhooks)
BIPOLAR_MODE = False
BIPOLAR_WEBHOOKS = {} # guild_id -> {"miku_webhook_url": str, "evil_webhook_url": str}
BIPOLAR_ARGUMENT_IN_PROGRESS = {} # channel_id -> {"active": bool, "exchange_count": int, "current_speaker": str}
# Regular Miku mood emojis (used in bipolar mode for webhook display names)
MOOD_EMOJIS = {
"bubbly": "",
"sleepy": "💤",
"curious": "🔍",
"shy": "🥺",
"serious": "😐",
"excited": "🎉",
"silly": "🤪",
"melancholy": "💙",
"flirty": "💕",
"romantic": "💖",
"irritated": "😤",
"angry": "😠",
"neutral": "",
"asleep": "😴"
}
BOT_USER = None
LAST_FULL_PROMPT = ""
# Persona Dialogue System (conversations between Miku and Evil Miku)
LAST_PERSONA_DIALOGUE_TIME = 0 # Timestamp of last dialogue for cooldown