DC 5.1.0 4.9 Cognitive Services
This page will describe how to configure Cognitive Services together with Digizuite.
- How to setup Computer Services from your Azure Portal.
- Pricing Details
- Find Endpoint and Subscription key in the Azure Portal
- Change the Appsettings in Digizuite to use the Endpoint and Subscruption Key.
Note: This guide shows you how to configure AI feature on the Azure portal: /wiki/spaces/PSBOK/pages/702939141 (Lasse Brønnum Brønsholt (Unlicensed) )
Configure Azure Portal
Add the Computer Vision service to your account through the azure portal:
Select a pricing tier that fits your consumption. After adding the service it will appear in your dashboard.
Pricing Details
Pricing details can be found here: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/computer-vision/
"For Recognize Text each POST call counts as a transaction. All GET calls to see the results of the async service are counted as transactions but are free of charge. For all other operations, each feature call counts as a transaction, whether called independently or grouped through the Analyze call. Analyze calls are used to make calling the API easier, but each feature used counts as a transaction. For instance an Analyze call containing Tag, Face, and Adult would count as three transactions."
The features that are supported is shown below here. The number of transaction is dependent on the number of visual features wanted. So if the system is configured with all, then it will be 7 transactions per asset.
ImageType = 0,
Faces = 1,
Adult = 2,
Categories = 3,
Color = 4,
Tags = 5,
Description = 6
These visual features are defaulted in the Digizuite configuration to "Tags". This will mean that we out of the box will have 1 transactions per asset.
Endpoint & Subscription Key
Important for the Digizuite AI Service is to have the endpoint and subscription key. These can be found when selecting the service in azure as shown below:
Appsettings in the Digizuite
These must be correctly added to app.settings under damcenter/DigizuiteCore/appsettings.json:
"ComputerVisionDetails": {
"subscriptionKey": "……………………………………………………..",
"AzureEndpointUrl": "https://northeurope.api.cognitive.microsoft.com/",
"VisualFeatures": "Tags"
}
Important is to notice that the Visual Features are based on the list from Azure. The default is these 5 which can be configured. Changing it will impact pricing.
Rate Limiting for Cognitive Services
In order to prevent overflow of requests from clients and change the limits of request depending on services, the endpoints must have rate limiters. The following documentation is a NuGet package called 'AspNetCoreRateLimit', which can also be used for services other than Azure's.
There are two ways of implementing rate limiting. Making the rate limiter global for all of azure services or specifying rate limiters on specific endpoints. The endpoint rules has to be done in the 'appsettings.json'. The rate limiters can also be based on Client Id or Client Ip. (Check documentation - https://github.com/stefanprodan/AspNetCoreRateLimit)
The Rules for the endpoints are specified in the 'General Rules' in appsettings. If the rate limiting is based on Client Id or Client Ip, then in addition to the general rules, 'appsettings' requires another set of endpoint rules for specific clients. ('ClientRateLimitRolicies')
These rules must be loaded in the 'StartUp' and 'Program'. (Check Documentation - https://github.com/stefanprodan/AspNetCoreRateLimit)
StartUp:
services.Configure<ClientRateLimitPolicies>(Configuration.GetSection("ClientRateLimitPolicies"));
Program:
using (var scope = webHost.Services.CreateScope()){
var clientPolicyStore = scope.ServiceProvider.GetRequiredService<IClientPolicyStore>();
awai clientPolicyStore.SeedAsync();
}
Rate Limiting without client Id or Client Ip
If the rate limiting without client id or client Ip, then the code documentation from above can be skipped.
Implementing rate limits for all endpoint
Variables 'EnableEndpointRateLimiting' has to be false and 'StackBlockedRequests' must be true (if you want throttle counter).
If 'StackedBlockedRequests' is false, the blocked requests that exceed the limits will not be recorded towards the other limits. So, the other rules will only record the requests that were not blocked. By settings the variable to true, the blocked requests will count towards the other rules.
"GeneralRules":[
{
"Endpoint": "*",
"Period": "15s",
"Limit": 10
},
{
"Endpoint": "*",
"Period": "15m",
"Limit": 100
},
{
"Endpoint": "*",
"Period": "24h",
"Limit": 5000
},
{
"Endpoint": "*",
"Period": "7d",
"Limit": 10000
}
]
Implementing rate limits for specific endpoints
Variables 'EnableEndpointRateLimiting' has to be true and 'StackBlockedRequest' must be true.
"GeneralRules":[
{
"Endpoint": "*get:/api/values",
"Period": "10s",
"Limit": 10
},
{
"Endpoint": "*:/api/values/1",
"Period": "2s",
"Limit": 10
}
]
"Endpoint" : "*:/api/values" - The rule will apply for all HTTP request for the specific endpoint.
"Endpoint" . "*get:/api/values" - The rule will only apply for the GET requests of that particular endpoint.
Update Rate limiting at runtime (Possible feature for future reference)
It is possible to add new rules (client specific) at runtime.
[httpPost]
public void Post(){
var id = $"{_options.ClientPolicyPrefix}_cl-key-1";
var clPolicy = _clientPolicyStore.Get(id);
clPolicy.Rules.Add(new RateLimitRule){
Endpoint = "*/api/testpolicyupdate";
Period = "1h",
Limit = 100
});
_clientPolicyStore.Set(id,clPolicy);
}