Skip to content

Commit

Permalink
CLU Build SDK (Azure#28639)
Browse files Browse the repository at this point in the history
* regenerated swagger

* Fixing convienience layer

* Naming errors fixes

* Fixes

* regenerated swagger

* modified convience layer client

* added sample

* lol

* added directives

* adding LRO support

* Added samples and tests

* changed directives

* var usage

* var usage

* updated samples, readme and update log

* directives

* Converted generation to DPG

* regeneration

* export api

* fixes

* regenerated snippets + export api

* rerecorded tests

* added breaking changes to the log

* fix

* fix

* addressing comments

* updated snippets

* fixed directive

* Updated sample
  • Loading branch information
Salah Mostafa authored May 23, 2022
1 parent b283376 commit f54d173
Show file tree
Hide file tree
Showing 314 changed files with 13,671 additions and 2,619 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Release History

## 1.0.0-beta.4 (Unreleased)
## 1.1.0-beta.1 (Unreleased)

### Features Added
* Added Conversation issue summarization task (Long-running operation)
* Added Conversation PII extraction task (Long-running operation)

### Breaking Changes
- Client now uses python dictionaries for method parameters and results instead of classes.
- Many input and result parameter name changes in `analyze_conversation()` method

### Bugs Fixed

Expand Down
297 changes: 274 additions & 23 deletions sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Response<AnalyzeConversationTaskResult> response = client.AnalyzeConversation(
conversationsProject);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Expand Down Expand Up @@ -68,9 +68,9 @@ Response<AnalyzeConversationTaskResult> response = await client.AnalyzeConversat
conversationsProject);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.Prediction.ProjectKind}");
Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Console.WriteLine("Intents:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
"How are you?",
orchestrationProject);
CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction;
var orchestratorPrediction = customConversationalTaskResult.Result.Prediction as OrchestratorPrediction;
```

## Asynchronous
Expand All @@ -32,7 +32,7 @@ Response<AnalyzeConversationResult> response = await client.AnalyzeConversation
"How are you?",
orchestrationProject);
CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction;
var orchestratorPrediction = customConversationalTaskResult.Result.Prediction as OrchestratorPrediction;
```

## Accessing project specific results
Expand All @@ -45,22 +45,14 @@ Depending on the project chosen by your orchestration model, you may get results
string respondingProjectName = orchestratorPrediction.TopIntent;
TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName];

