#!/usr/bin/env python3 """ 测试 Vertex AI 配置和连接 """ import os import sys from config.doppler_config import get_google_genai_config def test_doppler_config(): """测试 Doppler 配置""" print("🔍 测试 Doppler 配置...") try: config = get_google_genai_config() print("✅ 成功读取 Google GenAI 配置") print(f" - API Key: {'已配置' if config.get('api_key') else '未配置'}") print(f" - Use Vertex AI: {config.get('use_vertex_ai', '未设置')}") print(f" - Project ID: {config.get('project_id', '未设置')}") print(f" - Location: {config.get('location', '未设置')}") print(f" - Memory Bank Enabled: {config.get('memory_bank_enabled', '未设置')}") return config except Exception as e: print(f"❌ 读取 Google GenAI 配置失败: {e}") return None def test_environment_variables(): """测试环境变量""" print("\n🔍 测试环境变量...") adc_path = os.path.expanduser("~/.config/gcloud/application_default_credentials.json") if os.path.exists(adc_path): print("✅ 找到 Application Default Credentials 文件") else: print("❌ 未找到 Application Default Credentials 文件") google_env_vars = [var for var in os.environ if var.startswith('GOOGLE_')] if google_env_vars: print("✅ 找到以下 Google 环境变量:") for var in google_env_vars: # 不显示敏感信息 if 'KEY' in var or 'SECRET' in var or 'TOKEN' in var: print(f" - {var}: {'已设置' if os.environ.get(var) else '未设置'}") else: print(f" - {var}: {os.environ.get(var, '未设置')}") else: print("⚠️ 未找到 Google 环境变量") def main(): """主函数""" print("🧪 Vertex AI 配置测试\n") # 测试 Doppler 配置 config = test_doppler_config() # 测试环境变量 test_environment_variables() # 检查是否满足基本要求 print("\n📋 配置检查摘要:") if config: project_id = config.get('project_id') api_key = config.get('api_key') if project_id: print("✅ Google Cloud Project ID 已配置") else: print("❌ 未配置 Google Cloud Project ID") if api_key: print("✅ Google API Key 已配置") else: print("❌ 未配置 Google API Key") # 检查是否启用 Vertex AI use_vertex = config.get('use_vertex_ai', '').upper() if use_vertex == 'TRUE': print("✅ Vertex AI 已启用") else: print("❌ Vertex AI 未启用 (请检查 GOOGLE_GENAI_USE_VERTEXAI 环境变量)") # 检查是否启用 Memory Bank memory_bank_enabled = config.get('memory_bank_enabled', '').upper() if memory_bank_enabled == 'TRUE': print("✅ Memory Bank 已启用") else: print("❌ Memory Bank 未启用 (请检查 VERTEX_MEMORY_BANK_ENABLED 环境变量)") else: print("❌ 无法读取配置,请检查 Doppler 配置") if __name__ == "__main__": main()