test_config_refactor.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. """
  3. 测试配置重构是否成功
  4. """
  5. def test_config_refactor():
  6. """测试配置重构"""
  7. print("=== 配置重构测试 ===")
  8. try:
  9. import app_config
  10. print("✓ app_config 导入成功")
  11. except ImportError as e:
  12. print(f"✗ app_config 导入失败: {e}")
  13. return False
  14. # 测试新配置是否存在
  15. new_configs = [
  16. 'API_DEEPSEEK_CONFIG',
  17. 'API_QWEN_CONFIG',
  18. 'OLLAMA_EMBEDDING_CONFIG',
  19. 'API_LLM_MODEL',
  20. 'VECTOR_DB_TYPE'
  21. ]
  22. print("\n--- 新配置检查 ---")
  23. for config_name in new_configs:
  24. if hasattr(app_config, config_name):
  25. print(f"✓ {config_name} 存在")
  26. else:
  27. print(f"✗ {config_name} 不存在")
  28. return False
  29. # 测试旧配置是否已删除
  30. old_configs = [
  31. 'DEEPSEEK_CONFIG',
  32. 'QWEN_CONFIG',
  33. 'EMBEDDING_OLLAMA_CONFIG',
  34. 'LLM_MODEL_NAME',
  35. 'VECTOR_DB_NAME'
  36. ]
  37. print("\n--- 旧配置检查 ---")
  38. for config_name in old_configs:
  39. if hasattr(app_config, config_name):
  40. print(f"✗ {config_name} 仍然存在(应该已删除)")
  41. return False
  42. else:
  43. print(f"✓ {config_name} 已删除")
  44. # 测试utils.py中的函数
  45. print("\n--- Utils函数测试 ---")
  46. try:
  47. from common.utils import get_current_llm_config, get_current_embedding_config
  48. # 测试LLM配置
  49. llm_config = get_current_llm_config()
  50. print(f"✓ get_current_llm_config() 成功,返回类型: {type(llm_config)}")
  51. # 测试Embedding配置
  52. embedding_config = get_current_embedding_config()
  53. print(f"✓ get_current_embedding_config() 成功,返回类型: {type(embedding_config)}")
  54. except Exception as e:
  55. print(f"✗ Utils函数测试失败: {e}")
  56. return False
  57. # 测试配置内容
  58. print("\n--- 配置内容验证 ---")
  59. try:
  60. # 验证API_QWEN_CONFIG
  61. qwen_config = app_config.API_QWEN_CONFIG
  62. if 'model' in qwen_config and 'api_key' in qwen_config:
  63. print("✓ API_QWEN_CONFIG 结构正确")
  64. else:
  65. print("✗ API_QWEN_CONFIG 结构不正确")
  66. return False
  67. # 验证API_DEEPSEEK_CONFIG
  68. deepseek_config = app_config.API_DEEPSEEK_CONFIG
  69. if 'model' in deepseek_config and 'api_key' in deepseek_config:
  70. print("✓ API_DEEPSEEK_CONFIG 结构正确")
  71. else:
  72. print("✗ API_DEEPSEEK_CONFIG 结构不正确")
  73. return False
  74. # 验证OLLAMA_EMBEDDING_CONFIG
  75. ollama_embedding_config = app_config.OLLAMA_EMBEDDING_CONFIG
  76. if 'model_name' in ollama_embedding_config and 'base_url' in ollama_embedding_config:
  77. print("✓ OLLAMA_EMBEDDING_CONFIG 结构正确")
  78. else:
  79. print("✗ OLLAMA_EMBEDDING_CONFIG 结构不正确")
  80. return False
  81. except Exception as e:
  82. print(f"✗ 配置内容验证失败: {e}")
  83. return False
  84. print("\n=== 配置重构测试完成 ===")
  85. print("✓ 所有测试通过!配置重构成功!")
  86. return True
  87. if __name__ == "__main__":
  88. success = test_config_refactor()
  89. if not success:
  90. exit(1)