如何在Azure C#文档智能SDK中设置预建布局模型返回Markdown
解决C# SDK调用prebuilt-layout模型输出Markdown格式的问题
- 先检查你的Azure.AI.FormRecognizer NuGet包版本,旧版本SDK未包含
OutputContentFormat配置项,需升级到最新稳定版。 - 升级完成后,
AnalyzeDocumentOptions类会新增OutputContentFormat属性,通过ContentFormat.Markdown枚举值即可指定输出格式为Markdown。
示例代码:
using Azure.AI.FormRecognizer.DocumentAnalysis; // 初始化客户端(注意新版本命名空间) var client = new DocumentAnalysisClient(new Uri("你的端点地址"), new AzureKeyCredential("你的API密钥")); var analyzeOptions = new AnalyzeDocumentOptions { OutputContentFormat = ContentFormat.Markdown }; AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, "prebuilt-layout", fileUri, analyzeOptions); // 获取生成的Markdown内容 var analysisResult = await operation.WaitForCompletionAsync(); string markdownContent = analysisResult.Value.Content;
- 若升级后仍看不到该属性,确认是否引用了正确的命名空间
Azure.AI.FormRecognizer.DocumentAnalysis——新版本SDK调整了命名空间结构,不再使用旧版Azure.AI.FormRecognizer下的相关类。
内容的提问来源于stack exchange,提问作者Ray Suelzer
相关产品推荐
相关产品推荐

