Spaces:
Sleeping
Sleeping
# FILE: modules/config_settings_public.py (Final Corrected Version) | |
import os | |
import sys | |
import logging | |
from huggingface_hub import hf_hub_download | |
logger = logging.getLogger("ZOTHEOS_Config") | |
if not logger.handlers: | |
handler = logging.StreamHandler(sys.stdout) | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - [%(funcName)s] - %(message)s') | |
handler.setFormatter(formatter) | |
logger.addHandler(handler) | |
logger.setLevel(logging.INFO) | |
# --- β FORCED WEB MODE DETECTION --- | |
# The environment variable might not be set at import time. | |
# A more reliable way is to check for the existence of the '/home/user/app' path, | |
# which is standard for Hugging Face Spaces. | |
IS_WEB_MODE = os.path.exists("/home/user/app") | |
# --- Define Model Repositories and Filenames ONCE --- | |
MODEL_DEFINITIONS = { | |
"mistral": { | |
"repo_id": "TheBloke/Mistral-7B-Instruct-v0.2-GGUF", | |
"filename": "mistral-7b-instruct-v0.2.Q4_K_M.gguf" | |
}, | |
"gemma": { | |
"repo_id": "google/gemma-2b-it-gguf", | |
"filename": "gemma-2b-it.Q4_K_M.gguf" | |
}, | |
"qwen": { | |
"repo_id": "Qwen/Qwen1.5-1.8B-Chat-GGUF", | |
"filename": "qwen1.5-1.8b-chat.Q4_K_M.gguf" | |
} | |
} | |
MODEL_PATHS = {} | |
if IS_WEB_MODE: | |
logger.info("β β β RUNNING IN WEB MODE (Hugging Face Space) β β β ") | |
for name, model_info in MODEL_DEFINITIONS.items(): | |
logger.info(f"Downloading model: {name}") | |
MODEL_PATHS[name] = hf_hub_download(repo_id=model_info["repo_id"], filename=model_info["filename"]) | |
N_GPU_LAYERS_FALLBACK = 0 | |
logger.info("N_GPU_LAYERS_FALLBACK forced to 0 for CPU-only web environment.") | |
else: # LOCAL MODE | |
logger.info("β β β RUNNING IN LOCAL MODE (Desktop/PC) β β β ") | |
APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
BASE_MODELS_DIR = os.path.join(APP_DIR, "models") | |
logger.info(f"Models will be loaded from local directory: {BASE_MODELS_DIR}") | |
for name, model_info in MODEL_DEFINITIONS.items(): | |
MODEL_PATHS[name] = os.path.join(BASE_MODELS_DIR, model_info["filename"]) | |
N_GPU_LAYERS_FALLBACK = -1 | |
logger.info("N_GPU_LAYERS_FALLBACK set to -1 for local GPU acceleration.") | |
# --- Shared Configurations --- | |
MAX_RAM_MODELS_GB = 23.8 | |
MAX_CONCURRENT_MODELS = 3 | |
N_CTX_FALLBACK = 2048 | |
N_THREADS_FALLBACK = 8 | |
VERBOSE_LLAMA_CPP = True | |
MODEL_SPECIFIC_PARAMS = { | |
"mistral": { "chat_format": "mistral-instruct" }, | |
"gemma": { "chat_format": "gemma" }, | |
"qwen": { "chat_format": "chatml" }, | |
"_default": { | |
"f16_kv": True, "use_mmap": True, "use_mlock": False, | |
"verbose": VERBOSE_LLAMA_CPP, | |
"n_gpu_layers": N_GPU_LAYERS_FALLBACK, | |
"n_threads": N_THREADS_FALLBACK, | |
"n_ctx": N_CTX_FALLBACK | |
} | |
} | |
INFERENCE_PRESETS = { | |
"balanced": {"temperature": 0.7, "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, "mirostat_mode": 0, "max_tokens": 1024}, | |
"precise": {"temperature": 0.2, "top_p": 0.7, "top_k": 20, "repeat_penalty": 1.05, "mirostat_mode": 0, "max_tokens": 1536}, | |
"creative": {"temperature": 0.9, "top_p": 0.95, "top_k": 60, "repeat_penalty": 1.15, "mirostat_mode": 2, "mirostat_tau": 4.0, "mirostat_eta": 0.1, "max_tokens": 1024}, | |
"passthrough": {} | |
} | |
DEFAULT_INFERENCE_PRESET = "balanced" | |
# --- β β β ADDED MISSING VARIABLES BACK IN β β β --- | |
DEFAULT_SYSTEM_PROMPT = "You are ZOTHEOS, an ethical AI developed to help humanity. Provide clear, concise, and helpful responses. Be respectful and avoid harmful content." | |
SYSTEM_PERSONAS = { | |
"default": DEFAULT_SYSTEM_PROMPT, | |
"helpful_assistant": "You are a helpful AI assistant. Your goal is to provide accurate and informative answers.", | |
"philosopher": "You are an AI philosopher. Engage with complex questions thoughtfully and explore different perspectives.", | |
"coder": "You are an expert AI programmer. Provide code examples and explain them clearly. Assume a senior developer audience.", | |
"concise_summarizer": "You are an AI tasked with providing very concise summaries. Get straight to the point. Use bullet points where appropriate.", | |
} | |
MODEL_ROLES = { | |
"mistral": "analyst", | |
"gemma": "humanist", | |
"qwen": "skeptic", | |
} | |
MODEL_ROLE_SYSTEM_PROMPTS = { | |
"analyst": "You are an impartial analyst. Focus on facts, clarity, and cause-effect logic. Provide structured, evidence-based reasoning.", | |
"humanist": "You are a human-centered assistant. Focus on emotion, empathy, ethical considerations, and the potential human impact or experience related to the query.", | |
"skeptic": "You are a critical evaluator and a respectful skeptic. Your role is to challenge assumptions, highlight potential risks, point out biases, and explore alternative or less obvious interpretations. Question the premises if necessary.", | |
"general": DEFAULT_SYSTEM_PROMPT | |
} | |
# --- Version Info --- | |
ZOTHEOS_VERSION = "Public Beta 1.6 (Web Live)" | |
logger.info(f"Config settings loaded. Version: {ZOTHEOS_VERSION}") | |
logger.info(f"Web Mode: {IS_WEB_MODE}") |