Question Answering - Get Answers From Text
使用正文中提供的文本回答指定的问题。
POST {Endpoint}/language/:query-text?api-version=2021-10-01
URI 参数
| 名称 | 在 | 必需 | 类型 | 说明 |
|---|---|---|---|---|
|
Endpoint
|
path | True |
string |
支持的认知服务终结点(例如,https://< resource-name.api.cognitiveservices.azure.com>)。 |
|
api-version
|
query | True |
string |
客户端 API 版本。 |
请求头
| 名称 | 必需 | 类型 | 说明 |
|---|---|---|---|
| Ocp-Apim-Subscription-Key | True |
string |
请求正文
| 名称 | 必需 | 类型 | 说明 |
|---|---|---|---|
| question | True |
string |
要查询给定文本记录的用户问题。 |
| records | True |
要搜索给定问题的文本记录。 |
|
| language |
string |
文本记录的语言。 这是语言的 BCP-47 表示形式。 例如,将“en”用于英语;西班牙语等的“es”。如果未设置,请将“en”用于英语作为默认值。 |
|
| stringIndexType |
指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets。 |
响应
| 名称 | 类型 | 说明 |
|---|---|---|
| 200 OK |
从输入文本获取答案的成功响应。 |
|
| Other Status Codes |
错误响应。 |
安全性
Ocp-Apim-Subscription-Key
类型:
apiKey
在:
header
示例
Successful query
示例请求
POST {Endpoint}/language/:query-text?api-version=2021-10-01
{
"question": "how long it takes to charge surface?",
"records": [
{
"id": "1",
"text": "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it."
},
{
"id": "2",
"text": "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface."
}
],
"language": "en"
}
示例响应
{
"answers": [
{
"answer": "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.",
"confidenceScore": 0.93,
"id": "1",
"answerSpan": {
"text": "two to four hours",
"confidenceScore": 0,
"offset": 28,
"length": 45
},
"offset": 0,
"length": 224
},
{
"answer": "It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.",
"confidenceScore": 0.92,
"id": "1",
"answerSpan": {
"text": "two to four hours",
"confidenceScore": 0,
"offset": 8,
"length": 25
},
"offset": 20,
"length": 224
},
{
"answer": "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.",
"confidenceScore": 0.05,
"id": "1",
"answerSpan": null,
"offset": 110,
"length": 244
}
]
}
定义
| 名称 | 说明 |
|---|---|
|
Answers |
要回答的问题和文本记录参数。 |
|
Answers |
表示答案结果。 |
|
Answer |
QnA 的应答范围对象。 |
| Error |
错误对象。 |
|
Error |
人工可读错误代码。 |
|
Error |
错误响应。 |
|
Inner |
人工可读错误代码。 |
|
Inner |
包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses。 |
|
String |
指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets。 |
|
Text |
表示答案结果。 |
|
Text |
表示要查询的输入文本记录。 |
AnswersFromTextOptions
要回答的问题和文本记录参数。
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| language |
string |
文本记录的语言。 这是语言的 BCP-47 表示形式。 例如,将“en”用于英语;西班牙语等的“es”。如果未设置,请将“en”用于英语作为默认值。 |
|
| question |
string |
要查询给定文本记录的用户问题。 |
|
| records |
要搜索给定问题的文本记录。 |
||
| stringIndexType | TextElements_v8 |
指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets。 |
AnswersFromTextResult
表示答案结果。
| 名称 | 类型 | 说明 |
|---|---|---|
| answers |
表示答案结果。 |
AnswerSpan
QnA 的应答范围对象。
| 名称 | 类型 | 说明 |
|---|---|---|
| confidenceScore |
number (double) minimum: 0maximum: 1 |
答案范围的预测分数,值范围为 0 到 1。 |
| length |
integer (int32) |
答案范围的长度。 |
| offset |
integer (int32) |
答案范围与答案的开始偏移量。 |
| text |
string |
答案范围的预测文本。 |
Error
错误对象。
| 名称 | 类型 | 说明 |
|---|---|---|
| code |
服务器定义的错误代码集之一。 |
|
| details |
Error[] |
导致此报告错误的特定错误的详细信息数组。 |
| innererror |
包含与当前对象有关错误的更具体信息的对象。 |
|
| message |
string |
错误的人工可读表示形式。 |
| target |
string |
错误的目标。 |
ErrorCode
人工可读错误代码。
| 值 | 说明 |
|---|---|
| InvalidRequest | |
| InvalidArgument | |
| Unauthorized | |
| Forbidden | |
| NotFound | |
| ProjectNotFound | |
| OperationNotFound | |
| AzureCognitiveSearchNotFound | |
| AzureCognitiveSearchIndexNotFound | |
| TooManyRequests | |
| AzureCognitiveSearchThrottling | |
| AzureCognitiveSearchIndexLimitReached | |
| InternalServerError | |
| ServiceUnavailable |
ErrorResponse
错误响应。
| 名称 | 类型 | 说明 |
|---|---|---|
| error |
错误对象。 |
InnerErrorCode
人工可读错误代码。
| 值 | 说明 |
|---|---|
| InvalidRequest | |
| InvalidParameterValue | |
| KnowledgeBaseNotFound | |
| AzureCognitiveSearchNotFound | |
| AzureCognitiveSearchThrottling | |
| ExtractionFailure |
InnerErrorModel
包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses。
| 名称 | 类型 | 说明 |
|---|---|---|
| code |
服务器定义的错误代码集之一。 |
|
| details |
object |
错误详细信息。 |
| innererror |
包含与当前对象有关错误的更具体信息的对象。 |
|
| message |
string |
错误信息。 |
| target |
string |
错误目标。 |
StringIndexType
指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets。
| 值 | 说明 |
|---|---|
| TextElements_v8 |
返回的偏移量和长度值将与 TextElements(Graphemes 和 Grapheme 群集)相对应,确认为 Unicode 8.0.0 标准。 如果应用程序是用 .Net Framework 或 .Net Core 编写的,并且将使用 StringInfo,请使用此选项。 |
| UnicodeCodePoint |
返回的偏移量和长度值将对应于 Unicode 码位。 如果使用支持 Unicode 的语言(例如 Python)编写应用程序,请使用此选项。 |
| Utf16CodeUnit |
返回的偏移量和长度值将对应于 UTF-16 代码单元。 如果应用程序是用支持 Unicode 的语言(例如 Java、JavaScript)编写的,请使用此选项。 |
TextAnswer
表示答案结果。
| 名称 | 类型 | 说明 |
|---|---|---|
| answer |
string |
答。 |
| answerSpan |
回答与用户问题相关的 span 对象。 |
|
| confidenceScore |
number (double) minimum: 0maximum: 1 |
答案置信度分数,值范围为 0 到 1。 |
| id |
string |
记录 ID。 |
| length |
integer (int32) |
句子的长度。 |
| offset |
integer (int32) |
文档开头的句子偏移量。 |
TextDocument
表示要查询的输入文本记录。
| 名称 | 类型 | 说明 |
|---|---|---|
| id |
string |
文本记录的唯一标识符。 |
| text |
string |
记录的文本内容。 |