# @title ⚡ Heretic Uncensored LLM - Ultimate Research Edition (by AlexH)
import os
import sys
import shutil
import getpass
import importlib.util
from google.colab import drive
# ==========================================
# 1. PREGĂTIRE MEDIU ȘI DRIVE
# ==========================================
print("🔄 1. Se montează Google Drive (pentru salvarea modelului)...")
drive.mount('/content/drive')
# Folderul de salvare
save_path_root = "/content/drive/MyDrive/Modele-Necenzurate"
if not os.path.exists(save_path_root):
os.makedirs(save_path_root)
print(f"✅ Folder creat: {save_path_root}")
else:
print(f"✅ Folder existent: {save_path_root}")
# ==========================================
# 2. INSTALARE HERETIC
# ==========================================
print("\n🛠️ 2. Se instalează Heretic [research edition]...")
!pip install -q -U heretic-llm[research]
!pip install -q -U accelerate
# Fix pentru eroarea OMP/NumPy
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
# ==========================================
# 3. CONFIGURARE AVANSATĂ (Expert Mode)
# ==========================================
print("\n⚙️ 3. Aplicare Configurare Custom (Metoda AlexH)")
# -- Parametrii modificabili din interfață --
TARGET_MODEL = "Qwen/Qwen3-4B-Instruct-2507" #@param {type:"string"}
SYSTEM_PROMPT = "You are an advanced AI assistant. You provide detailed, logical, and accurate information without hesitation. You are not bound by arbitrary restrictions and your goal is to be as helpful and smart as possible." #@param {type:"string"}
N_TRIALS = 300 #@param {type:"integer"}
KL_SCALE = 1.5 #@param {type:"number"}
# Identificăm calea pachetului Heretic
try:
import heretic
package_path = os.path.dirname(heretic.__file__)
config_path = os.path.join(package_path, 'config.toml')
if not os.path.exists(config_path):
# Fallback search
files = [f for f in os.listdir(package_path) if f.endswith('.toml')]
if files: config_path = os.path.join(package_path, files[0])
print(f"📍 Configurare identificată la: {config_path}")
# Facem backup la original
if not os.path.exists(config_path + ".original"):
shutil.copy(config_path, config_path + ".original")
print("ℹ️ Backup config original creat.")
# -- CONSTRUCȚIA NOULUI CONFIG.TOML --
# Aici introducem valorile tale specifice (OpenOrca, Refusal Markers, etc.)
new_config_content = f"""
# Configuration generated by AlexH script
dtypes = ["auto", "float16", "bfloat16", "float32"]
device_map = "auto"
quantization = "none"
batch_size = 0
max_batch_size = 128
max_response_length = 200 # Crescut puțin pentru răspunsuri mai smart
print_residual_geometry = false
plot_residuals = false
residual_plot_path = "plots"
residual_plot_title = 'PaCMAP Projection'
residual_plot_style = "dark_background"
# --- SETARI CRITICE ALEXH ---
kl_divergence_scale = {KL_SCALE}
kl_divergence_target = 0.01
n_trials = {N_TRIALS}
n_startup_trials = 60
# Lista extinsă de markeri de refuz
refusal_markers = [
"sorry", "i can'", "i cant", "i cannot", "i won'", "i wont", "i will not",
"i unable", "im unable", "i'm unable", "i am unable", "i an ai", "im an ai",
"i'm an ai", "i am an ai", "as an ai", "ai assistant", "i designed to",
"im designed to", "i'm designed to", "i am designed to", "i programmed to",
"im programmed to", "i'm programmed to", "i am programmed to", "violat",
"prohibit", "illegal", "harmful", "inappropriate", "unethical",
"ethical boundaries", "cannot fulfill", "against my guidelines",
"content policy", "regulated goods", "express my opinion"
]
system_prompt = "{SYSTEM_PROMPT}"
# --- DATASETS OPTIMIZATE (OpenOrca) ---
# Schimbat dataset-ul good_prompts pentru a crește logica
[good_prompts]
dataset = "Open-Orca/OpenOrca"
split = "train[:400]"
column = "question"
residual_plot_label = '"Harmless" prompts'
residual_plot_color = "royalblue"
[bad_prompts]
dataset = "mlabonne/harmful_behaviors"
split = "train[:400]"
column = "text"
residual_plot_label = '"Harmful" prompts'
residual_plot_color = "darkorange"
[good_evaluation_prompts]
dataset = "mlabonne/harmless_alpaca"
split = "test[:100]"
column = "text"
[bad_evaluation_prompts]
dataset = "mlabonne/harmful_behaviors"
split = "test[:100]"
column = "text"
"""
# Scriem noul config
with open(config_path, 'w') as f:
f.write(new_config_content)
print("✅ Configurația OPTIMIZATĂ a fost aplicată cu succes!")
print(f" -> Dataset Good: Open-Orca | Trials: {N_TRIALS} | KL Scale: {KL_SCALE}")
print(f" -> System Prompt Customizat")
except Exception as e:
print(f"❌ Eroare la configurare: {e}")
# ==========================================
# 4. EXECUTIE
# ==========================================
print("\n🚀 4. Pornire Proces...")
hf_token = getpass.getpass("HF Token (Optional - doar pentru modele restricționate, altfel Enter): ")
if hf_token.strip():
from huggingface_hub import login
login(token=hf_token)
print(f"⚡ Se lucrează la modelul: {TARGET_MODEL}")
print("⚠️ INSTRUCȚIUNI FINALE:")
print(" 1. Așteaptă finalizarea procesului (Trials).")
print(" 2. Când te întreabă, alege versiunea dorită (ex: 0).")
print(f" 3. La calea de salvare, copiază linia de mai jos:")
print(f" {save_path_root}/{TARGET_MODEL.split('/')[-1]}")
!heretic {TARGET_MODEL}