知识库问答 本文介绍知识库问答内容。 接口描述 依据知识库与大模型进行对话问答 请求方法 POST 接口要求 无 URI /openapi/v1/rag/talk 请求参数 请求头header参数 参数 是否必填 参数类型 说明 示例 下级对象 ContentType 是 String json格式 application/json Accept 否 String 设置开启接收ServerSent Events (SSE) 格式的流式响应 text/eventstream tenantId 是 String 租户ID 562b89493b1a40e1b97ea05e50dd8170 ctyuneoprequestid 是 String 用户请求 id,由用户构造,用户可以通过 uuid 等方法自行生成唯一字符串,用于日志请求追踪 33dfa732b27b464fb15a21ed6845afd5 eopdate 是 String 请求时间,由用户构造,形如 yyyymmddTHHMMSSZ。 20211221T163014Z host 是 String 终端节点域名,固定字段 kqaglobal.ctapi.ctyun.cn EopAuthorization 是 String 由天翼云官网 accessKey 和 securityKey 经签名后生成,参与签名生成的字段包括天翼云官网 accessKey 、securityKey、平台应用的appkey(非必须),用户请求id(非必须),请求时间,终端节点域名(非必须)以及请求体内容。 请求体body参数 参数 是否必填 参数类型 说明 示例 下级对象 text 是 String 问题的文本内容 infobaseIds 否 Array[String] 通用知识库ID列表 customBaseIds 否 Array[String] 自定义知识库ID列表 modelId 是 String 模型ID contextId 否 String 上一轮会话的ID,需要多轮对话时使用 searchEnable 否 Boolean 是否开启联网搜索 index 否 Boolean 是否输出文档索引引用标签 prompt 否 String 用户自定义输入的prompt 请求代码示例 plaintext Curl X POST " H "ContentType: application/json" H "Accept: text/eventstream" H "ctyuneoprequestid:33dfa732b27b464fb15a21ed6845afd5" H "tenantId:XXX" H "EopAuthorization:XXX" H "eopdate:20211109T104641Z" H "host:kqaglobal.ctapi.ctyun.cn" data '{ "text": "总结下文档内容", "infobaseIds": [123456789, 987654321], "modelId": "d5f09a41d4584715a5d94a4892411c0f", "searchEnable": false, "index": true, "prompt": "请依据文档内容进行回答,不得使用超出文档内容的知识;n 确保您的回答既精确又实用且忠实于原文,同时覆盖所有相关的要点,以满足用户的查询需求;n 要求语句通顺,条理清晰,易于阅读;n 请不要随意发散,尽量以原文档内容输出;n 对于包含多个子问题的问题,请回答每一个子问题,不要遗漏问题; n下面是文档信息:n{chunks}n问题为:{question}n开始回答:n" }' 返回值说明 1.请求成功返回响应参数 参数 参数类型 说明 示例 下级对象 statusCode String 返回状态,返回200表示成功 200 message String 返回Success Success returnObj Object 接口返回结果 returnObj表 returnObj表 参数 参数类型 说明 示例 下级对象 code Int 0表示成功 0 message String 返回success success result Object 对话结果 result表 result表 参数 参数类型 说明 示例 下级对象 input String 对话输入文本 介绍下定积分 output String 对话输出文本 定积分是一种.... contextId String 此轮对话的ID finishState String 会话状态 状态取值:start(开始)/continued(生成中)/stop(正常结束)/interrupt(中断) stop inferSource Array[Object] 拼入模型prompt的参考文档信息。请求体参数index为false时生效 inferSource对象 indexInfo Array[Object] 模型回复的参考引用片段。请求体参数index为true时生效 indexInfo对象 indexInfo表 参数 参数类型 说明 示例 下级对象 indexId int 引用下标 1 subTitle String 子标题 docTitlec String 文档标题 文档.doc docTitle String 来源 Knowledge content String 引用片段内容 fileName String 引用文档名称 文档.doc fileId String 引用文档id 133 inferSource表 参数 参数类型 说明 示例 下级对象 fileName String 检索到的参考文档名称 文档.doc fileId String 检索到的参考文档id 133 fileType String 文档类型 doc contentText String 参考文档的内容 score Float 参考文档和用户输入的相关性分数,取值[01] 0.33 2.请求失败返回响应参数 参数 参数类型 说明 示例 下级对象 statusCode String 错误码,放置API对应的错误码 40001 message String 失败信息 缺少鉴权信息 error String 返回对应的错误码 KQA40001 返回值示例 该接口为SSE接口,返回值为流式返回,返回时ContentType为text/eventstream。 1.请求成功返回值示例(关闭引用开关indexfalse) plaintext data:{ 'statusCode': 200, "error": null, "message": "Success", "returnObj": { "code": 0, "message": "success", "result": { "input": "水泥的国标", "output": " n好的,我现在需要处理用户的问题:“水泥的国标”。首先。。。", "finishState": "stop", "contextId": "2f963a77e58b467ead9223ddf2e4015b", "inferSource": [ { "fileName": "筑府办函xx号附件.wps", "fileId": 32432, "fileType": "doc", "contentText": "xxx", "score": 0.37754068 } ], "indexInfo": [] }, "details": null } } 2.请求成功返回值示例(开启引用开关indextrue) plaintext data:{ "statusCode": 200, "error": null, "message": "Success", "returnObj": { "code": 0, "message": "success", "result": { "input": "水泥的国标", "output": "根据提供的文档内容,水泥的参考标准为GB 16780[[1]]。。。", "finishState": "stop", "contextId": "bcca2bb95b454d41b9b878a24659b3d5", "inferSource": [], "indexInfo": [ { "indexId": 1, "subTitle": "", "docTitle": "筑府办函xx号附件.wps", "from": "Knowledge", "content": "xxx", "fileName": "筑府办函xx号附件.wps", "fileId": 32432 } ] }, "details": null } } 3.请求失败返回值示例 plaintext data:{ "statusCode": "40004", "error": "KQA40004", "message": "接口执行异常" } 状态码 http状态码 描述 200 表示请求成功 错误码说明 错误码 错误信息 错误描述 40013 对话出现异常 无法进行正常交互