|
|
@@ -10183,175 +10183,7 @@ const generateNewOutline = async () => {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// 生成考题
|
|
|
-const generateExam = async () => {
|
|
|
- try {
|
|
|
- // 检查是否有大纲数据
|
|
|
- if (!outlineData.value || outlineData.value.length === 0) {
|
|
|
- ElMessage.warning('请先生成大纲内容')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 设置生成状态
|
|
|
- isGeneratingExam.value = true
|
|
|
- isProcessing.value = true
|
|
|
-
|
|
|
- // 将大纲数据转换为markdown格式
|
|
|
- const markdownContent = convertOutlineToMarkdown(outlineData.value, outlineTitle.value)
|
|
|
-
|
|
|
- // 构建考试生成提示词
|
|
|
- const prompt = `请基于以下安全培训大纲内容生成一份考试试卷:
|
|
|
-
|
|
|
-大纲标题:${outlineTitle.value}
|
|
|
-
|
|
|
-大纲内容:
|
|
|
-${markdownContent}
|
|
|
-
|
|
|
-请生成一份包含以下题型的考试试卷:
|
|
|
-- 单选题:5题,每题5分,共25分
|
|
|
-- 判断题:5题,每题3分,共15分
|
|
|
-- 多选题:5题,每题8分,共40分
|
|
|
-- 简答题:2题,每题10分,共20分
|
|
|
-
|
|
|
-试卷总分:100分
|
|
|
-
|
|
|
-请严格按照以下JSON格式返回试卷内容,不要包含任何其他文字:
|
|
|
-
|
|
|
-{
|
|
|
- "title": "${outlineTitle.value} - 安全培训考试",
|
|
|
- "totalScore": 100,
|
|
|
- "totalQuestions": 17,
|
|
|
- "singleChoice": {
|
|
|
- "scorePerQuestion": 5,
|
|
|
- "totalScore": 25,
|
|
|
- "count": 5,
|
|
|
- "questions": [
|
|
|
- {
|
|
|
- "text": "题目内容",
|
|
|
- "options": [
|
|
|
- {"key": "A", "text": "选项A内容"},
|
|
|
- {"key": "B", "text": "选项B内容"},
|
|
|
- {"key": "C", "text": "选项C内容"},
|
|
|
- {"key": "D", "text": "选项D内容"}
|
|
|
- ],
|
|
|
- "selectedAnswer": "正确答案选项(A/B/C/D)"
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- "judge": {
|
|
|
- "scorePerQuestion": 3,
|
|
|
- "totalScore": 15,
|
|
|
- "count": 5,
|
|
|
- "questions": [
|
|
|
- {
|
|
|
- "text": "题目内容",
|
|
|
- "selectedAnswer": "正确答案(正确/错误)"
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- "multiple": {
|
|
|
- "scorePerQuestion": 8,
|
|
|
- "totalScore": 40,
|
|
|
- "count": 5,
|
|
|
- "questions": [
|
|
|
- {
|
|
|
- "text": "题目内容",
|
|
|
- "options": [
|
|
|
- {"key": "A", "text": "选项A内容"},
|
|
|
- {"key": "B", "text": "选项B内容"},
|
|
|
- {"key": "C", "text": "选项C内容"},
|
|
|
- {"key": "D", "text": "选项D内容"}
|
|
|
- ],
|
|
|
- "selectedAnswers": ["正确答案选项1", "正确答案选项2"]
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- "short": {
|
|
|
- "scorePerQuestion": 10,
|
|
|
- "totalScore": 20,
|
|
|
- "count": 2,
|
|
|
- "questions": [
|
|
|
- {
|
|
|
- "text": "题目内容",
|
|
|
- "outline": {
|
|
|
- "keyFactors": "答题要点、关键因素、示例答案"
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-注意:
|
|
|
-1. 所有题目内容必须基于提供的大纲内容
|
|
|
-2. 题目难度适中,符合安全培训考试要求
|
|
|
-3. 严格按照JSON格式返回,不要有多余字符
|
|
|
-4. 单选题和判断题的选项要合理
|
|
|
-5. 多选题至少要有2个正确答案
|
|
|
-6. 简答题要提供清晰的答题要点
|
|
|
-7. 必须为每道题设置正确答案
|
|
|
-8. 简答题答案字数不超过500字`
|
|
|
-
|
|
|
- console.log('发送给AI的考试生成提示词:', prompt)
|
|
|
-
|
|
|
- // 调用AI接口
|
|
|
- const response = await apis.reProduceSingleQuestion({
|
|
|
-
|
|
|
- message: prompt
|
|
|
-
|
|
|
- })
|
|
|
-
|
|
|
- if (response.statusCode === 200) {
|
|
|
- const aiReply = response.data.reply
|
|
|
- const aiConversationId = response.data.ai_conversation_id
|
|
|
- console.log('AI生成的考试试卷:', aiReply)
|
|
|
- console.log('AI对话ID:', aiConversationId)
|
|
|
-
|
|
|
- // 保存对话ID
|
|
|
- ai_conversation_id.value = aiConversationId
|
|
|
-
|
|
|
- // 解析AI回复并生成试卷
|
|
|
- const generatedExam = parseAIExamResponse(aiReply)
|
|
|
-
|
|
|
- // 直接导出考试文件
|
|
|
- exportExamToFile(generatedExam)
|
|
|
-
|
|
|
- ElMessage.success('考试试卷生成完成!')
|
|
|
-
|
|
|
- } else {
|
|
|
- throw new Error('AI接口调用失败')
|
|
|
- }
|
|
|
-
|
|
|
- } catch (error) {
|
|
|
- console.error('生成考题失败:', error)
|
|
|
- ElMessage.error('生成考题失败,请重试')
|
|
|
- } finally {
|
|
|
- // 重置生成状态
|
|
|
- isGeneratingExam.value = false
|
|
|
- isProcessing.value = false
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// 解析AI考试回复
|
|
|
-const parseAIExamResponse = (aiReply) => {
|
|
|
- try {
|
|
|
- // 尝试提取JSON内容
|
|
|
- const jsonMatch = aiReply.match(/\{[\s\S]*\}/)
|
|
|
- if (jsonMatch) {
|
|
|
- const examData = JSON.parse(jsonMatch[0])
|
|
|
|
|
|
- // 确保所有题目都有正确的初始值
|
|
|
- ensureQuestionInitialValues(examData)
|
|
|
-
|
|
|
- return examData
|
|
|
- } else {
|
|
|
- throw new Error('未找到有效的JSON数据')
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('解析AI回复失败:', error)
|
|
|
- // 返回默认试卷结构
|
|
|
- return generateDefaultExam()
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
// 确保题目初始值正确
|
|
|
const ensureQuestionInitialValues = (examData) => {
|