Skip to content

Commit

Permalink
Resolve archboard feedback
Browse files Browse the repository at this point in the history
Partial resolution for Azure#29331
  • Loading branch information
heaths committed Jun 20, 2022
1 parent fc06049 commit 95fb684
Show file tree
Hide file tree
Showing 14 changed files with 3,361 additions and 288 deletions.
23 changes: 12 additions & 11 deletions sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dotnet add package Azure.AI.Language.Conversations --prerelease
- An [Azure subscription][azure_subscription]
- An existing Azure Language Service Resource

Though you can use this SDK to create and import conversation projects, [Language Studio][language_studio] is the preferred method for creating projects.

### Authenticate the client

In order to interact with the Conversations service, you'll need to create an instance of the [`ConversationAnalysisClient`][conversationanalysis_client_class] class. You will need an **endpoint**, and an **API key** to instantiate a client object. For more information regarding authenticating with Cognitive Services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth].
Expand Down Expand Up @@ -131,19 +133,17 @@ foreach (JsonElement entity in conversationPrediction.GetProperty("entities").En
Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}");
Console.WriteLine();

if (!entity.TryGetProperty("resolutions", out JsonElement resolutions))
{
continue;
}

foreach (JsonElement resolution in resolutions.EnumerateArray())
if (entity.TryGetProperty("resolutions", out JsonElement resolutions))
{
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
foreach (JsonElement resolution in resolutions.EnumerateArray())
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
}
}
}
}
Expand Down Expand Up @@ -389,6 +389,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[cognitive_auth]: https://docs.microsoft.com/azure/cognitive-services/authentication/
[contributing]: https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md
[core_logging]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md
[language_studio]: https://language.cognitive.azure.com/
[nuget]: https://www.nuget.org/

[conversationanalysis_client_class]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/src/ConversationAnalysisClient.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,51 +67,26 @@ foreach (JsonElement entity in conversationPrediction.GetProperty("entities").En
Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}");
Console.WriteLine();

if (!entity.TryGetProperty("resolutions", out JsonElement resolutions))
if (entity.TryGetProperty("resolutions", out JsonElement resolutions))
{
continue;
}

foreach (JsonElement resolution in resolutions.EnumerateArray())
{
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
foreach (JsonElement resolution in resolutions.EnumerateArray())
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
}
}
}
}
```

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationAsync
string projectName = "Menu";
string deploymentName = "production";

var data = new
{
analysisInput = new
{
conversationItem = new
{
text = "Send an email to Carol about tomorrow's demo",
id = "1",
participantId = "1",
}
},
parameters = new
{
projectName,
deploymentName,

// Use Utf16CodeUnit for strings in .NET.
stringIndexType = "Utf16CodeUnit",
},
kind = "Conversation",
};
Using the same `data` definition above, you can make an asynchronous request by calling `AnalyzeConversationAsync`:

```C# Snippet:ConversationAnalysis_AnalyzeConversationAsync
Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));
```
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,9 @@ JsonElement orchestrationPrediction = conversationalTaskResult.GetProperty("resu

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync
string projectName = "DomainOrchestrator";
string deploymentName = "production";

var data = new
{
analysisInput = new
{
conversationItem = new
{
text = "How are you?",
id = "1",
participantId = "1",
}
},
parameters = new
{
projectName,
deploymentName,

// Use Utf16CodeUnit for strings in .NET.
stringIndexType = "Utf16CodeUnit",
},
kind = "Conversation",
};
Using the same `data` definition above, you can make an asynchronous request by calling `AnalyzeConversationAsync`:

```C# Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionAsync
Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));

using JsonDocument result = await JsonDocument.ParseAsync(response.ContentStream);
Expand Down Expand Up @@ -136,19 +113,17 @@ if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "Conversa
Console.WriteLine($"Length: {entity.GetProperty("length").GetInt32()}");
Console.WriteLine();

if (!entity.TryGetProperty("resolutions", out JsonElement resolutions))
{
continue;
}

