📝 试卷组装

🧾 接口说明

根据指定的科目和题型配置,自动生成完整的试卷,并提供Word文档下载。

请求URL POST /api/paper/assemble
请求方法 POST
认证方式 API Key

📥 请求参数

参数名 必填 类型 说明
title string 试卷标题,默认为"随机试卷"
description string 试卷描述
total_points integer 试卷总分,默认为100
duration integer 考试时长(分钟),默认为120
subjects array 科目配置数组
subjects对象结构
参数名 必填 类型 说明
name string 科目名称
question_type string 题型,支持的题型包括:
基础题型:single(单选题), multiple(多选题), judgement(判断题), fill(填空题), short_answer(简答题), calculation(计算题), essay(论述题), coding(编程题)
高考题型:reading_comprehension(阅读理解), material_analysis(材料分析题), cloze_test(完形填空), translation(翻译题), writing(写作题), continuation_writing(读后续写), summary_writing(概要写作), error_correction(改错题), grammar(语法题), vocabulary(词汇题), paragraph_ordering(段落排序题), listening_comprehension(听力理解)
difficulty string 难度等级,可选值:easy, medium, hard
count integer 题目数量
points integer 每题分值,默认为0
keywords string 关键词,用于指定出题范围,多个关键词用逗号分隔
方式B参数说明(当使用方式B时)
参数名 必填 类型 说明
subject string 基础科目名称,所有题型将使用此科目
question_types array 题型配置数组
difficulty string 默认难度等级,如果题型中未指定则使用此值,默认为"medium"
points integer 默认每题分值,如果题型中未指定则使用此值,默认为0
question_types数组元素结构
参数名 必填 类型 说明
typequestion_type string 题型,支持的题型包括:
基础题型:single(单选题), multiple(多选题), judgement(判断题), fill(填空题), short_answer(简答题), calculation(计算题), essay(论述题), coding(编程题)
高考题型:reading_comprehension(阅读理解), material_analysis(材料分析题), cloze_test(完形填空), translation(翻译题), writing(写作题), continuation_writing(读后续写), summary_writing(概要写作), error_correction(改错题), grammar(语法题), vocabulary(词汇题), paragraph_ordering(段落排序题), listening_comprehension(听力理解)
count integer 题目数量
difficulty string 难度等级,如果不指定则使用顶层的 difficulty
points integer 每题分值,如果不指定则使用顶层的 points
请求示例

本接口支持两种传参方式:

方式A:直接指定科目配置(推荐)
{
  "title": "2024年高考数学模拟试卷",
  "description": "高考数学全真模拟",
  "total_points": 150,
  "duration": 120,
  "subjects": [
    {
      "name": "数学",
      "question_type": "single",
      "difficulty": "medium",
      "count": 8,
      "points": 5,
      "keywords": "基础计算,函数"
    },
    {
      "name": "数学",
      "question_type": "fill",
      "difficulty": "medium",
      "count": 4,
      "points": 5,
      "keywords": "代数,几何"
    },
    {
      "name": "数学",
      "question_type": "calculation",
      "difficulty": "hard",
      "count": 6,
      "points": 10,
      "keywords": "复杂计算,应用题"
    }
  ]
}
方式B:指定基础科目和题型列表
{
  "title": "2024年高考数学模拟试卷",
  "description": "高考数学全真模拟",
  "total_points": 150,
  "duration": 120,
  "subject": "数学",
  "difficulty": "medium",
  "points": 5,
  "question_types": [
    {
      "type": "single",
      "count": 8,
      "difficulty": "medium",
      "points": 5
    },
    {
      "type": "fill",
      "count": 4,
      "difficulty": "medium",
      "points": 5
    },
    {
      "type": "calculation",
      "count": 6,
      "difficulty": "hard",
      "points": 10
    }
  ]
}

方式B说明:当使用方式B时,所有题型将使用相同的 `subject` 值。每个题型可以单独指定 `difficulty` 和 `points`,如果不指定则使用顶层的 `difficulty` 和 `points` 作为默认值。

📤 响应参数

参数名 类型 说明
code integer 状态码,1表示成功,0表示失败
message string 状态信息
paper_id string 试卷ID
paper_data object 试卷数据
download_url string 试卷下载链接
paper_data对象结构
参数名 类型 说明
paper_id string 试卷ID
title string 试卷标题
description string 试卷描述
created_at string 创建时间
total_points integer 试卷总分
duration integer 考试时长(分钟)
subjects array 科目数据
questions array 题目列表(扁平化,包含所有科目的题目)
statistics object 统计信息
question对象结构
参数名 类型 说明
question_id string 题目ID,格式为 Q1, Q2, Q3...
subject string 科目名称
type string 题型
difficulty string 难度等级
points integer 分值
content string 题目内容(已去除答案部分)
answer string 答案内容(包含解答过程)
order integer 题目序号(全局排序)
响应示例
{
  "code": 1,
  "message": "试卷组装成功",
  "paper_id": "a1b2c3d4",
  "paper_data": {
    "paper_id": "a1b2c3d4",
    "title": "2024年高考数学模拟试卷",
    "description": "高考数学全真模拟",
    "created_at": "2024-01-15T10:30:00",
    "total_points": 150,
    "duration": 120,
    "subjects": [
      {
        "subject_id": "subject_1",
        "name": "数学",
        "question_type": "single",
        "difficulty": "medium",
        "points_per_question": 5,
        "question_count": 8,
        "questions": [
          {
            "question_id": "Q1",
            "subject": "数学",
            "type": "single",
            "difficulty": "medium",
            "points": 5,
            "content": "已知函数f(x)=x²+2x+1,求f(x)的最小值。",
            "order": 1
          }
        ]
      }
    ],
    "questions": [
      {
        "question_id": "Q1",
        "subject": "数学",
        "type": "single",
        "difficulty": "medium",
        "points": 5,
        "content": "已知函数f(x)=x²+2x+1,求f(x)的最小值。",
        "answer": "正确答案:0\n\n解答过程:\nf(x)=x²+2x+1=(x+1)²\n当x=-1时,f(x)取得最小值0。",
        "order": 1
      }
    ],
    "statistics": {
      "total_questions": 18,
      "questions_by_type": {
        "single": 8,
        "fill": 4,
        "calculation": 6
      },
      "questions_by_difficulty": {
        "medium": 12,
        "hard": 6
      },
      "ai_models_used": ["deepseek-chat"]
    }
  },
  "download_url": "http://your-domain.com/download/paper/paper_a1b2c3d4_20240115_103000.docx"
}

失败响应示例:
{
  "code": 0,
  "message": "未生成任何题目,可能因模型限流或调用失败,请稍后重试或调整参数",
  "paper_id": "a1b2c3d4",
  "paper_data": {
    "paper_id": "a1b2c3d4",
    "title": "2024年高考数学模拟试卷",
    "description": "高考数学全真模拟",
    "created_at": "2024-01-15T10:30:00",
    "total_points": 150,
    "duration": 120,
    "subjects": [],
    "questions": [],
    "statistics": {
      "total_questions": 0,
      "questions_by_type": {},
      "questions_by_difficulty": {},
      "ai_models_used": []
    }
  }
}

⚠️ 错误码

错误码 说明
0 试卷组装失败(可能是未生成任何题目、AI调用失败等)
400 请求参数错误(如未提供科目配置)
401 未提供API密钥或密钥无效
429 请求过于频繁
500 服务器内部错误