ZOTHEOS commited on
Commit
cafa3c5
Β·
verified Β·
1 Parent(s): 11a8951

Update modules/config_settings_public.py

Browse files
Files changed (1) hide show
  1. modules/config_settings_public.py +106 -47
modules/config_settings_public.py CHANGED
@@ -1,4 +1,4 @@
1
- # FILE: modules/config_settings_public.py (Definitive Final Version 3 - Corrected Gemma Repo ID)
2
 
3
  import os
4
  import sys
@@ -13,68 +13,127 @@ if not logger.handlers:
13
  logger.addHandler(handler)
14
  logger.setLevel(logging.INFO)
15
 
16
- IS_WEB_MODE = os.path.exists("/home/user/app")
17
-
18
- # --- βœ…βœ…βœ… CORRECTED GEMMA REPO ID (2B, not 2b) βœ…βœ…βœ… ---
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 from 2b to 2B
26
- "filename": "gemma-2b-it.Q4_K_M.gguf"
27
- },
28
- "qwen": {
29
- "repo_id": "Qwen/Qwen1.5-1.8B-Chat-GGUF",
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.1 (Live)"
80
- logger.info(f"Config loaded. Version: {ZOTHEOS_VERSION}, Web Mode: {IS_WEB_MODE}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FILE: modules/config_settings_public.py
2
 
3
  import os
4
  import sys
 
13
  logger.addHandler(handler)
14
  logger.setLevel(logging.INFO)
15
 
16
+ # --- βœ… ENV DETECTION ---
17
+ IS_WEB_MODE = "HF_SPACE_ID" in os.environ
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
+ # "gemma": DISABLED β€” known 404
59
+ }
60
  N_GPU_LAYERS_FALLBACK = 0
61
+ logger.info("N_GPU_LAYERS_FALLBACK forced to 0 for web/CPU-only environment.")
62
+
63
+ else:
64
+ logger.info("βœ…βœ…βœ… RUNNING IN LOCAL MODE (Desktop) βœ…βœ…βœ…")
65
+ MODEL_PATHS = {
66
+ "mistral": os.path.join(BASE_MODELS_DIR, "mistral-7b-instruct-v0.2.Q4_K_M.gguf"),
67
+ "qwen": os.path.join(BASE_MODELS_DIR, "qwen1.5-1.8b-chat.Q4_K_M.gguf")
68
+ # "gemma": os.path.join(BASE_MODELS_DIR, "gemma-2b-it.Q4_K_M.gguf") # Optional: enable locally if you have it
69
+ }
 
 
 
 
 
70
  N_GPU_LAYERS_FALLBACK = -1
71
+ logger.info("N_GPU_LAYERS_FALLBACK set to -1 for local GPU acceleration.")
72
 
73
+ # --- βœ… UNIVERSAL SETTINGS ---
74
+ MAX_RAM_MODELS_GB = 23.8
75
  MAX_CONCURRENT_MODELS = 3
76
  N_CTX_FALLBACK = 2048
77
+ N_THREADS_FALLBACK = 8
78
  VERBOSE_LLAMA_CPP = True
79
+
80
  MODEL_SPECIFIC_PARAMS = {
81
+ "mistral": { "chat_format": "mistral-instruct", "n_ctx": N_CTX_FALLBACK },
82
+ "qwen": { "chat_format": "chatml", "n_ctx": N_CTX_FALLBACK },
83
  "_default": {
84
+ "f16_kv": True, "use_mmap": True, "use_mlock": False,
85
+ "verbose": VERBOSE_LLAMA_CPP,
86
+ "n_gpu_layers": N_GPU_LAYERS_FALLBACK,
87
+ "n_threads": N_THREADS_FALLBACK,
88
+ "n_ctx": N_CTX_FALLBACK
89
+ }
90
  }
91
+
92
  INFERENCE_PRESETS = {
93
+ "balanced": {"temperature": 0.7, "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, "mirostat_mode": 0, "max_tokens": 1024},
94
+ "precise": {"temperature": 0.2, "top_p": 0.7, "top_k": 20, "repeat_penalty": 1.05, "mirostat_mode": 0, "max_tokens": 1536},
95
+ "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},
96
+ "passthrough": {}
97
  }
98
  DEFAULT_INFERENCE_PRESET = "balanced"
99
+
100
+ 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."
101
+
102
+ SYSTEM_PERSONAS = {
103
+ "default": DEFAULT_SYSTEM_PROMPT,
104
+ "helpful_assistant": "You are a helpful AI assistant.",
105
+ "philosopher": "You are a philosopher. Engage deeply and explore ideas.",
106
+ "coder": "You are an expert AI developer. Provide great code and reasoning.",
107
+ "concise_summarizer": "Summarize in bullet points. Be concise."
108
+ }
109
+
110
+ MODEL_ROLES = {
111
+ "mistral": "analyst",
112
+ "qwen": "skeptic"
113
+ }
114
+
115
  MODEL_ROLE_SYSTEM_PROMPTS = {
116
+ "analyst": "You are an impartial analyst. Focus on evidence and logic.",
117
+ "skeptic": "You are a respectful skeptic. Point out flaws and explore alternate views.",
118
+ "general": DEFAULT_SYSTEM_PROMPT
119
+ }
120
+
121
+ MODEL_WEIGHTS = {
122
+ "mistral": 1.0,
123
+ "qwen": 1.1
124
  }
125
+
126
+ LOG_LEVEL = "INFO"
127
+ LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - [%(funcName)s] - %(message)s'
128
+
129
+ ENV_VARS_TO_SET = {
130
+ "TRANSFORMERS_CACHE": CORE_DIRS_TO_VERIFY["cache_transformers"],
131
+ "HF_HOME": CORE_DIRS_TO_VERIFY["cache_huggingface"],
132
+ "HF_HUB_CACHE": CORE_DIRS_TO_VERIFY["cache_hf_hub"],
133
+ "TOKENIZERS_PARALLELISM": "false"
134
+ }
135
+
136
+ ZOTHEOS_VERSION = "Public Beta 1.4 (Web Enabled)"
137
+
138
+ logger.info(f"Config settings loaded. Version: {ZOTHEOS_VERSION}")
139
+ logger.info(f"APP_DIR: {APP_DIR} (Frozen: {_is_frozen}) | Web Mode: {IS_WEB_MODE}")