foreach (JsonElement resolution in resolutions.EnumerateArray())
if (entity.TryGetProperty("resolutions", out JsonElement resolutions))
{
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
foreach (JsonElement resolution in resolutions.EnumerateArray())
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution")
{
Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}");
Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}");
Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}");
Console.WriteLine();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,8 @@ Response response = client.AnalyzeConversation(RequestContent.Create(data));

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithLanguageAsync
string projectName = "Menu";
string deploymentName = "production";

var data = new
{
analysisInput = new
{
conversationItem = new
{
text = "Enviar un email a Carol acerca de la presentación de mañana",
language = "es",
id = "1",
participantId = "1",
}
},
parameters = new
{
projectName,
deploymentName,
verbose = true,

// Use Utf16CodeUnit for strings in .NET.
stringIndexType = "Utf16CodeUnit",
},
kind = "Conversation",
};
Using the same `data` definition above, you can make an asynchronous request by calling `AnalyzeConversationAsync`:

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithLanguageAsync
Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));
```
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,8 @@ Response response = client.AnalyzeConversation(RequestContent.Create(data));

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithOptionsAsync
string projectName = "Menu";
string deploymentName = "production";

var data = new
{
analysisInput = new
{
conversationItem = new
{
text = "Send an email to Carol about tomorrow's demo",
id = "1",
participantId = "1",
}
},
parameters = new
{
projectName,
deploymentName,
verbose = true,

// Use Utf16CodeUnit for strings in .NET.
stringIndexType = "Utf16CodeUnit",
},
kind = "Conversation",
};
Using the same `data` definition above, you can make an asynchronous request by calling `AnalyzeConversationAsync`:

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithOptionsAsync
Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Once you have created a client, you can call synchronous or asynchronous methods
```C# Snippet:ConversationAnalysisProjectsClient_ImportProject
string projectName = "Menu";

// Define our project assets and import.
// Define our project assets and import. In practice this would most often be read from a file.
var importData = new
{
projectFileVersion = "2022-05-01",
Expand Down Expand Up @@ -111,20 +111,31 @@ var trainData = new
trainingMode = "standard",
};

Operation<BinaryData> trainOperation = client.Train(WaitUntil.Started, projectName, RequestContent.Create(trainData));
trainOperation.WaitForCompletion();
Console.WriteLine($"Training project {projectName}...");
Operation<BinaryData> trainOperation = client.Train(
WaitUntil.Completed,
projectName,
RequestContent.Create(trainData));

// Deploy the model.
var deployData = new
{
trainedModelLabel = "Sample5",
};

Operation<BinaryData> deployOperation = client.DeployProject(WaitUntil.Started, projectName, "production", RequestContent.Create(deployData));
deployOperation.WaitForCompletion();
Console.WriteLine($"Deploying project {projectName} to production...");
Operation<BinaryData> deployOperation = client.DeployProject(
WaitUntil.Started,
projectName,
"production",
RequestContent.Create(deployData));

Console.WriteLine("Import complete");
```

# Asynchronous
## Asynchronous

Using the same `importData` definition above, you can make an asynchronous request by calling `ImportProjectAsync`:

```C# Snippet:ConversationAnalysisProjectsClient_ImportProjectAsync
string projectName = "Menu";
Expand Down Expand Up @@ -223,15 +234,24 @@ var trainData = new
trainingMode = "standard",
};

Operation<BinaryData> trainOperation = await client.TrainAsync(WaitUntil.Started, projectName, RequestContent.Create(trainData));
await trainOperation.WaitForCompletionAsync();
Console.WriteLine($"Training project {projectName}...");
Operation<BinaryData> trainOperation = await client.TrainAsync(
WaitUntil.Completed,
projectName,
RequestContent.Create(trainData));

// Deploy the model.
var deployData = new
{
trainedModelLabel = "Sample5",
};

Operation<BinaryData> deployOperation = await client.DeployProjectAsync(WaitUntil.Started, projectName, "production", RequestContent.Create(deployData));
await deployOperation.WaitForCompletionAsync();
Console.WriteLine($"Deploying project {projectName} to production...");
Operation<BinaryData> deployOperation = await client.DeployProjectAsync(
WaitUntil.Started,
projectName,
"production",
RequestContent.Create(deployData));

Console.WriteLine("Import complete");
```
Loading

0 comments on commit 95fb684

Please sign in to comment.