if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering)
if (targetIntentResult.TargetProjectKind == TargetProjectKind.QuestionAnswering)
{
Console.WriteLine($"Top intent: {respondingProjectName}");

QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult;

KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result;

Console.WriteLine("Answers: \n");
foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers)
{
Console.WriteLine($"Answer: {answer.Answer}");
Console.WriteLine($"Confidence: {answer.Confidence}");
Console.WriteLine($"Source: {answer.Source}");
Console.WriteLine();
}
BinaryData questionAnsweringResponse = qnaTargetIntentResult.Result;
Console.WriteLine($"Qustion Answering Response: {questionAnsweringResponse.ToString()}");
}
```

Expand All @@ -70,7 +62,7 @@ if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering)
string respondingProjectName = orchestratorPrediction.TopIntent;
TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName];

if (targetIntentResult.TargetKind == TargetKind.Conversation)
if (targetIntentResult.TargetProjectKind == TargetProjectKind.Conversation)
{
ConversationTargetIntentResult cluTargetIntentResult = targetIntentResult as ConversationTargetIntentResult;

Expand Down Expand Up @@ -116,7 +108,7 @@ if (targetIntentResult.TargetKind == TargetKind.Conversation)
string respondingProjectName = orchestratorPrediction.TopIntent;
TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName];

if (targetIntentResult.TargetKind == TargetKind.Luis)
if (targetIntentResult.TargetProjectKind == TargetProjectKind.Luis)
{
LuisTargetIntentResult luisTargetIntentResult = targetIntentResult as LuisTargetIntentResult;
BinaryData luisResponse = luisTargetIntentResult.Result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Response<AnalyzeConversationTaskResult> response = client.AnalyzeConversation(
options);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.Prediction.ProjectKind}");
Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Console.WriteLine("Intents:");
Expand Down Expand Up @@ -89,9 +89,9 @@ Response<AnalyzeConversationTaskResult> response = await client.AnalyzeConversat
options);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.Prediction.ProjectKind}");
Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Console.WriteLine("Intents:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ TextConversationItem input = new TextConversationItem(
text: "Send an email to Carol about the tomorrow's demo.");
AnalyzeConversationOptions options = new AnalyzeConversationOptions(input)
{
IsLoggingEnabled = true,
Verbose = true
};

Expand All @@ -34,9 +33,9 @@ Response<AnalyzeConversationTaskResult> response = client.AnalyzeConversation(
options);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.Prediction.ProjectKind}");
Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Console.WriteLine("Intents:");
Expand Down Expand Up @@ -79,7 +78,6 @@ TextConversationItem input = new TextConversationItem(
text: "Send an email to Carol about the tomorrow's demo.");
AnalyzeConversationOptions options = new AnalyzeConversationOptions(input)
{
IsLoggingEnabled = true,
Verbose = true
};

Expand All @@ -91,9 +89,9 @@ Response<AnalyzeConversationTaskResult> response = await client.AnalyzeConversat
options);

CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Results.Prediction as ConversationPrediction;
ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction;

Console.WriteLine($"Project Kind: {customConversationalTaskResult.Results.Prediction.ProjectKind}");
Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}");
Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}");

Console.WriteLine("Intents:");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Analyze a conversation

This sample demonstrates how to analyze a conversation with Conversation Summarization. To get started, you'll need to create a Cognitive Language service endpoint and an API key. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md) for links and instructions.

To analyze an utterance, you need to first create a `ConversationAnalysisClient` using an endpoint and API key. These can be stored in an environment variable, configuration setting, or any way that works for your application.

```C# Snippet:ConversationAnalysisClient_Create
Uri endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
```

Once you have created a client, you can prepare the input:

```C# Snippet:StartAnalyzeConversation_ConversationSummarization_Input
var textConversationItems = new List<TextConversationItem>()
{
new TextConversationItem("1", "Agent", "Hello, how can I help you?"),
new TextConversationItem("2", "Customer", "How to upgrade Office? I am getting error messages the whole day."),
new TextConversationItem("3", "Agent", "Press the upgrade button please. Then sign in and follow the instructions."),
};

var input = new List<TextConversation>()
{
new TextConversation("1", "en", textConversationItems)
};

var conversationSummarizationTaskParameters = new ConversationSummarizationTaskParameters(new List<SummaryAspect>() { SummaryAspect.Issue, SummaryAspect.Resolution });

