Skip to content

Commit e35b626

Browse files
committed
add image; finish guide draft
1 parent 14a9d44 commit e35b626

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

articles/search/cognitive-search-custom-skill-form.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,58 @@ You'll need to train a Form Recognizer model with your input forms before you us
3232

3333
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.
3434

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:
3737
* `FORMS_RECOGNIZER_ENDPOINT_URL` with the value set to your endpoint URL.
3838
* `FORMS_RECOGNIZER_API_KEY` with the value set to your subscription key.
3939
* `FORMS_RECOGNIZER_MODEL_ID` with the value set to the ID of the model you trained.
4040
* `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.
4242

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.
4444

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.
4646

4747
## Test the function from Visual Studio
4848

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.
5054

5155
```HTTP
5256
POST https://localhost:7071/api/analyze-form
5357
```
5458

5559
### Request body
5660

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.
61+
Start with the request body template below.
5962

6063
```json
6164
{
6265
"values": [
6366
{
6467
"recordId": "record1",
6568
"data": {
66-
"formUrl": "https://github.com/Azure-Samples/azure-search-power-skills/raw/master/SampleData/Invoice_4.pdf",
67-
"formSasToken": "?st=sasTokenThatWillBeGeneratedByCognitiveSearch"
69+
"formUrl": "<your-form-url>",
70+
"formSasToken": "<your-sas-token>"
6871
}
6972
}
7073
]
7174
}
7275
```
7376

77+
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+
> ![Azure storage explorer; a pdf document is selected](media/cognitive-search-skill-form/form-sas.png)
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+
7487
### Response
7588

7689
You should see a response similar to the following example:
@@ -92,16 +105,13 @@ You should see a response similar to the following example:
92105
```
93106

94107
## Publish the function to Azure
95-
When you're satisfied with the function behavior, you can publish it.
96108

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.
98110

111+
1. In the **Solution Explorer** in Visual Studio, right-click the project and select **Publish**. Choose **Create New** > **Publish**.
99112
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**.
103114
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-
105115
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.
106116

107117
## 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
151161

152162
In this guide, you created a custom skill from the Azure Form Recognizer service. To learn more about custom skills, see the following resources.
153163

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)
157-
+ [Create Skillset (REST)](https://docs.microsoft.com/rest/api/searchservice/create-skillset)
158-
+ [How to map enriched fields](cognitive-search-output-field-mapping.md)
164+
* [Power Skills: a repository of custom skills](https://github.com/*zure-Samples/azure-search-power-skills)
165+
* [Add a custom skill to an AI enrichment pipeline](cognitive-search-custom-skill-interface.md)
166+
* [How to define a skillset](cognitive-search-defining-skillset.md)
167+
* [Create Skillset (REST)](https://docs.microsoft.com/rest/api/*earchservice/create-skillset)
168+
* [How to map enriched fields](cognitive-search-output-field-mapping.md)
60 KB
Loading

0 commit comments

Comments
 (0)