Azure Form Recognizer 设置 API 版本

huangapple go评论51阅读模式
英文:

Azure Form Recognizer Set API Version

问题

我正在尝试使用 Az Form Recognizer SDK 版本 4.1.0-beta.1 和 API 版本 "2023_02_28_preview"。

文档中写道我可以使用 DocumentAnalysisClient,但没有显示如何将 API 版本设置为所需版本。有关如何做到这一点的任何示例吗?

英文:

I am trying to use the Az Form Recognizer SDK version 4.1.0-beta.1 and the API version "2023_02_28_preview".

The documentation reads that I can use the DocumentAnalysisClient, but it doesnt show how to set the API version to the desired version. Any examples on how to do that?

答案1

得分: 0

您无法在C#代码中指定表单识别API版本,因为在使用C#SDK进行表单识别时,默认情况下将使用Form Recognizer REST API版本3.0,或者根据导入的Nuget包版本默认使用4.1.0-beta.1。

> 请参阅此MS文档中的重要说明
> 重要
> 此项目针对Form Recognizer REST API版本
> 3.0
,请参阅来自此链接的下面的注意事项
> 注意:此客户端库的默认版本为服务的2022-08-31版本。

您可以在Visual Studio中导入Form Recognizer Nuget包时选择所需的API版本,如下所示:

Azure Form Recognizer 设置 API 版本

导入上述Azure.AI.FormRecognizer** Nuget包并使用所需的API版本后,您无需在代码中专门再次提及它。**

现在,您可以参考此MS文档中的代码并运行示例代码以管理表单识别资源。

> 注意:上述文档使用API版本4.0.0,如选择 - 从下拉菜单中选择4.0.0并在项目中安装该包。

代码:

> csharp > // 代码示例 >

输出:

Azure Form Recognizer 设置 API 版本

或者,您可以直接通过访问此链接或此链接并传递所需参数来调用API,如下所示:

> Azure Form Recognizer 设置 API 版本
>
> Azure Form Recognizer 设置 API 版本

> 注意- Form Recognizer 2023-02-28-preview仍处于预览状态,某些功能可能尚未完全工作。

您还可以在创建模型时在Form recognizer studio中指定API版本,如下所示:

Azure Form Recognizer 设置 API 版本

英文:

You cannot specify the Form recognizer API version in your C# code, Because while using C# SDK for form recognizer, By default it will use the Form Recognizer REST API version 3.0 or use 4.1.0-beta.1 by default depending on the Nuget package version you have imported.

> Refer the Note which states Important in this MS Document
> Important
> This project targets Form Recognizer REST API version
> 3.0
and Refer the Note below from this link.
> Note: This version of the client library defaults to the 2022-08-31 version of the service.

You can select your required API version while importing the Form Recognizer Nuget package in Visual Studio like below:-

Azure Form Recognizer 设置 API 版本

After importing the above Azure.AI.FormRecognizer Nuget package with desired API version you do not need to specifically mention it again in your code.

Now, you can refer the code from this MS Document and run the sample code to manage form recognizer resource.

> Note:- above document uses API version 4.0.0 as mentioned - Select version 4.0.0 from the dropdown menu and install the package in your project.

Code:-

> csharp
>
> using Azure; using Azure.AI.FormRecognizer.DocumentAnalysis;
>
> //use your `key` and `endpoint` environment variables to create your
> `AzureKeyCredential` and `DocumentAnalysisClient` instances string key
> = "<api-key>"; string endpoint = "https://siliconformrecgnizer123.cognitiveservices.azure.com/";
> AzureKeyCredential credential = new AzureKeyCredential(key);
> DocumentAnalysisClient client = new DocumentAnalysisClient(new
> Uri(endpoint), credential);
>
> //sample document Uri fileUri = new
> Uri("https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/rest-api/read.png");
>
> AnalyzeDocumentOperation operation = await
> client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed,
> "prebuilt-read", fileUri); AnalyzeResult result = operation.Value;
>
> foreach (DocumentPage page in result.Pages) {
> Console.WriteLine($"Document Page {page.PageNumber} has {page.Lines.Count} line(s), {page.Words.Count} word(s),");
> Console.WriteLine($"and {page.SelectionMarks.Count} selection mark(s).");
>
> for (int i = 0; i < page.Lines.Count; i++)
> {
> DocumentLine line = page.Lines[i];
> Console.WriteLine($" Line {i} has content: '{line.Content}'.");
>
> Console.WriteLine($" Its bounding polygon (points ordered clockwise):");
>
> for (int j = 0; j < line.BoundingPolygon.Count; j++)
> {
> Console.WriteLine($" Point {j} => X: {line.BoundingPolygon[j].X}, Y: {line.BoundingPolygon[j].Y}");
> }
> } }
>
> foreach (DocumentStyle style in result.Styles) {
> // Check the style and style confidence to see if text is handwritten.
> // Note that value '0.8' is used as an example.
>
> bool isHandwritten = style.IsHandwritten.HasValue && style.IsHandwritten == true;
>
> if (isHandwritten && style.Confidence > 0.8)
> {
> Console.WriteLine($"Handwritten content found:");
>
> foreach (DocumentSpan span in style.Spans)
> {
> Console.WriteLine($" Content: {result.Content.Substring(span.Index, span.Length)}");
> }
> } }
>
> Console.WriteLine("Detected languages:");
>
> foreach (DocumentLanguage language in result.Languages) {
> Console.WriteLine($" Found language with locale'{language.Locale}' with confidence {language.Confidence}."); }
>
>
>

Output:-

Azure Form Recognizer 设置 API 版本

Alternatively, You can directly call the API by going to this link or this link and passing the require parameters like below:-

> Azure Form Recognizer 设置 API 版本
>
> Azure Form Recognizer 设置 API 版本

> Note- Form Recognizer 2023-02-28-preview is still in preview and not Generally available so some features might not yet work completely.

You can also Specify API version in Form recognizer studio while creating your model like below:-

Azure Form Recognizer 设置 API 版本

huangapple
  • 本文由 发表于 2023年5月11日 08:12:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定