var tasks = new List<AnalyzeConversationLROTask>()
{
new AnalyzeConversationSummarizationTask("1", AnalyzeConversationLROTaskKind.ConversationalSummarizationTask, conversationSummarizationTaskParameters),
};
```

then you can start analyzing by calling the `StartAnalyzeConversation`, and because this is a long running operation, you have to wait until it's finished by calling `WaitForCompletion` function.

## Synchronous

```C# Snippet:StartAnalyzeConversation_StartAnalayzing
var analyzeConversationOperation = client.StartAnalyzeConversation(input, tasks);
analyzeConversationOperation.WaitForCompletion();
```

## Asynchronous

```C# Snippet:StartAnalyzeConversationAsync_StartAnalayzing
var analyzeConversationOperation = await client.StartAnalyzeConversationAsync(input, tasks);
await analyzeConversationOperation.WaitForCompletionAsync();
```

You can finally print the results:

```C# Snippet:StartAnalyzeConversation_ConversationSummarization_Results
var jobResults = analyzeConversationOperation.Value;
foreach (var result in jobResults.Tasks.Items)
{
var analyzeConversationSummarization = result as AnalyzeConversationSummarizationResult;

var results = analyzeConversationSummarization.Results;

Console.WriteLine("Conversations:");
foreach (var conversation in results.Conversations)
{
Console.WriteLine($"Conversation #:{conversation.Id}");
Console.WriteLine("Summaries:");
foreach (var summary in conversation.Summaries)
{
Console.WriteLine($"Text: {summary.Text}");
Console.WriteLine($"Aspect: {summary.Aspect}");
}
Console.WriteLine();
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Analyze a conversation

This sample demonstrates how to analyze a conversation with Conversation PII (Text input). To get started, you'll need to create a Cognitive Language service endpoint and an API key. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md) for links and instructions.

To analyze an utterance, you need to first create a `ConversationAnalysisClient` using an endpoint and API key. These can be stored in an environment variable, configuration setting, or any way that works for your application.

```C# Snippet:ConversationAnalysisClient_Create
Uri endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
```

Once you have created a client, you can prepare the input:

```C# Snippet:StartAnalyzeConversation_ConversationPII_Text_Input
var textConversationItems = new List<TextConversationItem>()
{
new TextConversationItem("1", "0", "Hi, I am John Doe."),
new TextConversationItem("2", "1", "Hi John, how are you doing today?"),
new TextConversationItem("3", "0", "Pretty good."),
};

var input = new List<TextConversation>()
{
new TextConversation("1", "en", textConversationItems)
};

var conversationPIITaskParameters = new ConversationPIITaskParameters(false, "2022-05-15-preview", new List<ConversationPIICategory>() { ConversationPIICategory.All }, false, null);

var tasks = new List<AnalyzeConversationLROTask>()
{
new AnalyzeConversationPIITask("analyze", AnalyzeConversationLROTaskKind.ConversationalPIITask, conversationPIITaskParameters),
};
```

then you can start analyzing by calling the `AnalyzeConversation`, and because this is a long running operation, you have to wait until it's finished by calling `WaitForCompletion` function.

## Synchronous

```C# Snippet:StartAnalyzeConversation_StartAnalayzing
var analyzeConversationOperation = client.StartAnalyzeConversation(input, tasks);
analyzeConversationOperation.WaitForCompletion();
```

## Asynchronous

```C# Snippet:StartAnalyzeConversationAsync_StartAnalayzing
var analyzeConversationOperation = await client.StartAnalyzeConversationAsync(input, tasks);
await analyzeConversationOperation.WaitForCompletionAsync();
```

You can finally print the results:

```C# Snippet:StartAnalyzeConversation_ConversationPII_Text_Results
var jobResults = analyzeConversationOperation.Value;
foreach (var result in jobResults.Tasks.Items)
{
var analyzeConversationPIIResult = result as AnalyzeConversationPIIResult;

var results = analyzeConversationPIIResult.Results;

Console.WriteLine("Conversations:");
foreach (var conversation in results.Conversations)
{
Console.WriteLine($"Conversation #:{conversation.Id}");
Console.WriteLine("Conversation Items: ");
foreach (var conversationItem in conversation.ConversationItems)
{
Console.WriteLine($"Conversation Item #:{conversationItem.Id}");

Console.WriteLine($"Redacted Text: {conversationItem.RedactedContent.Text}");

Console.WriteLine("Entities:");
foreach (var entity in conversationItem.Entities)
{
Console.WriteLine($"Text: {entity.Text}");
Console.WriteLine($"Offset: {entity.Offset}");
Console.WriteLine($"Category: {entity.Category}");
Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}");
Console.WriteLine($"Length: {entity.Length}");
Console.WriteLine();
}
}
Console.WriteLine();
}
}
```
Loading

0 comments on commit f54d173

Please sign in to comment.