ZOTHEOS commited on
Commit
40b123c
Β·
verified Β·
1 Parent(s): 26e8bc9

Update modules/config_settings_public.py

Browse files
Files changed (1) hide show
  1. 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
- # --- βœ… FORCE WEB MODE ---
17
- IS_WEB_MODE = True # 🚨 Hugging Face Spaces override
18
- _is_frozen = getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')
19
-
20
- if _is_frozen:
21
- APP_DIR = os.path.dirname(sys.executable)
22
- else:
23
- try:
24
- APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25
- except NameError:
26
- APP_DIR = os.getcwd()
27
- logger.warning(f"__file__ not defined, APP_DIR set to CWD: {APP_DIR}")
28
-
29
- BASE_MODELS_DIR = os.path.join(APP_DIR, "models")
30
- BASE_DATA_SUBDIR = "zotheos_public_data"
31
- BASE_DATA_PATH = os.path.join(APP_DIR, BASE_DATA_SUBDIR)
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
- for dir_key, dir_path in CORE_DIRS_TO_VERIFY.items():
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
- logger.info("N_GPU_LAYERS_FALLBACK forced to 0 for web/CPU-only environment.")
61
-
62
- else:
63
- logger.info("βœ…βœ…βœ… RUNNING IN LOCAL MODE (Desktop) βœ…βœ…βœ…")
64
- MODEL_PATHS = {
65
- "mistral": os.path.join(BASE_MODELS_DIR, "mistral-7b-instruct-v0.2.Q4_K_M.gguf"),
66
- "qwen": os.path.join(BASE_MODELS_DIR, "qwen1.5-1.8b-chat.Q4_K_M.gguf")
67
- }
 
 
 
 
 
 
68
  N_GPU_LAYERS_FALLBACK = -1
69
- logger.info("N_GPU_LAYERS_FALLBACK set to -1 for local GPU acceleration.")
70
 
71
- # --- βœ… UNIVERSAL SETTINGS ---
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
- "f16_kv": True, "use_mmap": True, "use_mlock": False,
83
- "verbose": VERBOSE_LLAMA_CPP,
84
- "n_gpu_layers": N_GPU_LAYERS_FALLBACK,
85
- "n_threads": N_THREADS_FALLBACK,
86
- "n_ctx": N_CTX_FALLBACK
87
- }
88
  }
89
-
90
  INFERENCE_PRESETS = {
91
- "balanced": {"temperature": 0.7, "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, "mirostat_mode": 0, "max_tokens": 1024},
92
- "precise": {"temperature": 0.2, "top_p": 0.7, "top_k": 20, "repeat_penalty": 1.05, "mirostat_mode": 0, "max_tokens": 1536},
93
- "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},
94
- "passthrough": {}
95
  }
96
  DEFAULT_INFERENCE_PRESET = "balanced"
97
-
98
- 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."
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. Focus on evidence and logic.",
115
- "skeptic": "You are a respectful skeptic. Point out flaws and explore alternate views.",
116
- "general": DEFAULT_SYSTEM_PROMPT
117
- }
118
-
119
- MODEL_WEIGHTS = {
120
- "mistral": 1.0,
121
- "qwen": 1.1
122
  }
123
-
124
- LOG_LEVEL = "INFO"
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}")