Share via


QuestionAnsweringAuthoringClient.Import Method

Definition

Import project assets.

public virtual Azure.Operation<BinaryData> Import(Azure.WaitUntil waitUntil, string projectName, Azure.Core.RequestContent content, string format = default, string assetKind = default, Azure.RequestContext context = default);
abstract member Import : Azure.WaitUntil * string * Azure.Core.RequestContent * string * string * Azure.RequestContext -> Azure.Operation<BinaryData>
override this.Import : Azure.WaitUntil * string * Azure.Core.RequestContent * string * string * Azure.RequestContext -> Azure.Operation<BinaryData>
Public Overridable Function Import (waitUntil As WaitUntil, projectName As String, content As RequestContent, Optional format As String = Nothing, Optional assetKind As String = Nothing, Optional context As RequestContext = Nothing) As Operation(Of BinaryData)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

projectName
String

The name of the project to use.

content
RequestContent

The content to send as the body of the request. Details of the request body schema are in the Remarks section below.

format
String

Knowledge base Import or Export format. Allowed values: "json" | "tsv" | "excel".

assetKind
String

Kind of the asset of the project. Allowed values: "qnas" | "synonyms".

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The Operation<T> from the service that will contain a BinaryData object once the asynchronous operation on the service has completed. Details of the body schema for the operation's final value are in the Remarks section below.

Exceptions

projectName is null.

projectName is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call Import with required parameters and parse the result.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new QuestionAnsweringAuthoringClient(endpoint, credential);

var data = new {};

var operation = client.Import(WaitUntil.Completed, "<projectName>", RequestContent.Create(data));

BinaryData data = operation.WaitForCompletion();
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("jobId").ToString());
Console.WriteLine(result.GetProperty("lastUpdatedDateTime").ToString());
Console.WriteLine(result.GetProperty("status").ToString());

This sample shows how to call Import with all parameters and request content, and how to parse the result.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new QuestionAnsweringAuthoringClient(endpoint, credential);

var data = new {
    metadata = new {
        description = "<description>",
        language = "<language>",
        multilingualResource = true,
        settings = new {
            defaultAnswer = "<defaultAnswer>",
        },
    },
    assets = new {
        synonyms = new[] {
            new {
                alterations = new[] {
                    "<String>"
                },
            }
        },
        qnas = new[] {
            new {
                id = 1234,
                answer = "<answer>",
                source = "<source>",
                questions = new[] {
                    "<String>"
                },
                metadata = new {
                    key = "<String>",
                },
                dialog = new {
                    isContextOnly = true,
                    prompts = new[] {
                        new {
                            displayOrder = 1234,
                            qnaId = 1234,
                            qna = new {
                                id = 1234,
                                answer = "<answer>",
                                source = "<source>",
                                questions = new[] {
                                    "<String>"
                                },
                                metadata = new {
                                    key = "<String>",
                                },
                                activeLearningSuggestions = new[] {
                                    new {
                                        clusterHead = "<clusterHead>",
                                        suggestedQuestions = new[] {
                                            new {
                                                question = "<question>",
                                                userSuggestedCount = 1234,
                                                autoSuggestedCount = 1234,
                                            }
                                        },
                                    }
                                },
                            },
                            displayText = "<displayText>",
                        }
                    },
                },
                activeLearningSuggestions = new[] {
                    new {
                        clusterHead = "<clusterHead>",
                        suggestedQuestions = new[] {
                            new {
                                question = "<question>",
                                userSuggestedCount = 1234,
                                autoSuggestedCount = 1234,
                            }
                        },
                    }
                },
            }
        },
    },
    fileUri = "<fileUri>",
};

var operation = client.Import(WaitUntil.Completed, "<projectName>", RequestContent.Create(data), "<format>", "<assetKind>");

BinaryData data = operation.WaitForCompletion();
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("expirationDateTime").ToString());
Console.WriteLine(result.GetProperty("jobId").ToString());
Console.WriteLine(result.GetProperty("lastUpdatedDateTime").ToString());
Console.WriteLine(result.GetProperty("status").ToString());

