You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/cognitive-search-custom-skill-form.md
+31-21Lines changed: 31 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,45 +32,58 @@ You'll need to train a Form Recognizer model with your input forms before you us
32
32
33
33
Clone the [Azure Search Power Skills](https://github.com/Azure-Samples/azure-search-power-skills) GitHub repository to your local machine. Then navigate to **Vision/AnalyzeForm/** and open _AnalyzeForm.csproj_ in Visual Studio. This project creates an Azure Function resource that fulfills the [custom skill interface](cognitive-search-custom-skill-interface.md) and can be used for Azure Cognitive Search enrichment. It takes form documents as inputs, and it outputs (as text) the key/value pairs that you specify.
34
34
35
-
Open _PowerSkills.sln_ in Visual Studio and locate the **AnalyzeForm** project on the left pane. Then make the following changes.
36
-
* Add project-level environment variables. Right-click the project file and select **Properties**. In the **Properties** window, click the **Debug** tab and then find the **Environment variables** field. Click **Add** to add the following variables:
35
+
Locate the **AnalyzeForm** project on the left pane and make the following changes.
36
+
* Add project-level environment variables. Right-click the project title and select **Properties**. In the **Properties** window, click the **Debug** tab and then find the **Environment variables** field. Click **Add** to add the following variables:
37
37
*`FORMS_RECOGNIZER_ENDPOINT_URL` with the value set to your endpoint URL.
38
38
*`FORMS_RECOGNIZER_API_KEY` with the value set to your subscription key.
39
39
*`FORMS_RECOGNIZER_MODEL_ID` with the value set to the ID of the model you trained.
40
40
*`FORMS_RECOGNIZER_RETRY_DELAY` with the value set to 1000. This is the time in milliseconds that the program will wait before re-querying the service for a response.
41
-
*`FORMS_RECOGNIZER_MAX_ATTEMPTS` with the value set to 100. This is the number of times the program will query the service while attempting to get a success response.
41
+
*`FORMS_RECOGNIZER_MAX_ATTEMPTS` with the value set to 100. This is the number of times the program will query the service while attempting to get a successful response.
42
42
43
-
Next, open _AnalyzeForm.cs_ and find the `fieldMappings` variable, which references the field-mappings.json file. This file (and the variable that references it) defines the list of keys you want to extract from your forms and a custom label for each key. For example, a value of `{ "Address:", "address" }, { "Invoice For:", "recipient" }` means the script will only save the values for the detected `Address:` and `Invoice For:`keys, and it'll label those values with `"address"` and `"recipient"`, respectively.
43
+
Next, open _AnalyzeForm.cs_ and find the `fieldMappings` variable, which references the field-mappings.json file. This file (and the variable that references it) defines the list of keys you want to extract from your forms and a custom label for each key. For example, a value of `{ "Address:", "address" }, { "Invoice For:", "recipient" }` means the script will only save the values for the detected `Address:` and `Invoice For:`fields, and it'll label those values with `"address"` and `"recipient"`, respectively.
44
44
45
-
Finally, note the `contentType` variable. This script runs the given Form Recognizer model on PDF files, but if you're working with a different file type, you need to change the `contentType` to the correct[MIME type](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types) for your file.
45
+
Finally, note the `contentType` variable. This script runs the given Form Recognizer model on remote documents that are accessed by URL, so the content type is `application/json`. If you want to analyze local files by including their byte streams in the HTTP requests, you'll need to change the `contentType` to the appropriate[MIME type](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types) for your file.
46
46
47
47
## Test the function from Visual Studio
48
48
49
-
After you've edited your project, save it and set the **AnalyzeForm** project as the startup project in Visual Studio. Then Press **F5** to run it in your local environment. Use a REST service like Postman to call the function.
49
+
After you've edited your project, save it and set the **AnalyzeForm** project as the startup project in Visual Studio (if it isn't set already). Then press **F5** to run the function in your local environment. Use a REST service like Postman to call the function.
50
+
51
+
### HTTP request
52
+
53
+
You'll make the following request to access the function.
50
54
51
55
```HTTP
52
56
POST https://localhost:7071/api/analyze-form
53
57
```
54
58
55
59
### Request body
56
60
57
-
> [!NOTE]
58
-
> This request uses a sample file stored in the [Azure Search Power Skills](https://github.com/Azure-Samples/azure-search-power-skills) repository. If you trained the model with your own forms, replace this URL with the URL to your own sample form. When the skill is integrated in a skillset, the URL and token will be provided by Cognitive Search.
Here you'll need to provide the URL of a form that has the same type as the forms you trained with. For testing purposes, you can use one of your training forms. If you followed the cURL quickstart, your forms will be located in an Azure blob storage account. Open Azure Storage Explorer, locate a form file, right-click it, and select **Get Shared Access Signature**. This will provide you with a URL and SAS token. Enter these in the `"formUrl"` and `"formSasToken"` fields of your request body, respectively.
78
+
79
+
> [!div class="mx-imgBorder"]
80
+
> 
81
+
82
+
If you want to analyze a remote document that isn't in Azure blob storage, paste its URL in the `"formUrl"` field and leave the `"formSasToken"` field blank.
83
+
84
+
> [!NOTE]
85
+
> When the skill is integrated in a skillset, the URL and token will be provided by Cognitive Search.
86
+
74
87
### Response
75
88
76
89
You should see a response similar to the following example:
@@ -92,16 +105,13 @@ You should see a response similar to the following example:
92
105
```
93
106
94
107
## Publish the function to Azure
95
-
When you're satisfied with the function behavior, you can publish it.
96
108
97
-
1. In **Solution Explorer**, right-click the project and select **Publish**. Choose **Create New** > **Publish**.
109
+
When you're satisfied with the function behavior, you can publish it.
98
110
111
+
1. In the **Solution Explorer** in Visual Studio, right-click the project and select **Publish**. Choose **Create New** > **Publish**.
99
112
1. If you haven't already connected Visual Studio to your Azure account, select **Add an account....**
100
-
101
-
1. Follow the on-screen prompts. You're asked to specify a unique name for your app service, the Azure subscription, the resource group, the hosting plan, and the storage account you want to use. You can create a new resource group, a new hosting plan, and a storage account if you don't already have these. When finished, select **Create**.
102
-
113
+
1. Follow the on-screen prompts. You need to specify a unique name for your app service, the Azure subscription, the resource group, the hosting plan, and the storage account you want to use. You can create a new resource group, a new hosting plan, and a new storage account if you don't already have these. When you're finished, select **Create**.
103
114
1. After the deployment is complete, notice the Site URL. This is the address of your function app in Azure. Save it to a temporary location.
104
-
105
115
1. In the [Azure portal](https://portal.azure.com), navigate to the Resource Group, and look for the `AnalyzeForm` Function you published. Under the **Manage** section, you should see Host Keys. Copy the *default* host key and save it to a temporary location.
106
116
107
117
## Connect to your pipeline
@@ -151,8 +161,8 @@ To use this skill in a Cognitive Search pipeline, you'll need to add a skill def
151
161
152
162
In this guide, you created a custom skill from the Azure Form Recognizer service. To learn more about custom skills, see the following resources.
153
163
154
-
+[Power Skills: a repository of custom skills](https://github.com/Azure-Samples/azure-search-power-skills)
155
-
+[Add a custom skill to an AI enrichment pipeline](cognitive-search-custom-skill-interface.md)
156
-
+[How to define a skillset](cognitive-search-defining-skillset.md)
0 commit comments