我有以下代码:
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 有效。端点和密钥与此处相同:
我注意到的一件事是,在 Azure AI 的文档智能部分中,我的项目没有出现:
对可能发生的事情有什么想法吗?我不知道为什么该方法会抛出 404。所有元素、url 和键都就位。
我一步步尝试了文档,但它似乎已经过时了(使用文档智能模型)。
对可能发生的事情有什么想法吗?我不知道为什么该方法会抛出 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);
}
}
}
这是我的文档智能资源。