Remarks

Below is the JSON schema for the request and response payloads. Additional information can be found in the service REST API documentation: https://learn.microsoft.com/rest/api/cognitiveservices/questionanswering/question-answering-projects/import

Request Body:

Schema for ImportJobOptions:

{
              metadata: {
                description: string, # Optional. Description of the project.
                language: string, # Required. Language of the text records. This is BCP-47 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default.
                multilingualResource: boolean, # Optional. Set to true to enable creating knowledgebases in different languages for the same resource.
                settings: {
                  defaultAnswer: string, # Optional. Default Answer response when no good match is found in the knowledge base.
                }, # Optional. Configurable settings of the Project.
              }, # Optional. Parameters needed to create the project.
              assets: {
                synonyms: [
                  {
                    alterations: [string], # Required. Collection of word alterations.
                  }
                ], # Optional. Collection of synonyms.
                qnas: [
                  {
                    id: number, # Optional. Unique ID for the QnA.
                    answer: string, # Optional. Answer text.
                    source: string, # Optional. Source from which QnA was indexed e.g. https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs .
                    questions: [string], # Optional. List of questions associated with the answer.
                    metadata: Dictionary<string, string>, # Optional. Metadata associated with the answer, useful to categorize or filter question answers.
                    dialog: {
                      isContextOnly: boolean, # Optional. To mark if a prompt is relevant only with a previous question or not. If true, do not include this QnA as answer for queries without context; otherwise, ignores context and includes this QnA in answers.
                      prompts: [
                        {
                          displayOrder: number, # Optional. Index of the prompt. It is used for ordering of the prompts.
                          qnaId: number, # Optional. ID of the QnA corresponding to the prompt.
                          qna: {
                            id: number, # Optional. Unique ID for the QnA.
                            answer: string, # Optional. Answer text.
                            source: string, # Optional. Source from which QnA was indexed e.g. https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs .
                            questions: [string], # Optional. List of questions associated with the answer.
                            metadata: Dictionary<string, string>, # Optional. Metadata associated with the answer, useful to categorize or filter question answers.
                            dialog: QnaDialog, # Optional. Context of a QnA.
                            activeLearningSuggestions: [
                              {
                                clusterHead: string, # Optional. Question chosen as the head of suggested questions cluster by Active Learning clustering algorithm.
                                suggestedQuestions: [
                                  {
                                    question: string, # Optional. Question suggested by the Active Learning feature.
                                    userSuggestedCount: number, # Optional. The number of times the question was suggested explicitly by the user.
                                    autoSuggestedCount: number, # Optional. The number of times the question was suggested automatically by the Active Learning algorithm.
                                  }
                                ], # Optional. List of all suggested questions for the QnA.
                              }
                            ], # Optional. List of Active Learning suggestions for the QnA.
                          }, # Optional. QnA record. Either QnAId or QnA record needs to be present in a Prompt.
                          displayText: string, # Optional. Text displayed to represent a follow up question prompt.
                        }
                      ], # Optional. List of prompts associated with the answer.
                    }, # Optional. Context of a QnA.
                    activeLearningSuggestions: [SuggestedQuestionsCluster], # Optional. List of Active Learning suggestions for the QnA.
                  }
                ], # Optional. List of QnA records to import.
              }, # Optional. All assets for this project.
              fileUri: string, # Optional. Import data File URI.
            }

Response Body:

ExportJobStateSchema for ExportJobState:
{
              createdDateTime: string (ISO 8601 Format), # Required.
              expirationDateTime: string (ISO 8601 Format), # Optional.
              jobId: string, # Required.
              lastUpdatedDateTime: string (ISO 8601 Format), # Required.
              status: "notStarted" | "running" | "succeeded" | "failed" | "cancelled" | "cancelling" | "partiallyCompleted", # Required. Job Status.
            }

Applies to