Exemple #1
0
        private NaturalLanguageResult Request(string text, string url, NaturalLanguageRequestFeatures features = null)
        {
            var document       = new NaturalLanguageRequestDocument(text);
            var request        = url == "classifyText" ? new NaturalLanguageRequest(document) : new NaturalLanguageRequestWithEncodingType(document, features);
            var jsonRequest    = JsonConvert.SerializeObject(request, JsonSettings);
            var requestContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");

            if (!string.IsNullOrWhiteSpace(_apiKey))
            {
                _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}");
            }

            var requestUrl = UseProxyIfPossible(BaseUrl + url);
            var result     = _httpClient.PostAsync(requestUrl, requestContent).Result.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <NaturalLanguageResult>(result));
        }
 public NaturalLanguageRequest(NaturalLanguageRequestDocument document)
 {
     Document = document;
 }
 public NaturalLanguageRequestWithEncodingType(NaturalLanguageRequestDocument document, NaturalLanguageRequestFeatures features) : base(document)
 {
     Features = features;
 }