test_model_selection.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 测试模型选择功能
  5. """
  6. import sys
  7. import os
  8. # 添加src目录到Python路径
  9. sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
  10. def test_download_model_selection():
  11. """测试下载模型时的选择功能"""
  12. print("=== 测试下载模型选择功能 ===")
  13. # 导入下载模块的函数
  14. sys.path.insert(0, os.path.dirname(__file__))
  15. from download_model import get_user_model_choice
  16. try:
  17. model_key = get_user_model_choice()
  18. print(f"\n选择的模型: {model_key}")
  19. # 获取模型配置信息
  20. from src.config.model_configs import ModelRegistry
  21. registry = ModelRegistry()
  22. model_config = registry.get_model_config(model_key)
  23. print(f"模型名称: {model_config.name}")
  24. print(f"模型ID: {model_config.model_id}")
  25. print(f"架构: {model_config.architecture}")
  26. return True
  27. except Exception as e:
  28. print(f"测试失败: {e}")
  29. return False
  30. def test_app_model_selection():
  31. """测试应用程序中的模型选择功能"""
  32. print("\n=== 测试应用程序模型选择功能 ===")
  33. try:
  34. from src.app import get_user_model_choice
  35. model_key = get_user_model_choice()
  36. print(f"\n选择的模型: {model_key}")
  37. # 设置模型
  38. from src.config.settings import Config
  39. Config.set_current_model(model_key)
  40. print(f"当前模型已设置为: {Config.get_current_model_key()}")
  41. return True
  42. except Exception as e:
  43. print(f"测试失败: {e}")
  44. return False
  45. def main():
  46. """主函数"""
  47. print("模型选择功能测试")
  48. print("=" * 50)
  49. # 测试1: 下载模型选择
  50. success1 = test_download_model_selection()
  51. # 测试2: 应用程序模型选择
  52. success2 = test_app_model_selection()
  53. if success1 and success2:
  54. print("\n✅ 所有测试通过!")
  55. return 0
  56. else:
  57. print("\n❌ 部分测试失败")
  58. return 1
  59. if __name__ == "__main__":
  60. sys.exit(main())