如何在Az Form Recognizer SDK 4.1.0-beta.1中设置API版本2023_02_28_preview?
Azure Form Recognizer SDK 4.1.0-beta.1 指定API版本示例
针对你使用的Azure Form Recognizer SDK 4.1.0-beta.1版本,要设置指定的API版本"2023_02_28_preview",可以通过初始化DocumentAnalysisClient时配置客户端选项实现,以下是主流语言的示例:
C# 示例
在C# SDK中,你可以通过DocumentAnalysisClientOptions的枚举值指定API版本:
using Azure.AI.FormRecognizer.DocumentAnalysis; using Azure; // 替换为你的资源密钥和端点 string resourceKey = "your-resource-key-here"; Uri resourceEndpoint = new Uri("https://your-resource-name.cognitiveservices.azure.com/"); // 初始化客户端选项,指定目标API版本 var clientOptions = new DocumentAnalysisClientOptions(DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview); // 创建DocumentAnalysisClient实例 DocumentAnalysisClient client = new DocumentAnalysisClient( resourceEndpoint, new AzureKeyCredential(resourceKey), clientOptions );
这里的V2023_02_28_Preview枚举值对应你需要的"2023_02_28_preview" API版本,SDK会自动映射正确的版本格式。
Python 示例
Python SDK则更直接,在构造DocumentAnalysisClient时直接传入api_version参数即可(注意版本号使用短横线分隔):
from azure.ai.formrecognizer import DocumentAnalysisClient from azure.core.credentials import AzureKeyCredential # 替换为你的资源密钥和端点 resource_key = "your-resource-key-here" resource_endpoint = "https://your-resource-name.cognitiveservices.azure.com/" # 创建客户端时指定API版本 client = DocumentAnalysisClient( endpoint=resource_endpoint, credential=AzureKeyCredential(resource_key), api_version="2023-02-28-preview" )
这样初始化后的客户端就会使用你指定的预览版API进行所有调用。
内容的提问来源于stack exchange,提问作者zooes
相关产品推荐
相关产品推荐

