python - 表单识别器 V2 / 成本呈爆炸式增长
问题描述
作为对 ChadZ 的回应,这里是表单识别器的指标,我正在谈论表单识别器指标。在我们的测试中,我们检查目录中的文件并按顺序分析它们,等待每个响应,写入结果,获取下一个文件等等。没有多线程。
看看 4 月 14 日的最大峰值是 15330 次通话。如果我们假设在 4 月 14 日的每个呼叫需要 10 秒(这会很快,通常可能需要一分钟),那么分析需要 153300 秒,即 2555 分钟或 42.58 小时。即使分析只需要 5 秒,那也将超过 20 小时。
当然我可能是错的,但目前最好的逻辑解释是跟踪和计费获取请求。
原帖
我正在使用带有标签的自定义模型(使用示例标签工具创建),并使用本页底部的“Python Form Recognizer Async Analyze”V2 SDK 代码获取结果。虽然 V2 中的异步功能比 V1 慢得多(我在这里描述过),但它似乎也贵得多。
在 post api 调用后获取结果的原始示例代码如下所示:
n_tries = 15
n_try = 0
wait_sec = 5
max_wait_sec = 60
while n_try < n_tries:
try:
resp = get(url = get_url, headers = {"Ocp-Apim-Subscription-Key": apim_key})
resp_json = resp.json()
if resp.status_code != 200:
print("GET analyze results failed:\n%s" % json.dumps(resp_json))
quit()
status = resp_json["status"]
if status == "succeeded":
print("Analysis succeeded:\n%s" % json.dumps(resp_json))
quit()
if status == "failed":
print("Analysis failed:\n%s" % json.dumps(resp_json))
quit()
# Analysis still running. Wait and retry.
time.sleep(wait_sec)
n_try += 1
wait_sec = min(2*wait_sec, max_wait_sec)
except Exception as e:
msg = "GET analyze results failed:\n%s" % str(e)
print(msg)
quit()
print("Analyze operation did not complete within the allocated time.")
正如您在原始示例代码中看到的那样,它每 5 秒查看一次以获取结果。
我的问题:在我看来,不仅对分析文档的 api 调用收费,而且对每个获取结果的 get-request 也收费。
自从使用 V2 以来,我们的账单增加了十倍甚至更多。我们目前处于测试阶段,我们通常每月大约有 400-500 个文档,这些文档在 V1 中被正确跟踪和计费。使用 V2 和上面的示例代码,我们现在有 63690 (!!!!!) 呼叫,每个呼叫都计费,成本正在爆炸式增长。
有人可以确认这种行为吗?
就个人而言,我想找回同步操作,其中 api 调用的响应还包含任何文档分析的结果。
try:
url = base_url + "/models/" + model_id + "/analyze"
with open(filepath, "rb") as f:
data_bytes = f.read()
response = requests.post(url=url, data=data_bytes, headers=headers)
return response.json()
except Exception as e:
print(str(e))
return None
不幸的是,这不再起作用了......
try:
response = requests.post(url=post_url, data=data_bytes, headers=headers) # , params=params)
if response.status_code != 202:
return None
# Success
get_url = response.headers["operation-location"]
return form_recognizerv2_getdata(get_url, subscription_key)
except Exception as e:
print("POST analyze failed:\n%s" % str(e))
return None
解决方案
GetAnalyzeResults 调用不计费。表单识别器仅针对已分析页面而非交易和请求计费。“表单识别器指标”图表显示了您的所有交易和 API 调用,包括 GetAnalyzeResults,但您无需为此付费。V1 和 V2 的计费方式相同。如果您遇到计费问题,请联系客户服务。
Neta-MSFT
推荐阅读
- tensorflow-probability - 在张量流中,是否有一个普通的“密集”双射器?
- excel - 使用 Excel VBA 根据主题和日期中的单词从 Outlook 电子邮件中提取详细信息
- c++ - 为什么可以遵守隐式转换
- regex - 正则表达式匹配两个单词之间有空格
- visual-studio - 如何修复:为 Google Play 商店创建 .aab 文件时,“jarsigner.exe”退出并显示代码 1
- matlab - 如何找到具有固定分量的矩阵的所有可能组合
- python - 散景回调:更改地理源
- tfs - 我们可以为 TFS 中的每个构建触发获取单独的工件放置文件夹吗
- java - maven 构建失败 - 无法解决 maven 依赖项
- java - Java中枚举值的线程安全比较