单轮问答(即将下线)
功能介绍
问答服务的输入为用户提问,输出是与输入最匹配的Top N(默认为top5)个知识点,知识点按得分从高到低排序。
返回知识点如果含有答案字段(answer),则表示返回匹配成功结果,如果没有答案字段,则表示推荐结果。
URI
POST https://{endpoint}/v1/{project_id}/qabots/{qabot_id}/requests
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| X-Auth-Token | 是 | String | 用户Token。 用于获取操作API的权限。获取Token接口响应消息头中X-Subject-Token的值即为Token。 |
| Content-Type | 是 | String | 消息体的类型(格式),参数值为“application/json”。 |
| 参数 | 是否必选 | 参数类型 | 说明 |
|---|---|---|---|
| session_id | 是 | String | 会话ID,由任意字符串组成,由用户自定义产生,用来区分不同的会话。 |
| user_id | 否 | String | 用户ID,用来区分唯一用户信息。 |
| question | 是 | String | 用户问题。 |
| extends | 否 | Extends object | 扩展参数项。 |
| threshold_enable | 否 | Boolean | true:启动内部阈值 返回经过阈值处理之后的答案。 false:不启用内部阈值 返回原答案。 |
| chat_enable | 否 | Boolean | 默认true true:使用内部闲聊语料进行兜底。 false:不使用闲聊兜底。 |
| operate_type | 否 | Integer | 调用接口时候传入,用以标记的问答的行为,默认为0,最终会展示在问答日志里。
|
响应消息
| 参数 | 参数类型 | 描述 |
|---|---|---|
| qa_pair_id | String | 问答对ID。 |
| st_question | String | 标准问题。 |
| ex_questions | Array of ExQuestions objects | 扩展问。 |
| answer | String | 答案。 |
| score | Float | 相似度得分,精确到小数点后3位。 |
| domain | String | 问题类别。 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| domains | 否 | Array of strings | 领域列表,多个领域用分号隔开。如果设置了领域且领域不为空,就从这些领域中匹配答案,否则就从该用户的全部知识库匹配答案。 当前最多支持10个领域。 |
| top | 否 | Integer | 返回答案数量,默认为5,取值范围1~10。 |
状态码: 400
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 调用失败时的错误码。 调用成功时无此字段。 |
| error_msg | String | 调用失败时的错误信息。 调用成功时无此字段。 |
请求示例
POST https://{endpoint}/v1/1604d8170cd84440a81281e5a3a04f8b/qabots/303a0a00-c88a-43e3-aa2f-d5b8b9832b02/requests
Request Header:
Content-Type: application/json
X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"user_id": "z00123456",
"session_id": "xxxxxxxxxxxxxxxxxx",
"operate_type":3,
"question": "桌面云无法登录",
"extends":{
"domains":["桌面云"],
"top":5
},
"threshold_enable":false,
"chat_enable":true
} 响应示例
状态码:200
成功响应示例
- 关闭内置阈值处理(设置threshold_enable = false),按top个数返回结果数量。
{ "request_id": "303a0a00-c88a", "question": "桌面云打不开", "answers": [ { "qa_pair_id":"123", "st_question":"桌面云打开不了", "answer":"用户帐号不对", "score":0.952, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"桌面云打开不了了", "answer":"用户帐号不对", "score":0.901, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"桌面云是啥", "answer":"桌面云是可以远程办公的系统", "score":0.352, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"电脑桌面打不开", "answer":"请检查下显示器是否开启", "score":0.352, "domain":"桌面云" }, ] } - 开启内部阈值处理
表10 内部阈值处理 处理条件
结果
备注
分值>0.85
返回分值与最高分差距在0.05范围内所有命中语料。
如果QaPairanswers对象的answer不为空,则为命中语料,如果answer为空,则为推荐语料。
0.70<分值<0.85
如果存在这个区间的语料,返回最高分值处于这个区间的命中语料。如果不存在这个区间的语料,则返回推荐语料。
0.55<分值<0.70
返回推荐语料。
分值<0.55
不返回语料。
- 示例1
{ "request_id": "303a0a00-c88a", "question": "桌面云打不开", "answers": [ { "qa_pair_id":"123", "st_question":"桌面云打开不了", "ex_questions": [ { "content": "桌面云" } ], "answer":"用户帐号不对", "top_score_question":"桌面云打开不了", "score":0.952, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"桌面云打开", "ex_questions": [ { "content": "桌面" } ], "answer":"打开桌面云", "top_score_question":"桌面云打开", "score":0.912, "domain":"桌面云" } ] } - 示例2
{ "request_id": "303a0a00-c88a", "question": "桌面云打不开", "answers": [ { "qa_pair_id":"123", "st_question":"桌面云打开不了", "top_score_question":"桌面云打开不了", "answer":"用户帐号不对", "score":0.752, "domain":"桌面云" } { "qa_pair_id":"123", "st_question":"桌面云打开不了了", "score":0.70, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"桌面云是啥", "score":0.54, "domain":"桌面云" } ] }
- 示例3
{ "request_id": "303a0a00-c88a", "question": "桌面云打不开", "answers": [ { "qa_pair_id":"123", "st_question":"桌面云打开不了了", "score":0.291, "domain":"桌面云" }, { "qa_pair_id":"123", "st_question":"桌面云是啥", "score":0.252, "domain":"桌面云" } ] }
- 示例1
- 闲聊兜底或无答案回复
{ "request_id": "303a0a00-c88a", "question": "你好", "answers": [ { "answer":"您好,请问有什么可以帮您的吗?" } ] }
状态码:400
失败响应示例
{
"error_code": "CBS.0022",
"error_msg": "session_id can not be null"
} 状态码
状态码请参见状态码。
错误码
错误码请参见错误码。