1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import requests
- import json
- import time
- # 测试生成题目并检查difficulty字段
- def test_difficulty_generation():
- base_url = "http://localhost:8080"
-
- print("=== 测试题目生成和difficulty字段 ===")
-
- # 1. 创建一个新目标
- create_goal_data = {
- "userId": 1,
- "subject": "数学",
- "goalType": "选择",
- "goalContent": "代数练习",
- "difficulty": "中等",
- "totalQuantity": 10,
- "estimatedTime": 60,
- "startTime": "2024-01-15T10:00:00"
- }
-
- try:
- print("\n1. 创建新目标...")
- response = requests.post(f"{base_url}/api/goals", json=create_goal_data)
- print(f"创建目标响应状态: {response.status_code}")
-
- if response.status_code == 200:
- goal_data = response.json()
- print(f"创建目标成功: {goal_data}")
-
- if 'data' in goal_data and 'goalId' in goal_data['data']:
- goal_id = goal_data['data']['goalId']
- print(f"目标ID: {goal_id}")
-
- # 2. 调用生成题目API
- print(f"\n2. 为目标 {goal_id} 生成题目...")
- generate_data = {
- "goalId": goal_id,
- "subject": "数学",
- "contentType": "选择题",
- "difficulty": "中等",
- "questionCount": 3,
- "knowledgePoint": "代数",
- "goalContent": "代数练习"
- }
- generate_response = requests.post(f"{base_url}/api/ai/generate-questions", json=generate_data)
- print(f"生成题目响应状态: {generate_response.status_code}")
-
- if generate_response.status_code == 200:
- generate_data = generate_response.json()
- print(f"生成题目成功: {generate_data}")
-
- # 等待一下让数据库操作完成
- time.sleep(2)
-
- # 3. 检查生成的题目详情
- print(f"\n3. 检查生成的题目详情...")
- details_response = requests.get(f"{base_url}/api/goal-details/goal/{goal_id}")
- print(f"获取题目详情响应状态: {details_response.status_code}")
-
- if details_response.status_code == 200:
- details_data = details_response.json()
- print(f"题目详情: {json.dumps(details_data, indent=2, ensure_ascii=False)}")
-
- # 检查difficulty字段
- if 'data' in details_data and isinstance(details_data['data'], list):
- questions = details_data['data']
- print(f"\n4. 检查difficulty字段:")
- print(f"共找到 {len(questions)} 道题目")
-
- for i, question in enumerate(questions):
- difficulty = question.get('difficulty', 'NULL')
- print(f"题目 {i+1}: difficulty = {difficulty}")
-
- if difficulty is None or difficulty == 'NULL':
- print(f"❌ 题目 {i+1} 的difficulty字段为空!")
- else:
- print(f"✅ 题目 {i+1} 的difficulty字段正常: {difficulty}")
- else:
- print("❌ 未找到题目数据")
- else:
- print(f"❌ 获取题目详情失败: {details_response.text}")
- else:
- print(f"❌ 生成题目失败: {generate_response.text}")
- else:
- print("❌ 创建目标响应中未找到目标ID")
- else:
- print(f"❌ 创建目标失败: {response.text}")
-
- except Exception as e:
- print(f"❌ 测试过程中发生错误: {e}")
- if __name__ == "__main__":
- test_difficulty_generation()
|