#!/usr/bin/env python3 """ 验证模型供应商插件安装状态 使用方法: cd dify-main/api python check_plugins.py """ import sys import os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def main(): from app import create_app app = create_app() with app.app_context(): from extensions.ext_database import db from models.account import Tenant from core.plugin.impl.plugin import PluginInstaller # 获取 tenant_id tenant = db.session.query(Tenant).first() if not tenant: print("错误: 数据库中没有找到租户信息") sys.exit(1) tenant_id = tenant.id print(f"租户 ID: {tenant_id}\n") # 获取已安装的插件 installer = PluginInstaller() try: installed = installer.list_plugins(tenant_id) except Exception as e: print(f"获取插件列表失败: {e}") print("\n请检查 Plugin Daemon 是否运行:") print(" curl http://127.0.0.1:5002/health") sys.exit(1) # 分类显示 model_plugins = [] other_plugins = [] for plugin in installed: if hasattr(plugin, 'plugin_type') and plugin.plugin_type == 'model': model_plugins.append(plugin) else: other_plugins.append(plugin) print(f"已安装 {len(installed)} 个插件:") print(f" - 模型供应商: {len(model_plugins)} 个") print(f" - 其他插件: {len(other_plugins)} 个") if model_plugins: print("\n模型供应商插件:") for p in sorted(model_plugins, key=lambda x: x.plugin_id): print(f" ✓ {p.plugin_id}") else: print("\n⚠ 没有安装任何模型供应商插件!") print(" 请运行: python install_model_plugins.py") # 检查 API 返回的供应商列表 print("\n" + "-" * 40) print("检查 API 返回的供应商列表...") from core.provider_manager import ProviderManager from core.plugin.impl.model_runtime import PluginModelRuntime from core.plugin.impl.model import PluginModelClient from core.plugin.plugin_service import PluginService model_runtime = PluginModelRuntime( tenant_id=tenant_id, user_id=None, client=PluginModelClient(), plugin_service=PluginService, ) provider_manager = ProviderManager(model_runtime=model_runtime) configurations = provider_manager.get_configurations(tenant_id) provider_count = len(list(configurations)) print(f"\nAPI 返回 {provider_count} 个模型供应商:") for config in configurations: print(f" ✓ {config.provider}") if __name__ == "__main__": main()