Spaces:
Running
Running
Update modules/config_settings_public.py
Browse files- modules/config_settings_public.py +47 -104
modules/config_settings_public.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# FILE: modules/config_settings_public.py
|
2 |
|
3 |
import os
|
4 |
import sys
|
@@ -13,125 +13,68 @@ if not logger.handlers:
|
|
13 |
logger.addHandler(handler)
|
14 |
logger.setLevel(logging.INFO)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
CORE_DIRS_TO_VERIFY = {
|
34 |
-
"data_base": BASE_DATA_PATH,
|
35 |
-
"memory": os.path.join(BASE_DATA_PATH, "zotheos_memory"),
|
36 |
-
"cache": os.path.join(BASE_DATA_PATH, "cache"),
|
37 |
-
"cache_transformers": os.path.join(BASE_DATA_PATH, "cache", "transformers"),
|
38 |
-
"cache_huggingface": os.path.join(BASE_DATA_PATH, "cache", "huggingface"),
|
39 |
-
"cache_hf_hub": os.path.join(BASE_DATA_PATH, "cache", "huggingface", "hub"),
|
40 |
-
"logs": os.path.join(BASE_DATA_PATH, "logs"),
|
41 |
-
"temp": os.path.join(BASE_DATA_PATH, "temp_files"),
|
42 |
-
"models_root": BASE_MODELS_DIR
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
if dir_key == "models_root" and (_is_frozen or IS_WEB_MODE):
|
47 |
-
continue
|
48 |
-
os.makedirs(dir_path, exist_ok=True)
|
49 |
|
50 |
-
# --- β
MODEL PATHS CONFIG ---
|
51 |
if IS_WEB_MODE:
|
52 |
logger.info("β
β
β
RUNNING IN WEB MODE (Hugging Face Space) β
β
β
")
|
53 |
-
logger.info("Model paths will be resolved via hf_hub_download.")
|
54 |
-
|
55 |
-
MODEL_PATHS = {
|
56 |
-
"mistral": hf_hub_download(repo_id="TheBloke/Mistral-7B-Instruct-v0.2-GGUF", filename="mistral-7b-instruct-v0.2.Q4_K_M.gguf"),
|
57 |
-
"qwen": hf_hub_download(repo_id="Qwen/Qwen1.5-1.8B-Chat-GGUF", filename="qwen1.5-1.8b-chat.Q4_K_M.gguf")
|
58 |
-
}
|
59 |
N_GPU_LAYERS_FALLBACK = 0
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
N_GPU_LAYERS_FALLBACK = -1
|
69 |
-
logger.info("N_GPU_LAYERS_FALLBACK set to -1 for local GPU acceleration.")
|
70 |
|
71 |
-
# ---
|
72 |
-
MAX_RAM_MODELS_GB = 23.8
|
73 |
MAX_CONCURRENT_MODELS = 3
|
74 |
N_CTX_FALLBACK = 2048
|
75 |
-
N_THREADS_FALLBACK = 8
|
76 |
VERBOSE_LLAMA_CPP = True
|
77 |
-
|
78 |
MODEL_SPECIFIC_PARAMS = {
|
79 |
-
"mistral": { "chat_format": "mistral-instruct", "n_ctx": N_CTX_FALLBACK },
|
80 |
-
"qwen": { "chat_format": "chatml", "n_ctx": N_CTX_FALLBACK },
|
81 |
"_default": {
|
82 |
-
"
|
83 |
-
"verbose": VERBOSE_LLAMA_CPP
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
}
|
88 |
}
|
89 |
-
|
90 |
INFERENCE_PRESETS = {
|
91 |
-
"balanced": {"temperature": 0.7, "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, "
|
92 |
-
"precise":
|
93 |
-
"creative": {"temperature": 0.9, "top_p": 0.95, "top_k": 60, "repeat_penalty": 1.15, "
|
94 |
-
"passthrough": {}
|
95 |
}
|
96 |
DEFAULT_INFERENCE_PRESET = "balanced"
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
SYSTEM_PERSONAS = {
|
101 |
-
"default": DEFAULT_SYSTEM_PROMPT,
|
102 |
-
"helpful_assistant": "You are a helpful AI assistant.",
|
103 |
-
"philosopher": "You are a philosopher. Engage deeply and explore ideas.",
|
104 |
-
"coder": "You are an expert AI developer. Provide great code and reasoning.",
|
105 |
-
"concise_summarizer": "Summarize in bullet points. Be concise."
|
106 |
-
}
|
107 |
-
|
108 |
-
MODEL_ROLES = {
|
109 |
-
"mistral": "analyst",
|
110 |
-
"qwen": "skeptic"
|
111 |
-
}
|
112 |
-
|
113 |
MODEL_ROLE_SYSTEM_PROMPTS = {
|
114 |
-
"analyst": "You are an impartial analyst.
|
115 |
-
"skeptic": "You are a
|
116 |
-
"general": DEFAULT_SYSTEM_PROMPT
|
117 |
-
}
|
118 |
-
|
119 |
-
MODEL_WEIGHTS = {
|
120 |
-
"mistral": 1.0,
|
121 |
-
"qwen": 1.1
|
122 |
}
|
123 |
-
|
124 |
-
|
125 |
-
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - [%(funcName)s] - %(message)s'
|
126 |
-
|
127 |
-
ENV_VARS_TO_SET = {
|
128 |
-
"TRANSFORMERS_CACHE": CORE_DIRS_TO_VERIFY["cache_transformers"],
|
129 |
-
"HF_HOME": CORE_DIRS_TO_VERIFY["cache_huggingface"],
|
130 |
-
"HF_HUB_CACHE": CORE_DIRS_TO_VERIFY["cache_hf_hub"],
|
131 |
-
"TOKENIZERS_PARALLELISM": "false"
|
132 |
-
}
|
133 |
-
|
134 |
-
ZOTHEOS_VERSION = "Public Beta 1.4 (Web Enabled)"
|
135 |
-
|
136 |
-
logger.info(f"Config settings loaded. Version: {ZOTHEOS_VERSION}")
|
137 |
-
logger.info(f"APP_DIR: {APP_DIR} (Frozen: {_is_frozen}) | Web Mode: {IS_WEB_MODE}")
|
|
|
1 |
+
# FILE: modules/config_settings_public.py (Final Verified Version)
|
2 |
|
3 |
import os
|
4 |
import sys
|
|
|
13 |
logger.addHandler(handler)
|
14 |
logger.setLevel(logging.INFO)
|
15 |
|
16 |
+
IS_WEB_MODE = os.path.exists("/home/user/app")
|
17 |
+
|
18 |
+
# --- β
β
β
VERIFIED AND CORRECTED REPO IDS β
β
β
---
|
19 |
+
MODEL_DEFINITIONS = {
|
20 |
+
"mistral": {
|
21 |
+
"repo_id": "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
|
22 |
+
"filename": "mistral-7b-instruct-v0.2.Q4_K_M.gguf"
|
23 |
+
},
|
24 |
+
"gemma": {
|
25 |
+
"repo_id": "TheBloke/Gemma-2B-IT-GGUF", # Corrected: Capital 'G' and 'IT'
|
26 |
+
"filename": "gemma-2b-it.Q4_K_M.gguf"
|
27 |
+
},
|
28 |
+
"qwen": {
|
29 |
+
"repo_id": "TheBloke/Qwen1.5-1.8B-Chat-GGUF", # Corrected to use TheBloke's repo
|
30 |
+
"filename": "qwen1.5-1.8b-chat.Q4_K_M.gguf"
|
31 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
+
MODEL_PATHS = {}
|
|
|
|
|
|
|
35 |
|
|
|
36 |
if IS_WEB_MODE:
|
37 |
logger.info("β
β
β
RUNNING IN WEB MODE (Hugging Face Space) β
β
β
")
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
N_GPU_LAYERS_FALLBACK = 0
|
39 |
+
for name, model_info in MODEL_DEFINITIONS.items():
|
40 |
+
logger.info(f"Downloading model: {name} from repo: {model_info['repo_id']}")
|
41 |
+
try:
|
42 |
+
MODEL_PATHS[name] = hf_hub_download(repo_id=model_info["repo_id"], filename=model_info["filename"])
|
43 |
+
logger.info(f"β
Successfully downloaded {name}.")
|
44 |
+
except Exception as e:
|
45 |
+
logger.error(f"β FAILED to download model {name}. Error: {e}")
|
46 |
+
raise e
|
47 |
+
else: # LOCAL MODE
|
48 |
+
logger.info("β
β
β
RUNNING IN LOCAL MODE (Desktop/PC) β
β
β
")
|
49 |
+
APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
50 |
+
BASE_MODELS_DIR = os.path.join(APP_DIR, "models")
|
51 |
+
for name, model_info in MODEL_DEFINITIONS.items():
|
52 |
+
MODEL_PATHS[name] = os.path.join(BASE_MODELS_DIR, model_info["filename"])
|
53 |
N_GPU_LAYERS_FALLBACK = -1
|
|
|
54 |
|
55 |
+
# --- Shared Configurations ---
|
|
|
56 |
MAX_CONCURRENT_MODELS = 3
|
57 |
N_CTX_FALLBACK = 2048
|
|
|
58 |
VERBOSE_LLAMA_CPP = True
|
|
|
59 |
MODEL_SPECIFIC_PARAMS = {
|
|
|
|
|
60 |
"_default": {
|
61 |
+
"n_gpu_layers": N_GPU_LAYERS_FALLBACK, "n_ctx": N_CTX_FALLBACK, "f16_kv": True,
|
62 |
+
"use_mmap": True, "verbose": VERBOSE_LLAMA_CPP
|
63 |
+
},
|
64 |
+
"mistral": {"chat_format": "mistral-instruct"}, "gemma": {"chat_format": "gemma"},
|
65 |
+
"qwen": {"chat_format": "chatml"}
|
|
|
66 |
}
|
|
|
67 |
INFERENCE_PRESETS = {
|
68 |
+
"balanced": {"temperature": 0.7, "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, "max_tokens": 1024},
|
69 |
+
"precise": {"temperature": 0.2, "top_p": 0.7, "top_k": 20, "repeat_penalty": 1.05, "max_tokens": 1536},
|
70 |
+
"creative": {"temperature": 0.9, "top_p": 0.95, "top_k": 60, "repeat_penalty": 1.15, "max_tokens": 1024}
|
|
|
71 |
}
|
72 |
DEFAULT_INFERENCE_PRESET = "balanced"
|
73 |
+
DEFAULT_SYSTEM_PROMPT = "You are ZOTHEOS, an ethical AI developed to help humanity."
|
74 |
+
MODEL_ROLES = {"mistral": "analyst", "gemma": "humanist", "qwen": "skeptic"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
MODEL_ROLE_SYSTEM_PROMPTS = {
|
76 |
+
"analyst": "You are an impartial analyst.", "humanist": "You are a human-centered assistant.",
|
77 |
+
"skeptic": "You are a critical evaluator and a respectful skeptic.", "general": DEFAULT_SYSTEM_PROMPT
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
+
ZOTHEOS_VERSION = "2.2 (Live and Corrected)"
|
80 |
+
logger.info(f"Config loaded. Version: {ZOTHEOS_VERSION}, Web Mode: {IS_WEB_MODE}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|