Getting started

下面将通过一个简单的例子来说明如何使用金数据 AI 考试 API。

假定你有一份员工学习资料文件(员工学习资料.docx),你希望基于这份资料生成 10 道单选题,那么你可以按照以下步骤操作:

1.通过文件上传接口,上传资料文件,获得 file ID(file-xxxxxx)。

  curl --request POST \
    --url https://v5.jinshuju.net/exam/api/files \
    --header 'Content-Type: multipart/form-data' \
    --header 'Authorization Bearer sk-xxxxxx' \
    --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.通过任务创建接口,创建一个题目生成任务,获得 generation ID(gen-xxxxxx)。

  curl --request POST \
    --url https://v5.jinshuju.net/exam/api/generations \
    --header 'Content-Type: application/json' \
    --header 'Authorization Bearer sk-xxxxxx' \
    --data '{ "file": "file-xxxxxx", "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/generations/gen-xxxxxx \
    --header 'Authorization Bearer sk-xxxxxx'

  {"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/generations/gen-xxxxxx/questions \
    --header 'Authorization Bearer sk-xxxxxx'

  {"object":"list","data":[{"object":"question",...},{"object":"question",...},...]}

至此,你已经成功生成了 10 道单选题,可以将题目导入到你的在线系统中使用了。