你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Question Answering - Get Answers From Text

使用正文中提供的文本回答指定的问题。

POST {Endpoint}/language/:query-text?api-version=2023-04-01

URI 参数

名称 必需 类型 说明
Endpoint
path True

string (uri)

支持的认知服务终结点(例如 https://.api.cognitiveservices.azure.com).

api-version
query True

string

minLength: 1

用于此作的 API 版本。

请求正文

名称 必需 类型 说明
question True

string

要查询给定文本记录的用户问题。

records True

TextDocument[]

要搜索给定问题的文本记录。

language

string

文本记录的语言。 这是语言的 BCP-47 表示形式。 例如,将“en”用于英语;西班牙语等的“es”。如果未设置,请将“en”用于英语作为默认值。

stringIndexType

StringIndexType

指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets

响应

名称 类型 说明
200 OK

AnswersFromTextResult

请求已成功。

Other Status Codes

ErrorResponse

意外的错误响应。

标头

x-ms-error-code: string

安全性

Ocp-Apim-Subscription-Key

类型: apiKey
在: header

OAuth2Auth

类型: oauth2
流向: implicit
授权 URL: https://login.microsoftonline.com/common/oauth2/authorize

作用域

名称 说明
https://cognitiveservices.azure.com/.default

示例

Successful query

示例请求

POST {Endpoint}/language/:query-text?api-version=2023-04-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.",
      "answerSpan": {
        "confidenceScore": 0,
        "length": 45,
        "offset": 28,
        "text": "two to four hours"
      },
      "confidenceScore": 0.93,
      "id": "1",
      "length": 224,
      "offset": 0
    },
    {
      "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.",
      "answerSpan": {
        "confidenceScore": 0,
        "length": 25,
        "offset": 8,
        "text": "two to four hours"
      },
      "confidenceScore": 0.92,
      "id": "1",
      "length": 224,
      "offset": 20
    },
    {
      "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.",
      "answerSpan": null,
      "confidenceScore": 0.05,
      "id": "1",
      "length": 244,
      "offset": 110
    }
  ]
}

定义

名称 说明
AnswersFromTextOptions

要回答的问题和文本记录参数。

AnswersFromTextResult

表示答案结果。

AnswerSpan

QnA 的应答范围对象。

Error

服务在处理请求期间遇到一些错误时返回的错误响应对象。

ErrorCode

人工可读错误代码。

ErrorResponse

错误响应。

InnerErrorCode

人工可读错误代码。

InnerErrorModel

包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses

StringIndexType

指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets

TextAnswer

表示答案结果。

TextDocument

表示要查询的输入文本记录。

AnswersFromTextOptions

要回答的问题和文本记录参数。

名称 类型 默认值 说明
language

string

文本记录的语言。 这是语言的 BCP-47 表示形式。 例如,将“en”用于英语;西班牙语等的“es”。如果未设置,请将“en”用于英语作为默认值。

question

string

要查询给定文本记录的用户问题。

records

TextDocument[]

要搜索给定问题的文本记录。

stringIndexType

StringIndexType

TextElements_v8

指定用于解释字符串偏移的方法。 默认为文本元素(Graphemes),根据 Unicode v8.0.0。 有关详细信息,请参阅 https://aka.ms/text-analytics-offsets

AnswersFromTextResult

表示答案结果。

名称 类型 说明
answers

TextAnswer[]

表示答案结果。

AnswerSpan

QnA 的应答范围对象。

名称 类型 说明
confidenceScore

number (double)

minimum: 0
maximum: 1

答案范围的预测分数,值范围为 0 到 1。

length

integer (int32)

答案范围的长度。

offset

integer (int32)

答案范围与答案的开始偏移量。

text

string

答案范围的预测文本。

Error

服务在处理请求期间遇到一些错误时返回的错误响应对象。

名称 类型 说明
code

ErrorCode

服务器定义的错误代码集之一。

details

Error[]

导致此报告错误的特定错误的详细信息数组。

innererror

InnerErrorModel

包含与当前对象有关错误的更具体信息的对象。

message

string

错误的人工可读表示形式。

target

string

错误的目标。

ErrorCode

人工可读错误代码。

说明
AzureCognitiveSearchIndexLimitReached

Azure 认知搜索索引限制达到错误

AzureCognitiveSearchIndexNotFound

Azure 认知搜索索引找不到错误

AzureCognitiveSearchNotFound

Azure 认知搜索找不到错误

AzureCognitiveSearchThrottling

Azure 认知搜索限制错误

Conflict

冲突错误

Forbidden

禁止访问错误

InternalServerError

内部服务器错误

InvalidArgument

参数错误无效

InvalidRequest

请求错误无效

NotFound

找不到错误

OperationNotFound

找不到操作错误

ProjectNotFound

项目找不到错误

QuotaExceeded

超出配额错误

ServiceUnavailable

服务不可用错误

Timeout

超时错误

TooManyRequests

请求过多错误

Unauthorized

未经授权的访问错误

Warning

警告错误

ErrorResponse

错误响应。

名称 类型 说明
error

Error

错误对象。

InnerErrorCode

人工可读错误代码。

说明
AzureCognitiveSearchNotFound

Azure 认知搜索找不到错误

AzureCognitiveSearchThrottling

Azure 认知搜索限制错误

EmptyRequest

空请求错误

ExtractionFailure

提取失败错误

InvalidCountryHint

国家/地区提示错误无效

InvalidDocument

文档错误无效

InvalidDocumentBatch

文档批处理错误无效

InvalidParameterValue

参数值错误无效

InvalidRequest

请求错误无效

InvalidRequestBodyFormat

请求正文格式错误无效

KnowledgeBaseNotFound

知识库找不到错误

MissingInputDocuments

缺少输入文档错误

ModelVersionIncorrect

模型版本错误错误

UnsupportedLanguageCode

不支持的语言代码错误

InnerErrorModel

包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses

名称 类型 说明
code

InnerErrorCode

服务器定义的错误代码集之一。

details

object

错误详细信息。

innererror

InnerErrorModel

包含与当前对象有关错误的更具体信息的对象。

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

AnswerSpan

回答与用户问题相关的 span 对象。

confidenceScore

number (double)

minimum: 0
maximum: 1

答案置信度分数,值范围为 0 到 1。

id

string

记录 ID。

length

integer (int32)

句子的长度。

offset

integer (int32)

文档开头的句子偏移量。

TextDocument

表示要查询的输入文本记录。

名称 类型 说明
id

string

文本记录的唯一标识符。

text

string

记录的文本内容。