AnalyzeDocumentAsync(Azure 文档智能)抛出 404 异常

问题描述 投票:0回答:1

我有以下代码:

public async Task TestExtractionDataAsync()
{
    _documentAnalysisClient = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(key));

    var documentUri = new Uri("https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf");

    var analyzeDocumentContent = new AnalyzeDocumentContent()
{
    UrlSource = documentUri 
};

    var operation = await _documentAnalysisClient.AnalyzeDocumentAsync(WaitUntil.Completed, "Test_6_Jornalera", analyzeDocumentContent);
}

“AnalyzeDocumentAsync”方法抛出“404 Not Found”异常。文件 URL 有效。端点和密钥与此处相同: Key and endpoint

并从此处提取 ModelId: Models Ids

我注意到的一件事是,在 Azure AI 的文档智能部分中,我的项目没有出现: DIS section

我从这里创建了文档智能项目: Created in 1 Created in 2

对可能发生的事情有什么想法吗?我不知道为什么该方法会抛出 404。所有元素、url 和键都就位。

我一步步尝试了文档,但它似乎已经过时了(使用文档智能模型)。

.net azure artificial-intelligence azure-form-recognizer
1个回答
0
投票

对可能发生的事情有什么想法吗?我不知道为什么该方法会抛出 404。所有元素、url 和键都就位。

这里我创建了一个应用程序来与Azure Form Recognizer服务交互。

FormRecognizerService.cs:

using Azure;
using Azure.AI.FormRecognizer;
using Azure.AI.FormRecognizer.Models;
using System;
using System.Threading.Tasks;

namespace MyFormRecognizerApp
{
    public class FormRecognizerService
    {
        private readonly FormRecognizerClient _formRecognizerClient;

        public FormRecognizerService(string endpoint, string key)
        {
            var credential = new AzureKeyCredential(key);
            _formRecognizerClient = new FormRecognizerClient(new Uri(endpoint), credential);
        }

        public async Task AnalyzeDocumentAsync(Uri documentUri, string modelName)
        {
            try
            {
                // Start the custom form recognition operation
                RecognizeCustomFormsOperation operation = await _formRecognizerClient.StartRecognizeCustomFormsFromUriAsync(modelName, documentUri);

                // Wait for the operation to complete
                await operation.WaitForCompletionAsync();

                // Get the response
                Response<RecognizedFormCollection> response = await operation.WaitForCompletionAsync();

                // Check if the operation was successful
                if (response.GetRawResponse().Status == 200)
                {
                    RecognizedFormCollection recognizedForms = response.Value;
                    // Process the recognized forms
                    foreach (RecognizedForm form in recognizedForms)
                    {
                        Console.WriteLine($"Form of type: {form.FormType}");
                        foreach (FormField field in form.Fields.Values)
                        {
                            Console.WriteLine($"INVOICE: {form.Fields["INVOICE"].Value}");
                            Console.WriteLine($"DATE: {form.Fields["DATE"].Value}");
                        }
                    }
                }
                else
                {
                    throw new RequestFailedException("The operation did not complete successfully.");
                }
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine($"Error analyzing document: {ex.Message}");
            }
        }
    }
}

程序.cs:

using System;
using System.Threading.Tasks;

namespace MyFormRecognizerApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string endpoint = "https://your-Document intelligence.cognitiveservices.azure.com/";
            string key = "key";
            string modelName = "modelID";

            var service = new FormRecognizerService(endpoint, key);

            Uri documentUri = new Uri("https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf\r\n");

            await service.AnalyzeDocumentAsync(documentUri, modelName);
        }
    }
}

这是我的文档智能资源。 enter image description here

  • 以下是我的模型,通过样本发票进行测试并进行了训练。

enter image description here

  • 这里我的任务是分析文档并让以下字段识别并应在控制台中打印。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.