基础地址:
http://localhost:22001(开发环境)
所有 API 路径前缀:/apiv1
认证方式:Authorization: Bearer <token>
| 变量名 | 示例值 | 说明 |
|---|---|---|
base_url |
http://localhost:22001 |
服务基础地址 |
token |
eyJhbGc... |
登录后自动保存 |
user_id |
1 |
登录后自动保存 |
conversation_id |
0 |
对话ID,动态更新 |
ai_message_id |
0 |
AI消息ID,动态更新 |
recognition_record_id |
0 |
识别记录ID,动态更新 |
const url = pm.request.url.toString();
if (!url.includes('/auth/local_login')) {
const token = pm.environment.get("token");
if (token) {
pm.request.headers.add({ key: 'Authorization', value: 'Bearer ' + token });
}
}
pm.test("HTTP 200", () => pm.response.to.have.status(200));
pm.test("响应有 statusCode", () => {
pm.expect(pm.response.json()).to.have.property('statusCode');
});
if (pm.response.json().statusCode === 401) {
pm.environment.unset("token");
console.warn("Token 已过期,请重新登录");
}
POST /apiv1/auth/local_login请求体:
{
"username": "admin",
"password": "password123"
}
Tests 脚本:
const data = pm.response.json();
if (data.statusCode === 200 && data.token) {
pm.environment.set("token", data.token);
pm.environment.set("user_id", data.userInfo.id);
}
pm.test("登录成功并获取Token", () => {
pm.expect(data.statusCode).to.eql(200);
pm.expect(data.token).to.be.a('string').and.not.empty;
});
预期响应:
{
"statusCode": 200,
"msg": "登录成功",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"userInfo": { "id": 1, "username": "admin", "role": "admin" }
}
POST /apiv1/send_deepseek_message请求体:
{
"message": "如何做好施工现场安全管理?",
"ai_conversation_id": 0,
"business_type": 0,
"exam_name": "",
"ai_message_id": 0
}
business_type 说明:
| 值 | 含义 |
|---|---|
| 0 | 通用对话 |
| 1 | 安全培训 |
| 2 | AI 写作 |
| 3 | 考试工坊 |
Tests 脚本:
const data = pm.response.json();
if (data.data && data.data.ai_conversation_id) {
pm.environment.set("conversation_id", data.data.ai_conversation_id);
pm.environment.set("ai_message_id", data.data.ai_message_id);
}
pm.test("消息发送成功", () => pm.expect(data.statusCode).to.eql(200));
GET /apiv1/get_history_recordai_conversation_id=0&business_type=0ai_conversation_id=0 返回对话列表;传具体 ID 返回该对话的消息详情POST /apiv1/delete_conversation请求体:
{
"ai_conversation_id": 456
}
POST /apiv1/delete_history_record请求体:
{
"ai_conversation_id": 123
}
POST /apiv1/delete_recognition_record请求体:
{
"recognition_id": 123
}
POST /apiv1/guess_you_want请求体:
{
"message": "安全帽",
"ai_message_id": 456,
"business_type": 0
}
GET /apiv1/get_user_recommend_questionuser_message=安全帽GET /apiv1/get_file_linkfileName=建筑施工安全检查标准.pdf(注意大写 N)POST /apiv1/save_ppt_outline请求体:
{
"ai_conversation_id": 123,
"ppt_outline": "{\"title\":\"安全培训PPT\",\"slides\":[]}",
"ppt_content": "<完整PPT内容字符串>"
}
POST /apiv1/save_edit_document请求体:
{
"ai_conversation_id": 123,
"content": "编辑后的文档内容..."
}
GET /apiv1/online_searchkeywords=建筑施工安全规范 2026(注意是 keywords 复数)POST /apiv1/save_online_search_resultid 为 AI 消息 ID,search_source 为联网搜索结果内容请求体:
{
"id": 456,
"ai_conversation_id": 123,
"search_source": "[{\"title\":\"...\",\"url\":\"...\",\"content\":\"...\"}]"
}
POST /apiv1/intent_recognition请求体:
{
"message": "帮我写一份安全生产月活动方案",
"ai_conversation_id": 0,
"business_type": 0
}
预期响应(非知识库查询,直接返回答案):
{
"statusCode": 200,
"data": {
"intent_result": { "intent": "faq", "confidence": 0.9 },
"direct_answer": "安全生产月活动方案包括...",
"ai_conversation_id": 123,
"ai_message_id": 456,
"is_online_search": 0
}
}
预期响应(知识库查询,需前端继续调用 RAG):
{
"statusCode": 200,
"data": {
"intent_result": { "intent": "query_knowledge_base", "search_queries": ["高处作业安全规范"] },
"is_online_search": 1
}
}
GET /apiv1/get_chromadb_documentmessage=高处作业安全规范POST /apiv1/re_produce_single_question请求体:
{
"message": "请重新生成一道关于高处作业安全的单选题"
}
⚠️ Postman 对 SSE 流式响应支持有限,推荐使用 curl 或浏览器测试页面。
POST /apiv1/stream/chathttp://localhost:22001/stream-testcurl 测试命令:
curl -X POST "http://localhost:22001/apiv1/stream/chat" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message":"如何做好施工现场安全管理?","ai_conversation_id":0,"business_type":0}' \
--no-buffer
响应格式(SSE):
data: {"content":"施工现场"}
data: {"content":"安全管理"}
data: [DONE]
POST /apiv1/stream/chat-with-dbhttp://localhost:22001/stream-chat-with-db-testcurl 测试命令:
curl -X POST "http://localhost:22001/apiv1/stream/chat-with-db" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message":"施工安全要点","ai_conversation_id":0,"business_type":0}' \
--no-buffer
GET /apiv1/recommend_questionlimit=5(可选,默认 5)GET /apiv1/get_hot_questionquestion_type=0(0=AI问答,1=安全培训)GET /apiv1/get_function_cardfunction_type=0(0=AI问答,1=安全培训)POST /apiv1/submit_feedback请求体:
{
"content": "建议增加语音输入功能"
}
POST /apiv1/like_and_dislikeuser_feedback 为整数,1=点赞,-1=踩,0=取消请求体:
{
"id": 456,
"user_feedback": 1
}
GET /apiv1/get_policy_filepage=1&pageSize=10&search=安全&policy_type=0policy_type=0 表示全部类型GET /apiv1/download_filepdf_oss_download_link=<OSS文件URL>&file_name=建筑施工安全检查标准.pdfPOST /apiv1/policy_file_countaction_type 为整数,1=查看,2=下载请求体:
{
"policy_file_id": 1,
"action_type": 1
}
GET /apiv1/get_user_data_idaccount_id 查询⚠️ 考试工坊接口的具体请求体字段需以实际 controllers/exam.go 为准,以下为参考示例。
POST /apiv1/exam/build_prompt请求体:
{
"mode": "ai",
"client": "pc",
"projectType": "工程",
"examTitle": "施工安全员考试",
"totalScore": 100,
"questionTypes": [
{
"name": "单选题",
"romanNumeral": "一",
"questionCount": 10,
"scorePerQuestion": 2
}
],
"pptContent": ""
}
POST /apiv1/exam/build_single_prompt请求体:
{
"client": "pc",
"sectionType": "single",
"questionIndex": 0,
"projectType": "工程",
"questionType": "单选题",
"scorePerQuestion": 2,
"currentQuestion": {}
}
POST /apiv1/re_modify_question请求体:
{
"ai_conversation_id": 123,
"content": "修改后的题目内容..."
}
POST /apiv1/hazard请求体:
{
"scene_name": "隧道",
"image": "https://oss.example.com/images/site.jpg",
"date": "2026-04-07"
}
Tests 脚本:
const data = pm.response.json();
if (data.data && data.data.recognition_record_id) {
pm.environment.set("recognition_record_id", data.data.recognition_record_id);
}
pm.test("识别成功", () => pm.expect(data.statusCode).to.eql(200));
POST /apiv1/save_step请求体:
{
"ai_conversation_id": 123,
"step": 2,
"ppt_json_url": "https://oss.example.com/ppt.json",
"cover_image": "https://oss.example.com/cover.jpg",
"ppt_json_content": "{...}"
}
GET /apiv1/get_history_recognition_recordGET /apiv1/get_recognition_record_detailrecognition_record_id=123GET /apiv1/get_third_scene_example_imagethird_scene_name=未系安全带POST /apiv1/submit_evaluation请求体:
{
"id": 123,
"scene_match": 1,
"tip_accuracy": 1,
"effect_evaluation": 1,
"user_remark": "识别准确"
}
评分字段说明:
| 字段 | 0 | 1 | 2 |
|---|---|---|---|
| scene_match | 未评价 | 匹配 | 不匹配 |
| tip_accuracy | 未评价 | 准确 | 不准确 |
| effect_evaluation | 未评价 | 满意 | 不满意 |
GET /apiv1/get_latest_recognition_recordPOST /apiv1/oss/shudao/upload_imagemultipart/form-dataPostman Body 设置:
form-datafile,Type: File,Value: 选择本地图片Tests 脚本:
const data = pm.response.json();
if (data.data && data.data.url) {
pm.environment.set("image_url", data.data.url);
}
pm.test("图片上传成功", () => pm.expect(data.statusCode).to.eql(200));
POST /apiv1/oss/shudao/upload_json请求体:
{
"content": {
"title": "安全培训PPT",
"slides": [
{ "title": "第一章:安全生产基础", "content": "..." }
]
}
}
POST /apiv1/oss/upload请求体:
{
"file_name": "example.jpg",
"file_type": "image/jpeg"
}
GET /apiv1/oss/parseurl=https://oss.example.com/images/example.jpg直接返回文件内容(图片/PDF),用于解决跨域访问问题。
GET /apiv1/knowledge/files/advanced-searchquery=高处作业安全规范&top_k=5POST /apiv1/tracking/record请求体:
{
"api_path": "/apiv1/send_deepseek_message",
"method": "POST",
"extra_data": "附加数据"
}
GET /apiv1/tracking/recordspage=1&pageSize=20&start_date=2026-04-01&end_date=2026-04-07POST /apiv1/tracking/api_mapping请求体:
{
"api_path": "/apiv1/send_deepseek_message",
"api_name": "发送AI消息",
"api_desc": "用于发送 AI 会话的消息"
}
GET /apiv1/tracking/api_mappingsGET /apiv1/points/balanceTests 脚本:
const data = pm.response.json();
pm.test("积分余额查询成功", () => {
pm.expect(data.statusCode).to.eql(200);
pm.expect(data.data.points).to.be.a('number').and.at.least(0);
});
pm.environment.set("current_points", data.data.points);
POST /apiv1/points/consume请求体:
{
"file_name": "建筑施工安全检查标准.pdf",
"file_url": "https://oss.example.com/files/standard.pdf"
}
Tests 脚本:
const data = pm.response.json();
if (data.statusCode === 200) {
pm.test("积分消费成功", () => {
pm.expect(data.data.points_consumed).to.eql(10);
const before = parseInt(pm.environment.get("current_points"));
pm.expect(data.data.new_balance).to.eql(before - 10);
});
} else if (data.statusCode === 400) {
pm.test("积分不足提示正确", () => pm.expect(data.msg).to.include("积分不足"));
}
GET /apiv1/points/historypage=1&pageSize=101. POST /apiv1/auth/local_login → 获取 Token
2. GET /apiv1/recommend_question → 查看推荐问题(limit=5)
3. GET /apiv1/get_hot_question → 查看热点问题(question_type=0)
4. GET /apiv1/get_function_card → 查看功能卡片(function_type=0)
5. POST /apiv1/send_deepseek_message → 发送消息(保存 conversation_id, ai_message_id)
6. POST /apiv1/like_and_dislike → 对回复点赞(id=ai_message_id, user_feedback=1)
7. GET /apiv1/get_history_record → 查看历史记录(business_type=0)
8. POST /apiv1/delete_history_record → 删除整个对话(ai_conversation_id=xxx)
1. POST /apiv1/auth/local_login → 获取 Token
2. POST /apiv1/oss/shudao/upload_image → 上传图片(保存 image_url)
3. POST /apiv1/hazard → 提交识别(保存 recognition_record_id)
4. GET /apiv1/get_history_recognition_record → 查看历史
5. GET /apiv1/get_recognition_record_detail → 查看详情
6. GET /apiv1/get_third_scene_example_image → 查看示例图
7. GET /apiv1/get_latest_recognition_record → 检查是否已点评
8. POST /apiv1/submit_evaluation → 提交点评
9. POST /apiv1/delete_recognition_record → 删除记录
1. POST /apiv1/auth/local_login → 获取 Token
2. GET /apiv1/points/balance → 记录初始积分(需 ≥ 10)
3. GET /apiv1/get_policy_file → 查看政策文件列表
4. POST /apiv1/points/consume → 消费积分下载
5. GET /apiv1/points/balance → 验证积分已扣减 10
6. GET /apiv1/points/history → 查看消费记录
# 浏览器打开 http://localhost:22001/stream-test
# 或使用 curl:
curl -X POST "http://localhost:22001/apiv1/stream/chat" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message":"施工安全要点","ai_conversation_id":0,"business_type":0}' \
--no-buffer
| 状态码 | 含义 | 处理方式 |
|---|---|---|
| 200 | 成功 | 正常处理 |
| 400 | 参数错误 / 积分不足 | 检查请求参数 |
| 401 | Token 无效或过期 | 重新调用登录接口 |
| 403 | 权限不足 | 检查用户角色 |
| 500 | 服务器内部错误 | 查看服务器日志 |
Token 过期响应示例:
{ "statusCode": 401, "msg": "获取用户信息失败: token已过期" }
积分不足响应示例:
{
"statusCode": 400,
"msg": "积分不足,下载需要10积分",
"data": { "current_points": 5, "required_points": 10 }
}
| 模块 | 方法 | 路径 | 关键参数说明 |
|---|---|---|---|
| 认证 | POST | /apiv1/auth/local_login |
username, password |
| 对话 | POST | /apiv1/send_deepseek_message |
message, ai_conversation_id, business_type |
| 对话 | GET | /apiv1/get_history_record |
ai_conversation_id, business_type |
| 对话 | POST | /apiv1/delete_conversation |
ai_message_id(AI回复消息ID) |
| 对话 | POST | /apiv1/delete_history_record |
ai_conversation_id |
| 对话 | POST | /apiv1/guess_you_want |
message, ai_message_id, business_type |
| 对话 | GET | /apiv1/get_user_recommend_question |
user_message |
| 对话 | GET | /apiv1/get_file_link |
fileName(大写N) |
| 对话 | POST | /apiv1/save_ppt_outline |
ai_conversation_id, ppt_outline, ppt_content |
| 对话 | POST | /apiv1/save_edit_document |
ai_conversation_id, content |
| 对话 | GET | /apiv1/online_search |
keywords(复数) |
| 对话 | POST | /apiv1/save_online_search_result |
id(ai_message_id), ai_conversation_id, search_source |
| 对话 | POST | /apiv1/intent_recognition |
message, ai_conversation_id, business_type |
| 对话 | GET | /apiv1/get_chromadb_document |
message |
| 对话 | POST | /apiv1/re_produce_single_question |
message |
| 流式 | POST | /apiv1/stream/chat |
message, ai_conversation_id, business_type |
| 流式 | POST | /apiv1/stream/chat-with-db |
message, ai_conversation_id, business_type |
| 通用 | GET | /apiv1/recommend_question |
limit(默认5) |
| 通用 | GET | /apiv1/get_hot_question |
question_type(0/1) |
| 通用 | GET | /apiv1/get_function_card |
function_type(0/1) |
| 通用 | POST | /apiv1/submit_feedback |
content |
| 通用 | POST | /apiv1/like_and_dislike |
id, user_feedback(整数1/-1/0) |
| 通用 | GET | /apiv1/get_policy_file |
page, pageSize, search, policy_type |
| 通用 | GET | /apiv1/download_file |
pdf_oss_download_link, file_name |
| 通用 | POST | /apiv1/policy_file_count |
policy_file_id, action_type(1=查看/2=下载) |
| 通用 | GET | /apiv1/get_user_data_id |
无参数,从Token获取 |
| 考试 | POST | /apiv1/exam/build_prompt |
mode, client, projectType, examTitle, totalScore, questionTypes |
| 考试 | POST | /apiv1/exam/build_single_prompt |
client, sectionType, questionIndex, projectType, questionType, scorePerQuestion, currentQuestion |
| 考试 | POST | /apiv1/re_modify_question |
ai_conversation_id, content |
| 隐患 | POST | /apiv1/hazard |
scene_name, image, date |
| 隐患 | POST | /apiv1/save_step |
ai_conversation_id, step, ppt_json_url, cover_image, ppt_json_content |
| 隐患 | GET | /apiv1/get_history_recognition_record |
无参数 |
| 隐患 | GET | /apiv1/get_recognition_record_detail |
recognition_record_id |
| 隐患 | GET | /apiv1/get_third_scene_example_image |
third_scene_name |
| 隐患 | POST | /apiv1/submit_evaluation |
id, scene_match, tip_accuracy, effect_evaluation |
| 隐患 | GET | /apiv1/get_latest_recognition_record |
无参数 |
| 隐患 | POST | /apiv1/delete_recognition_record |
recognition_record_id |
| OSS | POST | /apiv1/oss/upload |
file_name, file_type |
| OSS | POST | /apiv1/oss/shudao/upload_image |
multipart file |
| OSS | POST | /apiv1/oss/shudao/upload_json |
content |
| OSS | GET | /apiv1/oss/parse |
url(无需认证) |
| 知识库 | GET | /apiv1/knowledge/files/advanced-search |
query, top_k |
| 埋点 | POST | /apiv1/tracking/record |
api_path, method, extra_data |
| 埋点 | GET | /apiv1/tracking/records |
page, pageSize, start_date, end_date |
| 埋点 | POST | /apiv1/tracking/api_mapping |
api_path, api_name, api_desc |
| 埋点 | GET | /apiv1/tracking/api_mappings |
无参数 |
| 积分 | GET | /apiv1/points/balance |
无参数,从Token获取 |
| 积分 | POST | /apiv1/points/consume |
file_name, file_url |
| 积分 | GET | /apiv1/points/history |
page, pageSize |
文档版本:v1.1 | 最后更新:2026-04-07 | 服务端口:22001