forked from ComputerTech/aprhodite
Implement JSON config system and AI PM integration
This commit is contained in:
parent
1537d8518e
commit
bff5afc366
|
|
@ -15,6 +15,7 @@ instance/
|
||||||
|
|
||||||
# Environment
|
# Environment
|
||||||
.env
|
.env
|
||||||
|
config.json
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
|
|
|
||||||
34
app.py
34
app.py
|
|
@ -39,6 +39,7 @@ Socket events (server → client)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
import base64
|
import base64
|
||||||
|
|
@ -57,21 +58,42 @@ from flask_socketio import SocketIO, emit, join_room, disconnect
|
||||||
from database import db, init_db
|
from database import db, init_db
|
||||||
from models import User, Message, UserIgnore
|
from models import User, Message, UserIgnore
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Configuration Loader
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
conf = {}
|
||||||
|
config_path = os.path.join(os.path.dirname(__file__), "config.json")
|
||||||
|
if os.path.exists(config_path):
|
||||||
|
try:
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
conf = json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Warning: Failed to load config.json: {e}")
|
||||||
|
return conf
|
||||||
|
|
||||||
|
_CONFIG = load_config()
|
||||||
|
|
||||||
|
def _get_conf(key, default=None):
|
||||||
|
# Order: Env Var > Config File > Default
|
||||||
|
return os.environ.get(key, _CONFIG.get(key, default))
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Configuration
|
# Configuration
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
SECRET_KEY = os.environ.get("SECRET_KEY", uuid.uuid4().hex)
|
SECRET_KEY = _get_conf("SECRET_KEY", uuid.uuid4().hex)
|
||||||
JWT_SECRET = os.environ.get("JWT_SECRET", uuid.uuid4().hex)
|
JWT_SECRET = _get_conf("JWT_SECRET", uuid.uuid4().hex)
|
||||||
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "admin1234")
|
ADMIN_PASSWORD = _get_conf("ADMIN_PASSWORD", "admin1234")
|
||||||
MAX_MSG_LEN = 500
|
MAX_MSG_LEN = 500
|
||||||
LOBBY = "lobby"
|
LOBBY = "lobby"
|
||||||
AI_FREE_LIMIT = 3
|
AI_FREE_LIMIT = int(_get_conf("AI_FREE_LIMIT", 3))
|
||||||
AI_BOT_NAME = "Violet"
|
AI_BOT_NAME = "Violet"
|
||||||
|
|
||||||
# Ollama
|
# Ollama
|
||||||
OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://localhost:11434")
|
OLLAMA_URL = _get_conf("OLLAMA_URL", "http://localhost:11434")
|
||||||
VIOLET_MODEL = os.environ.get("VIOLET_MODEL", "sam860/dolphin3-llama3.2:3b")
|
VIOLET_MODEL = _get_conf("VIOLET_MODEL", "sam860/dolphin3-llama3.2:3b")
|
||||||
VIOLET_SYSTEM = (
|
VIOLET_SYSTEM = (
|
||||||
"You are Violet, a flirtatious and sophisticated nightclub hostess at "
|
"You are Violet, a flirtatious and sophisticated nightclub hostess at "
|
||||||
"an exclusive, dimly-lit members-only club. You are charming, witty, "
|
"an exclusive, dimly-lit members-only club. You are charming, witty, "
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"HOST": "0.0.0.0",
|
||||||
|
"PORT": 5000,
|
||||||
|
"SECRET_KEY": "sexchat-very-secret-key-change-me",
|
||||||
|
"JWT_SECRET": "sexchat-jwt-secret-key-change-me",
|
||||||
|
"ADMIN_PASSWORD": "admin",
|
||||||
|
"OLLAMA_URL": "http://localhost:11434",
|
||||||
|
"VIOLET_MODEL": "sam860/dolphin3-llama3.2:3b",
|
||||||
|
"DATABASE_URL": "sqlite:///instance/sexchat.db",
|
||||||
|
"REDIS_URL": "redis://localhost:6379/0",
|
||||||
|
"AI_FREE_LIMIT": 3
|
||||||
|
}
|
||||||
20
start.py
20
start.py
|
|
@ -12,6 +12,7 @@ Usage:
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
@ -23,6 +24,21 @@ eventlet.monkey_patch()
|
||||||
# PID file to track the daemon process
|
# PID file to track the daemon process
|
||||||
PID_FILE = "sexchat.pid"
|
PID_FILE = "sexchat.pid"
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
conf = {}
|
||||||
|
config_path = os.path.join(os.path.dirname(__file__), "config.json")
|
||||||
|
if os.path.exists(config_path):
|
||||||
|
try:
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
conf = json.load(f)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return conf
|
||||||
|
|
||||||
|
def _get_conf(key, default=None):
|
||||||
|
conf = load_config()
|
||||||
|
return os.environ.get(key, conf.get(key, default))
|
||||||
|
|
||||||
def get_pid():
|
def get_pid():
|
||||||
if os.path.exists(PID_FILE):
|
if os.path.exists(PID_FILE):
|
||||||
with open(PID_FILE, "r") as f:
|
with open(PID_FILE, "r") as f:
|
||||||
|
|
@ -52,7 +68,7 @@ def start_daemon():
|
||||||
"gunicorn",
|
"gunicorn",
|
||||||
"--worker-class", "eventlet",
|
"--worker-class", "eventlet",
|
||||||
"-w", "1",
|
"-w", "1",
|
||||||
"--bind", f"{os.environ.get('HOST', '0.0.0.0')}:{os.environ.get('PORT', '5000')}",
|
"--bind", f"{_get_conf('HOST', '0.0.0.0')}:{_get_conf('PORT', 5000)}",
|
||||||
"--daemon",
|
"--daemon",
|
||||||
"--pid", PID_FILE,
|
"--pid", PID_FILE,
|
||||||
"--access-logfile", "access.log",
|
"--access-logfile", "access.log",
|
||||||
|
|
@ -108,7 +124,7 @@ def run_debug():
|
||||||
"gunicorn",
|
"gunicorn",
|
||||||
"--worker-class", "eventlet",
|
"--worker-class", "eventlet",
|
||||||
"-w", "1",
|
"-w", "1",
|
||||||
"--bind", f"{os.environ.get('HOST', '0.0.0.0')}:{os.environ.get('PORT', '5000')}",
|
"--bind", f"{_get_conf('HOST', '0.0.0.0')}:{_get_conf('PORT', 5000)}",
|
||||||
"--log-level", "debug",
|
"--log-level", "debug",
|
||||||
"--access-logfile", "-",
|
"--access-logfile", "-",
|
||||||
"--error-logfile", "-",
|
"--error-logfile", "-",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue