/// <summary>Answers the specified question using the provided text in the body.</summary> /// <param name="options">The question to answer.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> to cancel the request.</param> /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception> /// <exception cref="RequestFailedException">The service returned an error. The exception contains details of the service error.</exception> public virtual Response <TextAnswers> QueryText(TextQueryOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNull(options, nameof(options)); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(QuestionAnsweringClient)}.{nameof(QueryText)}"); scope.Start(); try { return(_textRestClient.Query(options, cancellationToken)); } catch (Exception ex) { scope.Failed(ex); throw; } }
public async Task <Response <TextAnswers> > QueryAsync(TextQueryOptions textQueryParameters, CancellationToken cancellationToken = default) { if (textQueryParameters == null) { throw new ArgumentNullException(nameof(textQueryParameters)); } using var message = CreateQueryRequest(textQueryParameters); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { TextAnswers value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = TextAnswers.DeserializeTextAnswers(document.RootElement); return(Response.FromValue(value, message.Response)); }
internal HttpMessage CreateQueryRequest(TextQueryOptions textQueryParameters) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendRaw("/language", false); uri.AppendPath("/:query-text", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(textQueryParameters); request.Content = content; return(message); }