Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Перевірка доступних моделей у Vertex AI | |
| """ | |
| import os | |
| import base64 | |
| import json | |
| import logging | |
| from dotenv import load_dotenv | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(levelname)s - %(message)s' | |
| ) | |
| logger = logging.getLogger(__name__) | |
| load_dotenv() | |
| def get_available_models(): | |
| """Отримати список доступних моделей""" | |
| try: | |
| from google.oauth2 import service_account | |
| import vertexai | |
| from vertexai.generative_models import GenerativeModel | |
| # Отримати credentials | |
| service_account_b64 = os.getenv('GCP_SERVICE_ACCOUNT_B64') | |
| service_account_json = base64.b64decode(service_account_b64).decode('utf-8') | |
| service_account_dict = json.loads(service_account_json) | |
| credentials = service_account.Credentials.from_service_account_info( | |
| service_account_dict, | |
| scopes=['https://www.googleapis.com/auth/cloud-platform'] | |
| ) | |
| project_id = service_account_dict.get('project_id') | |
| # Ініціалізація Vertex AI | |
| vertexai.init(project=project_id, credentials=credentials) | |
| logger.info("=" * 70) | |
| logger.info("ДОСТУПНІ МОДЕЛІ GEMINI У VERTEX AI") | |
| logger.info("=" * 70) | |
| # Список моделей для перевірки | |
| models_to_check = [ | |
| "gemini-3-flash-preview", | |
| "gemini-3-flash", | |
| "gemini-2.0-flash-preview", | |
| "gemini-2.0-flash", | |
| "gemini-1.5-pro", | |
| "gemini-1.5-flash", | |
| "gemini-pro", | |
| ] | |
| logger.info(f"\nПроект: {project_id}\n") | |
| logger.info("Перевірка доступності моделей:\n") | |
| available_models = [] | |
| for model_name in models_to_check: | |
| try: | |
| model = GenerativeModel(model_name) | |
| response = model.generate_content("test", stream=False) | |
| logger.info(f"✓ {model_name:30} - ДОСТУПНА") | |
| available_models.append(model_name) | |
| except Exception as e: | |
| error_msg = str(e) | |
| if "404" in error_msg or "not found" in error_msg.lower(): | |
| logger.info(f"✗ {model_name:30} - недоступна") | |
| else: | |
| logger.info(f"? {model_name:30} - помилка: {error_msg[:50]}") | |
| logger.info("\n" + "=" * 70) | |
| if available_models: | |
| logger.info(f"ЗНАЙДЕНО {len(available_models)} ДОСТУПНИХ МОДЕЛЕЙ:") | |
| logger.info("=" * 70) | |
| for model in available_models: | |
| logger.info(f" • {model}") | |
| else: | |
| logger.warning("ЖОДНА МОДЕЛЬ НЕ ДОСТУПНА") | |
| logger.info("=" * 70) | |
| return available_models | |
| except Exception as e: | |
| logger.error(f"Помилка: {e}") | |
| return [] | |
| if __name__ == "__main__": | |
| get_available_models() | |