gpt4 book ai didi

python - 微软 LUIS : unable to set time zone (datetimeReference) for datetimeV2 entities

转载 作者:行者123 更新时间:2023-12-03 04:02:19 25 4
gpt4 key购买 nike

我正在使用 V3 API 从 LUIS 端点获取预测,并且我需要一种方法来告诉 LUIS 我的时区,以便相对时间表达式(例如“过去两个小时”、“10 分钟内”)由 datetimeV2 实体正确解析。

如果我将 V2 API 与 timezoneOffset 选项一起使用,一切都会完美运行,但我无法使 V3 API 使用新选项 datetimeReference (应该替换 timezoneOffset)。实际上,我什至不知道应该为 datetimeReference 设置哪个值(整数?日期时间?)。

这是我使用 Python 的尝试。谁能告诉我是否有什么问题吗?

from datetime import datetime
import requests

appId = # my app id
subscriptionKey = # my subscription key

query = "tra 10 minuti" # = "in 10 minutes" (my app speaks Italian)

# ATTEMPT 1
# based on https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-concept-data-alteration?tabs=V2#change-time-zone-of-prebuilt-datetimev2-entity,
# assuming it works the same way as timezoneOffset
endpoint = 'https://westeurope.api.cognitive.microsoft.com/luis/prediction/v3.0/apps/{appId}/slots/staging/predict?datetimeReference=120&subscription-key={subscriptionKey}&query={query}'
endpoint = endpoint.format(appId = appId, subscriptionKey = subscriptionKey, query = query)

response = requests.get(endpoint)

# ATTEMPT 2
# according to https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-migration-api-v3
endpoint = 'https://westeurope.api.cognitive.microsoft.com/luis/prediction/v3.0/apps/{appId}/slots/staging/predict?'
endpoint = endpoint.format(appId = appId)

json = {
"query" : query,
"options":{
"datetimeReference": datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), # e.g. "2020-05-07T13:54:33". Not clear if that's what it wants
"preferExternalEntities": True
},
"externalEntities":[],
"dynamicLists":[]
}

response = requests.post(endpoint, json, headers = {'Ocp-Apim-Subscription-Key' : subscriptionKey})
<小时/>

更新:ATTEMPT 2 中发送请求的正确方法是

response = requests.post(endpoint, json = json, headers = {'Ocp-Apim-Subscription-Key' : subscriptionKey})

最佳答案

正如您所发现的,您的 JSON 应该放在 json 参数中,而不是 data 参数中:

response = requests.post(endpoint, json = json, headers = {'Ocp-Apim-Subscription-Key' : subscriptionKey})

关于python - 微软 LUIS : unable to set time zone (datetimeReference) for datetimeV2 entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61657527/

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