File size: 3,669 Bytes
0b2210a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/usr/bin/env python3
"""
Установка моделей OpenRouter по умолчанию для всех отделов
"""
import json
import os
from pathlib import Path
def setup_default_openrouter_models():
"""Устанавливает модель по умолчанию для всех OpenRouter моделей"""
# Путь к конфигу относительно корня AI-colab
config_path = Path(__file__).parent.parent / "config" / "models_config.json"
if not config_path.exists():
print(f"❌ Файл конфигурации не найден: {config_path}")
return False
with open(config_path, "r", encoding="utf-8") as f:
config = json.load(f)
# Модель по умолчанию (проверенная и работающая)
default_model = "meta-llama/llama-3.3-70b-instruct:free"
# Список ключей отделов, которые используют OpenRouter
openrouter_departments = [
"flick", "flock", "frack", "frock",
"freak", "frick", "fruck", "drink"
]
updated = False
active_models = config.get("active_models", {})
# Проверяем существующие модели и добавляем недостающие отделы
for dept in openrouter_departments:
if dept not in active_models:
active_models[dept] = {
"name": dept.capitalize(),
"provider": "openrouter",
"model_id": default_model,
"is_local": False
}
print(f"✅ Добавлен отдел: {dept}")
updated = True
else:
model_config = active_models[dept]
if model_config.get("provider") == "openrouter":
current_model = model_config.get("model_id", "")
if not current_model or ":free" not in current_model:
model_config["model_id"] = default_model
print(f"✅ Установлена модель по умолчанию для {dept}: {default_model}")
updated = True
# Также обновляем список доступных моделей
if "available_openrouter_models" not in config or not isinstance(config["available_openrouter_models"], list):
config["available_openrouter_models"] = []
# Добавляем модель по умолчанию, если её нет
if default_model not in config["available_openrouter_models"]:
config["available_openrouter_models"].append(default_model)
updated = True
# Сохраняем обновленный конфиг
if updated:
config["active_models"] = active_models
with open(config_path, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
print(f"\n🎯 Обновлено моделей OpenRouter.")
print(f"📌 Модель по умолчанию: {default_model}")
# Создаем backup
backup_path = config_path.with_suffix(f".json.backup_{int(os.path.getmtime(config_path))}")
import shutil
shutil.copy2(config_path, backup_path)
print(f"📦 Создан backup: {backup_path}")
else:
print("ℹ️ Изменений не требуется, модели OpenRouter уже настроены.")
return True
if __name__ == "__main__":
print("🔧 Установка моделей OpenRouter по умолчанию...")
setup_default_openrouter_models()
|