假定你有一份文件 员工学习资料.docx,希望基于这份资料生成 10 道单选题,可以按照以下步骤操作:
1.通过 文件上传接口,上传资料文件,获得 file ID。
curl --request POST \
--url https://v5.jinshuju.net/exam/api/files \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization Bearer $ACCESS_TOKEN' \
--form 'file=@/path/to/file/员工学习资料.docx'
{"id":"file-xxxxxx","object":"file","bytes":2045137,"created_at":"2024-11-15T18:11:47.765+08:00","filename":"员工学习资料.docx"}
2.通过 任务创建接口,创建一个题目生成任务,获得 job ID。
curl --request POST \
--url https://v5.jinshuju.net/exam/api/generation/jobs \
--header 'Content-Type: application/json' \
--header 'Authorization Bearer $ACCESS_TOKEN' \
--data '{ "file": $FILE_ID, "creation_type": "knowledge_base", "question_rules": [{ "type": "single_choice", "count": 10 }] }'
{"id":"gen-xxxxxx","object":"generation","created_at":"2024-11-15T18:11:54.617+08:00","finished_at":null,"status":"generating"}
3.通过 状态查询接口,轮询任务状态,等待状态变更为 succeeded
。
curl --request GET \
--url https://v5.jinshuju.net/exam/api/generation/jobs/$JOB_ID/status \
--header 'Authorization Bearer $ACCESS_TOKEN'
{"id":"gen-xxxxxx","object":"generation","created_at":"2024-11-15T18:11:54.617+08:00","finished_at":null,"status":"generating"}
// 继续轮询,直到
{"id":"gen-xxxxxx","object":"generation","created_at":"2024-11-15T18:11:54.617+08:00","finished_at":"2024-11-15T18:12:54.617+08:00","status":"succeeded"}
4.通过 题目查询接口,获取生成的题目。
curl --request GET \
--url https://v5.jinshuju.net/exam/api/generation/jobs/$JOB_ID/questions \
--header 'Authorization Bearer $ACCESS_TOKEN'
{"object":"list","data":[{"object":"question",...},{"object":"question",...},...]}
至此,便已成功生成了 10 道单选题,可以将题目导入到你的在线系统中使用。