forked from congde/emotional_chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python310.py
More file actions
executable file
·200 lines (162 loc) · 6.28 KB
/
test_python310.py
File metadata and controls
executable file
·200 lines (162 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python3
"""
Python 3.10 功能测试脚本
测试各个模块是否正常工作
"""
import sys
import os
# 添加项目根目录到路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)
def test_imports():
"""测试基础导入"""
print("=" * 60)
print("测试 1: 基础模块导入")
print("=" * 60)
try:
# 测试 LangChain 兼容层
from backend.modules.rag.core.langchain_compat import (
PyPDFLoader, DirectoryLoader, TextLoader,
Chroma, OpenAIEmbeddings, RecursiveCharacterTextSplitter,
Document, IS_NEW_VERSION, LANGCHAIN_VERSION
)
print(f"✅ LangChain 兼容层导入成功")
print(f" - LangChain 版本: {LANGCHAIN_VERSION}")
print(f" - 使用新版本: {IS_NEW_VERSION}")
# 测试核心模块
from backend.modules.llm.core.llm_core import SimpleEmotionalChatEngine
print("✅ LLM 核心模块导入成功")
from backend.modules.llm.core.llm_with_plugins import EmotionalChatEngineWithPlugins
print("✅ 插件引擎模块导入成功")
from backend.modules.rag.services.rag_service import RAGService
print("✅ RAG 服务模块导入成功")
from backend.evaluation_engine import EvaluationEngine
print("✅ 评估引擎模块导入成功")
from backend.emotion_analyzer import EmotionAnalyzer
print("✅ 情感分析模块导入成功")
from backend.vector_store import VectorStore
print("✅ 向量存储模块导入成功")
return True
except Exception as e:
print(f"❌ 导入失败: {e}")
import traceback
traceback.print_exc()
return False
def test_langchain_imports():
"""测试 LangChain 导入"""
print("\n" + "=" * 60)
print("测试 2: LangChain 模块导入")
print("=" * 60)
try:
from langchain_openai import ChatOpenAI
print("✅ langchain_openai.ChatOpenAI 导入成功")
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
print("✅ langchain_core.prompts 导入成功")
from langchain_core.output_parsers import StrOutputParser
print("✅ langchain_core.output_parsers 导入成功")
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage
print("✅ langchain_core.messages 导入成功")
from langchain_core.documents import Document
print("✅ langchain_core.documents 导入成功")
from langchain_community.document_loaders import PyPDFLoader
print("✅ langchain_community.document_loaders 导入成功")
from langchain_community.vectorstores import Chroma
print("✅ langchain_community.vectorstores 导入成功")
return True
except Exception as e:
print(f"❌ LangChain 导入失败: {e}")
import traceback
traceback.print_exc()
return False
def test_config():
"""测试配置加载"""
print("\n" + "=" * 60)
print("测试 3: 配置加载")
print("=" * 60)
try:
from config import Config
print(f"✅ 配置加载成功")
print(f" - MySQL Host: {Config.MYSQL_HOST}")
print(f" - ChromaDB 路径: {Config.CHROMA_PERSIST_DIRECTORY}")
return True
except Exception as e:
print(f"❌ 配置加载失败: {e}")
return False
def test_database():
"""测试数据库连接"""
print("\n" + "=" * 60)
print("测试 4: 数据库连接")
print("=" * 60)
try:
from backend.database import DatabaseManager
db = DatabaseManager()
print("✅ 数据库管理器创建成功")
# 测试连接(不实际连接,只检查导入)
print("✅ 数据库模块导入成功")
return True
except Exception as e:
print(f"⚠️ 数据库测试: {e}")
print(" (可能需要配置数据库连接)")
return True # 不阻止测试继续
def test_vector_store():
"""测试向量存储"""
print("\n" + "=" * 60)
print("测试 5: 向量存储初始化")
print("=" * 60)
try:
from backend.vector_store import VectorStore
# 只测试导入,不实际初始化(避免创建文件)
print("✅ 向量存储模块导入成功")
return True
except Exception as e:
print(f"⚠️ 向量存储测试: {e}")
return True
def test_emotion_analyzer():
"""测试情感分析器"""
print("\n" + "=" * 60)
print("测试 6: 情感分析器")
print("=" * 60)
try:
from backend.emotion_analyzer import EmotionAnalyzer
analyzer = EmotionAnalyzer()
print("✅ 情感分析器初始化成功")
return True
except Exception as e:
print(f"⚠️ 情感分析器测试: {e}")
import traceback
traceback.print_exc()
return True
def main():
"""主测试函数"""
print("\n" + "=" * 60)
print("Python 3.10 功能测试")
print("=" * 60)
print(f"Python 版本: {sys.version}")
print(f"Python 路径: {sys.executable}")
print()
results = []
# 运行测试
results.append(("基础导入", test_imports()))
results.append(("LangChain 导入", test_langchain_imports()))
results.append(("配置加载", test_config()))
results.append(("数据库", test_database()))
results.append(("向量存储", test_vector_store()))
results.append(("情感分析", test_emotion_analyzer()))
# 汇总结果
print("\n" + "=" * 60)
print("测试结果汇总")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✅ 通过" if result else "❌ 失败"
print(f"{name:20s}: {status}")
print(f"\n总计: {passed}/{total} 测试通过")
if passed == total:
print("\n🎉 所有测试通过!Python 3.10 环境配置正确。")
return 0
else:
print("\n⚠️ 部分测试未通过,请检查错误信息。")
return 1
if __name__ == "__main__":
sys.exit(main())