Ejemplo n.º 1
0
        private async Task GetTextAnalyticsResponse(ConversationUtterance utterance, ConcurrentDictionary <long, DocumentSentiment> textAnalyticsDictionary)
        {
            int retries = 0;
            var sent    = false;

            while (!sent)
            {
                try
                {
                    // run TA prediction endpoint
                    textAnalyticsDictionary[utterance.Timestamp] = await _textAnalyticsService.PredictSentimentAsync(utterance.Text, opinionMining : true);

                    sent = true;
                }
                catch (RequestFailedException e)
                {
                    retries++;
                    if (e.Status == (int)HttpStatusCode.TooManyRequests && retries <= Constants.MaxRetries)
                    {
                        await WaitRandomTime(Constants.RetryMaxWaitTimeInMillis);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async Task GetLuisResponse(ConversationUtterance utterance, ConcurrentDictionary <long, CustomLuisResponse> luisDictionary, int index)
        {
            int retires = 0;
            var sent    = false;

            while (!sent)
            {
                try
                {
                    // run luis prediction endpoint
                    int clientIndex = index % _luisPredictionServices.Count;
                    luisDictionary[utterance.Timestamp] = await _luisPredictionServices[clientIndex].Predict(utterance.Text);
                    sent = true;
                }
                catch (ErrorException e)
                {
                    retires++;
                    if (e.Response.StatusCode == HttpStatusCode.TooManyRequests && retires <= Constants.MaxRetries)
                    {
                        await WaitRandomTime(Constants.RetryMaxWaitTimeInMillis);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }