- Custom Skill for Azure Search
This code is provided for demo purposes only for course AI-102.
- Azure Subscription
- Visual Studio Code or VS 2019
- .Net Core
-
From the Azure portal create a new Cognitive Service Translator and pick the endpoint address and keys.
-
Create a new Function on azure portal or use Visual Studio Code to create and deploy HTTP triggered functions. Refer to the following tutorial for details.
-
In folder
TranslateFunction
you can find a demo project for deployment. UpdateTranslateFunction.cs
the following values with your Translator service.static string CognitiveServicesTokenUri = "https://<your-service-name>.cognitiveservices.azure.com/sts/v1.0/issuetoken"; static string SubscriptionKey = "<your key>";
-
Publish and test your function. Make sure that translation is working as expected. You can use following JSON as body for test:
{"values": [ { "recordId": "a1", "data": { "text": "Tiger, tiger burning bright in the darkness of the night.", "from": "en", "to": "fr" } }] }
-
Create or reuse a new storage account. Create container
reviews
and upload fileHotelReviews_Free.csv
in it. -
Create or reuse existing Azure Cognitive Search. Register new
Data Source
from the file you uploaded in the storage account above. -
Click on 'Import' on top to start importing wizard. Some details you can find in doc.
-
When the index build you can open
Search explorer
and run a few queries to check if review content can be retrieved. -
Now you need to add your function to
custom skills
update skill's JSON as explained in tutorial. Example of the custom skill modification{ "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill", "name": "custom translate to italian", "description": "translate description on italian by use custom skill", "context": "/document", "uri": "https://funazuretranslate.azurewebsites.net/api/Translate?to=en&code=<YOUR CODE>", "httpMethod": "POST", "timeout": "PT30S", "batchSize": 1, "degreeOfParallelism": 20, "inputs": [ { "name": "text", "source": "/document/reviews_text" }, { "name": "from", "source": "/document/Language" } ], "outputs": [ { "name": "text", "targetName": "reviews_text_en" } ], "httpHeaders": {} }
-
Now you need to create a new field with name
reviews_text_en
referenced in skill. First you need to updateindexer definition JSON
with new output like following:"outputFieldMappings": [ { "sourceFieldName": "/document/reviews_text_en", "targetFieldName": "reviews_text_en" } ],
-
Second add new field in
index definition JSON
like following:fields [ ... { "name": "reviews_text_en", "type": "Edm.String", "facetable": false, "filterable": false, "key": false, "retrievable": true, "searchable": false, "sortable": false, "analyzer": null, "indexAnalyzer": null, "searchAnalyzer": null, "synonymMaps": [], "fields": [] }, ...
-
Finally you need to
reset
andrun
again the indexer. It should be successful. It is important to copalitereset
before start a newrun
-
Next request in
Search explorer
should return you back the reviews with english translation.