自定义问答 预生成 API 提供基于文本段落回答问题的功能,而无需创建项目、维护问答对,或者产生未充分利用的基础结构的成本。 此功能以 API 的形式提供,可用于满足问答需求,而无需了解有关自定义问题解答的详细信息。
给定用户查询和文本/段落块后,API 将返回答案和精确答案(如果可用)。
示例 API 用法
假设你有一个或多个文本块,你希望从中获取给定问题的答案。 通常,必须创建与文本块数一样多的源。 但是,现在使用预生成 API 可以查询文本块,而无需在项目中定义内容源。
可以使用此 API 的其他一些方案包括:
- 你正在开发一个面向最终用户的电子书阅读器应用,使最终用户能够突出显示文本、输入问题并查找关于突出显示文本段落的答案。
- 一个浏览器扩展,允许用户对浏览器页面上当前显示的内容提出问题。
- 一个运行状况机器人,它从用户获取查询,并根据机器人标识为与用户查询最相关的医疗内容提供答案。
下面是示例请求的示例:
示例请求
POST https://{Unique-to-your-endpoint}.api.cognitive.azure.cn/language/:query-text
对单个文本块进行示例查询
请求主体
{
"parameters": {
"Endpoint": "{Endpoint}",
"Ocp-Apim-Subscription-Key": "{API key}",
"Content-Type": "application/json",
"api-version": "2021-10-01",
"stringIndexType": "TextElements_v8",
"textQueryOptions": {
"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"
}
}
}
示例响应
在请求正文中,我们将查询单个文本块。 下面是为查询收到的示例响应:
{
"responses": {
"200": {
"headers": {},
"body": {
"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
}
]
}
}
}
我们看到,作为 API 响应的一部分收到多个答案。 每个答案都有一个特定的置信度分数,有助于了解答案的整体相关性。 答案范围表示是否还检测到潜在的短答案。 用户可以使用此置信度分数来确定在响应查询时提供哪些答案。
预生成 API 限制
API 调用限制
如果需要使用比限制更大的文档,可以在将文本发送到 API 之前将文本分成较小的文本块。 在此上下文中,文档是定义的单个文本字符字符串。
这些数字表示 每个 API 调用限制:
- 文档数:5。
- 单个文档的最大大小:5,120 个字符。
- 每个文档最多 3 个响应。
支持的语言代码
以下语言代码支持预生成 API。 这些语言代码符合 ISO 639-1 代码标准。
语言代码 | 语言 |
---|---|
af |
阿非利堪斯语 |
am |
阿姆哈拉语 |
ar |
阿拉伯语 |
as |
阿萨姆语 |
az |
阿塞拜疆语 |
ba |
巴什基尔语 |
be |
白俄罗斯语 |
bg |
保加利亚语 |
bn |
孟加拉语 |
ca |
加泰罗尼亚语 |
ckb |
中部库尔德语 |
cs |
捷克语 |
cy |
威尔士语 |
da |
丹麦语 |
de |
德语 |
el |
希腊语,现代(1453-) |
en |
英语 |
eo |
世界语 |
es |
西班牙语,卡斯蒂利亚语 |
et |
爱沙尼亚语 |
eu |
巴斯克语 |
fa |
波斯语 |
fi |
芬兰语 |
fr |
法语 |
ga |
爱尔兰语 |
gl |
加利西亚语 |
gu |
古吉拉特语 |
he |
希伯来语 |
hi |
印地语 |
hr |
克罗地亚语 |
hu |
匈牙利语 |
hy |
亚美尼亚语 |
id |
印度尼西亚语 |
is |
Icelandic |
it |
意大利语 |
ja |
日语 |
ka |
乔治亚语 |
kk |
哈萨克语 |
km |
中央高棉语 |
kn |
卡纳达语 |
ko |
Korean |
ky |
基尔吉斯,吉尔吉斯 |
la |
拉丁语 |
lo |
老挝语 |
lt |
立陶宛语 |
lv |
拉脱维亚语 |
mk |
马其顿语 |
ml |
马拉雅拉姆语 |
mn |
蒙古语 |
mr |
马拉地语 |
ms |
马来语 |
mt |
马耳他语 |
my |
缅甸语 |
ne |
尼泊尔语 |
nl |
荷兰语、弗莱米什语 |
nn |
新挪威语 |
no |
挪威语 |
or |
奥里亚语 |
pa |
旁遮普语、旁遮普语 |
pl |
波兰语 |
ps |
Pashto、Pushto |
pt |
Portuguese |
ro |
罗马尼亚语 |
ru |
Russian |
sa |
梵文 |
sd |
信德语 |
si |
僧伽罗语、辛加莱语 |
sk |
斯洛伐克语 |
sl |
斯洛文尼亚语 |
sq |
阿尔巴尼亚语 |
sr |
塞尔维亚语 |
sv |
瑞典语 |
sw |
斯瓦希里语 |
ta |
泰米尔语 |
te |
泰卢固语 |
tg |
塔吉克斯坦 |
th |
泰语 |
tl |
塔加洛语 |
tr |
土耳其语 |
tt |
鞑靼语 |
ug |
维吾尔语、维吾尔语 |
uk |
乌克兰语 |
ur |
乌尔都语 |
uz |
乌兹别克语 |
vi |
越南语 |
yi |
意第绪语 |
zh |
Chinese |
预生成 API 参考
请访问 完整的预生成 API 示例 文档,了解调用 API 所需的输入和输出参数。