Download scripts/setup_default_openrouter.py from lhc-lab/AI-Colab: direct link, hf CLI and curl.
- Browser
- Download file 3.67 kB
-
https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/2a23844927124fb2ded2eae61fc030d5e95f735f/scripts/setup_default_openrouter.py
- Command line
-
hf download hf://datasets/lhc-lab/AI-Colab@2a23844927124fb2ded2eae61fc030d5e95f735f/scripts/setup_default_openrouter.py
-
curl -L -o setup_default_openrouter.py https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/2a23844927124fb2ded2eae61fc030d5e95f735f/scripts/setup_default_openrouter.py
3.67 kB
| #!/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() | |