-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
287 lines (242 loc) · 9.92 KB
/
Copy pathdemo.py
File metadata and controls
287 lines (242 loc) · 9.92 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env python3
"""
EduAdmin 主观题自动化评估系统演示脚本
"""
import requests
import json
import time
import sys
# 配置
EVAL_SERVICE_URL = "http://localhost:8000"
GO_BACKEND_URL = "http://localhost:8080"
def print_header(title):
"""打印标题"""
print("\n" + "="*60)
print(f" {title}")
print("="*60)
def print_step(step, description):
"""打印步骤"""
print(f"\n步骤 {step}: {description}")
print("-" * 40)
def check_service_health():
"""检查服务健康状态"""
print_step(1, "检查服务健康状态")
services = [
("eval-service", f"{EVAL_SERVICE_URL}/health"),
("go-backend", f"{GO_BACKEND_URL}/health")
]
for name, url in services:
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
print(f"✅ {name}: 运行正常")
else:
print(f"❌ {name}: 状态异常 ({response.status_code})")
return False
except requests.exceptions.RequestException as e:
print(f"❌ {name}: 连接失败 - {e}")
return False
return True
def demo_evaluation():
"""演示主观题评估"""
print_step(2, "主观题评估演示")
# 测试题目
test_cases = [
{
"question_id": "demo_001",
"reference_answer": "人工智能是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式做出反应的智能机器。",
"student_answer": "人工智能是让机器像人一样思考的技术,包括机器学习和深度学习等方法。",
"language": "zh"
},
{
"question_id": "demo_002",
"reference_answer": "机器学习是人工智能的核心技术之一,通过算法让计算机从数据中学习模式。",
"student_answer": "机器学习就是让计算机自己学习,不需要人工编程。",
"language": "zh"
},
{
"question_id": "demo_003",
"reference_answer": "深度学习是机器学习的一个子领域,使用多层神经网络进行学习。",
"student_answer": "深度学习使用神经网络,是机器学习的重要分支,可以处理复杂的模式识别任务。",
"language": "zh"
}
]
for i, test_case in enumerate(test_cases, 1):
print(f"\n测试案例 {i}:")
print(f"题目ID: {test_case['question_id']}")
print(f"参考答案: {test_case['reference_answer'][:50]}...")
print(f"学生答案: {test_case['student_answer'][:50]}...")
try:
response = requests.post(
f"{EVAL_SERVICE_URL}/api/v1/evaluate",
json=test_case,
timeout=30
)
if response.status_code == 200:
result = response.json()
print(f"✅ 评估成功")
print(f" 最终得分: {result['final_score']:.1f}")
print(f" 语义得分: {result['semantic_score']:.3f}")
print(f" 关键词得分: {result['keyterm_score']:.1f}")
print(f" 连贯性得分: {result['coherence_score']:.3f}")
print(f" 核心关键词: {', '.join(result['hit_keywords']['core'])}")
print(f" 评估总结: {result['explanations']['summary']}")
else:
print(f"❌ 评估失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ 请求失败: {e}")
def demo_feedback():
"""演示反馈机制"""
print_step(3, "反馈机制演示")
feedback_data = {
"question_id": "demo_001",
"user_id": "demo_user_001",
"human_score": 88.0,
"system_score": 85.5
}
print(f"提交反馈:")
print(f" 题目ID: {feedback_data['question_id']}")
print(f" 用户ID: {feedback_data['user_id']}")
print(f" 人工评分: {feedback_data['human_score']}")
print(f" 系统评分: {feedback_data['system_score']}")
try:
response = requests.post(
f"{EVAL_SERVICE_URL}/api/v1/feedback",
json=feedback_data,
timeout=10
)
if response.status_code == 200:
result = response.json()
print(f"✅ 反馈提交成功")
print(f" 消息: {result['message']}")
if 'updated_weights' in result:
print(f" 更新权重: {result['updated_weights']}")
else:
print(f"❌ 反馈提交失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ 请求失败: {e}")
def demo_go_backend():
"""演示Go后端API"""
print_step(4, "Go后端API演示")
# 测试考试提交
exam_data = {
"paper_id": "demo_paper_001",
"user_id": "demo_user_001",
"answers": {
"question_1": "A",
"question_2": "B"
},
"subjective_questions": {
"subjective_1": "人工智能是计算机科学的一个分支,它研究如何让机器模拟人类智能。",
"subjective_2": "机器学习是人工智能的核心技术,通过算法让计算机从数据中学习。"
}
}
print(f"提交考试:")
print(f" 试卷ID: {exam_data['paper_id']}")
print(f" 用户ID: {exam_data['user_id']}")
print(f" 主观题数量: {len(exam_data['subjective_questions'])}")
try:
response = requests.post(
f"{GO_BACKEND_URL}/api/v1/exam/submit",
json=exam_data,
timeout=30
)
if response.status_code == 200:
result = response.json()
print(f"✅ 考试提交成功")
print(f" 消息: {result['message']}")
else:
print(f"❌ 考试提交失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ 请求失败: {e}")
def demo_teacher_api():
"""演示教师端API"""
print_step(5, "教师端API演示")
paper_id = "demo_paper_001"
try:
response = requests.get(
f"{GO_BACKEND_URL}/api/v1/teacher/scores/{paper_id}",
timeout=10
)
if response.status_code == 200:
result = response.json()
print(f"✅ 获取教师评分成功")
print(f" 试卷ID: {result['paper_id']}")
print(f" 评分记录数: {result['total']}")
if result['scores']:
score = result['scores'][0]
print(f" 示例评分:")
print(f" 学生: {score.get('student_name', 'N/A')}")
print(f" 题目: {score['question_id']}")
print(f" 得分: {score['final_score']}")
else:
print(f"❌ 获取教师评分失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ 请求失败: {e}")
def demo_student_api():
"""演示学生端API"""
print_step(6, "学生端API演示")
paper_id = "demo_paper_001"
user_id = "demo_user_001"
try:
response = requests.get(
f"{GO_BACKEND_URL}/api/v1/student/scores/{paper_id}/{user_id}",
timeout=10
)
if response.status_code == 200:
result = response.json()
print(f"✅ 获取学生评分成功")
print(f" 试卷ID: {result['paper_id']}")
print(f" 用户ID: {result['user_id']}")
print(f" 评分记录数: {result['total']}")
if result['scores']:
score = result['scores'][0]
print(f" 示例评分:")
print(f" 题目: {score['question_id']}")
print(f" 得分: {score['final_score']}")
print(f" 总结: {score['explanations']['summary']}")
else:
print(f"❌ 获取学生评分失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ 请求失败: {e}")
def main():
"""主函数"""
print_header("EduAdmin 主观题自动化评估系统演示")
print("本演示将展示系统的主要功能:")
print("1. 服务健康检查")
print("2. 主观题自动评估")
print("3. 反馈机制")
print("4. Go后端API")
print("5. 教师端API")
print("6. 学生端API")
input("\n按回车键开始演示...")
# 检查服务健康状态
if not check_service_health():
print("\n❌ 服务健康检查失败,请确保所有服务都已启动")
print(" 启动命令: ./run.sh 或 docker-compose up -d")
sys.exit(1)
# 演示各个功能
demo_evaluation()
demo_feedback()
demo_go_backend()
demo_teacher_api()
demo_student_api()
print_header("演示完成")
print("🎉 所有功能演示完成!")
print("\n📋 系统访问地址:")
print(f" - 前端管理端: http://localhost:8080")
print(f" - 前端学员端: http://localhost:8081")
print(f" - eval-service API: http://localhost:8000")
print(f" - API 文档: http://localhost:8000/docs")
print("\n📖 更多信息请查看文档:")
print(" - README.md - 项目概述")
print(" - docs/API.md - API文档")
print(" - docs/ALGORITHM.md - 算法详解")
print(" - docs/DEPLOYMENT.md - 部署指南")
if __name__ == "__main__":
main()