gpt4 book ai didi

python - Azure 认知文本分析工具返回 400 错误请求 Python

转载 作者:行者123 更新时间:2023-12-03 05:55:42 25 4
gpt4 key购买 nike

我尝试使用 Azure 文本分析工具提取主题,但收到 400 Bad request 错误:我的代码如下:

account_key = '546e6162da424e6f991d03b7f6acxxx'
headers = {
'Ocp-Apim-Subscription-Key': account_key,
'Content-Type': 'application/json',
'Accept': 'application/json'}

import requests

tufani={
"documents": [
{
"language": "en",
"id": "1",
"text": "First document"
},
{
"language": "en",
"id": "100",
"text": "Final document"
}
]
}

print('Starting topic detection.')
uri = base_url + 'text/analytics/v2.0/topics'
r=requests.post('https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/topics',data=str(tufani),headers =headers)

print(r.status_code, r.reason)

(400,“错误请求”)

我在这方面做错了什么?

谢谢!

最佳答案

我尝试重现您的问题,并且发现如果使用 print(r.text),您的代码会出现 400 Bad Request 错误,原因如下。

u'{"code":"BadRequest","message":"Invalid request","innerError":{"code":"InvalidRequestContent","message":"Requests to this API should contain at least 100 documents, where each document is not null or empty","minimumNumberOfDocuments":100}}'

官方教程中也有显示Task 3 - Detect topics in a corpus of text ,如下。

This API requires a minimum of 100 text records to be submitted, but is designed to detect topics across hundreds to thousands of records. Any non-English records or records with less than 3 words will be discarded and therefore will not be assigned to topics. For topic detection, the maximum size of a single document that can be submitted is 30KB, and the total maximum size of submitted input is 30MB. Topic detection is rate limited to 5 submissions every 5 minutes.

因此请添加足够的文本记录以供使用API​​​​。

关于python - Azure 认知文本分析工具返回 400 错误请求 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41931434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com