public async Task <Response <AnswersResult> > GetAnswersAsync(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default) { if (projectName == null) { throw new ArgumentNullException(nameof(projectName)); } if (deploymentName == null) { throw new ArgumentNullException(nameof(deploymentName)); } if (knowledgeBaseQueryOptions == null) { throw new ArgumentNullException(nameof(knowledgeBaseQueryOptions)); } using var message = CreateGetAnswersRequest(projectName, deploymentName, knowledgeBaseQueryOptions); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { AnswersResult value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = AnswersResult.DeserializeAnswersResult(document.RootElement); return(Response.FromValue(value, message.Response)); }
/// <summary>Answers the specified question using your knowledge base.</summary> /// <param name="question">The question to ask of the knowledge base.</param> /// <param name="project">The <see cref="QuestionAnsweringProject"/> to query.</param> /// <param name="options">Optional <see cref="AnswersOptions"/> with additional query options.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> to cancel the request.</param> /// <returns>An <see cref="AnswersResult"/> containing answers from the knowledge base to the specified question.</returns> /// <exception cref="ArgumentException"><paramref name="question"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="question"/> or <paramref name="project"/> is null.</exception> /// <exception cref="RequestFailedException">The service returned an error. The exception contains details of the service error.</exception> public virtual Task <Response <AnswersResult> > GetAnswersAsync(string question, QuestionAnsweringProject project, AnswersOptions options = null, CancellationToken cancellationToken = default) => GetAnswersAsync(project, (options ?? new()).WithQuestion(question), cancellationToken);
internal HttpMessage CreateGetAnswersRequest(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions) { 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-knowledgebases", false); uri.AppendQuery("projectName", projectName, true); uri.AppendQuery("deploymentName", deploymentName, true); 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(knowledgeBaseQueryOptions); request.Content = content; return(message); }