I'm trying to call a self-trained model using the Javascript SDK so that I can analyze a document that I receive via URL. However, I get a 404 error and the message
The requested model was not found
If I have all ModelIDs displayed with the following code, I only get all the prebuilt models but not my own. What am I doing wrong?
const document_model_admin_client = new DocumentModelAdministrationClient(
endpoint,
new AzureKeyCredential(key)
);
for await (const summary of document_model_admin_client.listDocumentModels()) {
const {
modelId, // The model's unique ID
description, // a textual description of the model, if provided during model creation
} = summary;
// You can get the full model info using `getDocumentModel`
const model = await document_model_admin_client.getDocumentModel(
modelId
);
console.log("MODEL: " + model.modelId);
}
So I try to call my own model in vain:
const client = new DocumentAnalysisClient(
endpoint,
new AzureKeyCredential(key)
);
const poller = await client.beginAnalyzeDocumentFromUrl(
"All",
downloadUrl
);
const { keyValuePairs } = await poller.pollUntilDone();
if (!keyValuePairs || keyValuePairs.length <= 0) {
console.log("No key-value pairs were extracted from the document.");
} else {
console.log("Key-Value Pairs:");
for (const { key, value, confidence } of keyValuePairs) {
console.log("- Key :", `"${key.content}"`);
console.log(
" Value:",
`"${(value && value.content) || "<undefined>"}" (${confidence})`
);
}
}
The above error occurs when you don't have a model in your Azure form recognizer service or still it is in training the model.
You need to check whether the model is completely trained or not. In my environment, I trained my model and it succeeded with the below information.
Portal:
Now, I use the same code to get the all models and it executes with all models.
Code:
Output:
Now, you can use your same code to analyze a document from a self-trained model using the Javascript SDK.
Reference:
Build and train a custom model - Document Intelligence (formerly Form Recognizer) - Azure AI services | Microsoft Learn