Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-11-15-preview and 2024-11-01 updates for Conversations Runtime #47814

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a97f873
Updated the dotnet sdk based on the new commit
amber-ccc Jan 10, 2025
53fd53e
- adjust test examples based on the new generated sdk
amber-ccc Jan 13, 2025
52430f3
Merge branch 'Azure:main' into amber/release_new_beta_for_Conversatio…
amber-ccc Jan 13, 2025
4eb9eaa
updated samples and snippets
amber-ccc Jan 13, 2025
903eeae
Merge branch 'amber/release_new_beta_for_Conversations_runtime' of ht…
amber-ccc Jan 13, 2025
ad5cf52
updated code based on new commit id
amber-ccc Jan 13, 2025
49d0766
modified the ChangeLog
amber-ccc Jan 13, 2025
c036a00
remove breaking changes and Bugs Fixed sections
amber-ccc Jan 13, 2025
476e070
update sdk based on the latest commit id
amber-ccc Jan 27, 2025
60723fd
updated class name based on new commit id
amber-ccc Jan 27, 2025
e9c770f
updated the snippets
amber-ccc Jan 27, 2025
799370d
add one more version 2024-11-01 in TestBase and add test for Conversa…
amber-ccc Jan 28, 2025
f4fa80b
Merge branch 'Azure:main' into amber/release_new_beta_for_Conversatio…
amber-ccc Jan 28, 2025
642d2a5
-adjust the version to 2024-11-01 in the test
amber-ccc Jan 28, 2025
01ab95d
Modified the assertion in conversation pii test with MaskPolicyType
amber-ccc Jan 29, 2025
bb03610
add async test for ConversationPii_WithCharacterMaskPolicy
amber-ccc Jan 29, 2025
5a5b47f
add sync and async test for ConversationPii_WithEntityMaskPolicy
amber-ccc Jan 29, 2025
764f8dc
add sync and async test for ConversationPii_WithNoMaskPolicy
amber-ccc Jan 29, 2025
e92b9ba
revert ConversationsClientLiveTests
amber-ccc Jan 29, 2025
1b4f375
modify new test data for previous tests
amber-ccc Jan 30, 2025
76b8518
revert previous tests to main version.
amber-ccc Jan 30, 2025
24a6cda
testing
amber-ccc Jan 30, 2025
9b5ff79
Merge branch 'Azure:main' into amber/release_new_beta_for_Conversatio…
amber-ccc Jan 30, 2025
9cb4d0d
test for authentication
amber-ccc Jan 30, 2025
ea99fb1
- update the assets.json
amber-ccc Jan 30, 2025
9d25873
update recording for some old version apis
amber-ccc Jan 30, 2025
612253f
update assets.json
amber-ccc Jan 31, 2025
ad39cbf
Succesfully run all the local tests and update the assets.json
amber-ccc Jan 31, 2025
9eca5be
adding new tests to clientLiveTests and update assets.json
amber-ccc Jan 31, 2025
66a6fde
remove the duplicate snippets
amber-ccc Feb 3, 2025
b9cc497
update some remaining test recordings to 2024-11-15-preview
amber-ccc Feb 3, 2025
d6bbe4f
udpate the new test for MaskWithEntity
amber-ccc Feb 3, 2025
5e450e5
Update the snippets for new feature tests
amber-ccc Feb 3, 2025
de6b53d
update the snippets for the general README file.
amber-ccc Feb 3, 2025
c4a94b2
updated the change log
amber-ccc Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Release History

## 2.0.0-beta.2 (Unreleased)
## 2.0.0-beta.2 (2025-02-03)

### Features Added

- Exposed `JsonModelWriteCore` for model serialization procedure.

### Breaking Changes

### Bugs Fixed
- Added three differenct type of Redaction Policy `CharacterMaskPolicyType`, `EntityMaskTypePolicyType` and `NoMaskPolicyType` for the function `AnalyzeConversations`
- Added support for analyze-conversation API Versions
- 2024-11-01
- 2024-11-15-preview

### Other Changes

- Changed property `CreditCardNumberValue` to `CreditCardValue` and `PhoneNumberValue` to `PhoneValue` for class `ConversationPiiCategoryExclusions`
- Added a new `Instruction` property to class `ConversationSummarizationActionContent`

## 2.0.0-beta.1 (2024-08-01)

- Added support for service version 2024-05-01.
Expand Down
219 changes: 219 additions & 0 deletions sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,225 @@ foreach (AnalyzeConversationOperationResult operationResult in operationState.Ac
}
```

### Extract PII from a conversation With Character Mask Policy

To detect and redact PII in a conversation using Character Mask Policy, you can use the `AnalyzeConversationsAsync` method overload with an action of type `PiiOperationAction` and utilize `CharacterMaskPolicyType` to define the RedactionCharacter (e.g., an asterisk *) to replace sensitive information. The method returns a `Response<AnalyzeConversationOperationState>`::

```C# Snippet:AnalyzeConversation_ConversationPiiWithCharacterMaskPolicy
var redactionPolicy = new CharacterMaskPolicyType
{
RedactionCharacter = RedactionCharacter.Asterisk
};

// Simulate input conversation
MultiLanguageConversationInput input = new MultiLanguageConversationInput(
new List<ConversationInput>
{
new TextConversation("1", "en", new List<TextConversationItem>
{
new TextConversationItem(id: "1", participantId: "Agent_1", text: "Can you provide your name?"),
new TextConversationItem(id: "2", participantId: "Customer_1", text: "Hi, my name is John Doe."),
new TextConversationItem(id: "3", participantId: "Agent_1", text: "Thank you John, that has been updated in our system.")
})
});

// Add action with CharacterMaskPolicyType
List<AnalyzeConversationOperationAction> actions = new List<AnalyzeConversationOperationAction>
{
new PiiOperationAction
{
ActionContent = new ConversationPiiActionContent
{
RedactionPolicy = redactionPolicy
},
Name = "Conversation PII with Character Mask Policy"
}
};

// Create input for analysis
AnalyzeConversationOperationInput data = new AnalyzeConversationOperationInput(input, actions);

// Act: Perform the PII analysis
Response<AnalyzeConversationOperationState> analyzeConversationOperation = await client.AnalyzeConversationsAsync(data);
AnalyzeConversationOperationState operationState = analyzeConversationOperation.Value;
// Assert: Validate the results
foreach (AnalyzeConversationOperationResult operationResult in operationState.Actions.Items)
{
Console.WriteLine($"Operation action name: {operationResult.Name}");

if (operationResult is ConversationPiiOperationResult piiOperationResult)
{
foreach (ConversationalPiiResult conversation in piiOperationResult.Results.Conversations)
{
Console.WriteLine($"Conversation: #{conversation.Id}");
foreach (ConversationPiiItemResult item in conversation.ConversationItems)
{
string redactedText = item.RedactedContent?.Text ?? string.Empty;
Console.WriteLine($"Redacted Text: {redactedText}");

// Only verify redaction if the original sentence had PII
if (item.Entities.Any())
{
foreach (var entity in item.Entities)
{
Assert.That(redactedText, Does.Not.Contain(entity.Text),
$"Expected entity '{entity.Text}' to be redacted but found in: {redactedText}");

Assert.That(redactedText, Does.Contain("*"),
$"Expected redacted text to contain '*' but got: {redactedText}");
}
}
}
}
}
}
```

### Extract PII from a conversation With Entity Mask Policy

To detect and redact PII in a conversation using Character Mask Policy, you can use the `AnalyzeConversationsAsync` method overload with an action of type `PiiOperationAction` and utilize `EntityMaskTypePolicyType` as Mask Policy to replace sensitive information. The method returns a `Response<AnalyzeConversationOperationState>`::

```C# Snippet:AnalyzeConversation_ConversationPiiWithEntityMaskPolicy
var redactionPolicy = new EntityMaskTypePolicyType();

MultiLanguageConversationInput input = new MultiLanguageConversationInput(
new List<ConversationInput>
{
new TextConversation("1", "en", new List<TextConversationItem>
{
new TextConversationItem(id: "1", participantId: "Agent_1", text: "Can you provide your name?"),
new TextConversationItem(id: "2", participantId: "Customer_1", text: "Hi, my name is John Doe."),
new TextConversationItem(id: "3", participantId: "Agent_1", text: "Thank you John, that has been updated in our system.")
})
});

// Add action with EntityMaskTypePolicyType
List<AnalyzeConversationOperationAction> actions = new List<AnalyzeConversationOperationAction>
{
new PiiOperationAction
{
ActionContent = new ConversationPiiActionContent
{
RedactionPolicy = redactionPolicy
},
Name = "Conversation PII with Entity Mask Policy"
}
};

// Create input for analysis
AnalyzeConversationOperationInput data = new AnalyzeConversationOperationInput(input, actions);

// Act: Perform the PII analysis
Response<AnalyzeConversationOperationState> analyzeConversationOperation = await client.AnalyzeConversationsAsync(data);
AnalyzeConversationOperationState operationState = analyzeConversationOperation.Value;

// Assert: Validate the results
foreach (AnalyzeConversationOperationResult operationResult in operationState.Actions.Items)
{
Console.WriteLine($"Operation action name: {operationResult.Name}");

if (operationResult is ConversationPiiOperationResult piiOperationResult)
{
foreach (ConversationalPiiResult conversation in piiOperationResult.Results.Conversations)
{
Console.WriteLine($"Conversation: #{conversation.Id}");
foreach (ConversationPiiItemResult item in conversation.ConversationItems)
{
string redactedText = item.RedactedContent?.Text ?? string.Empty;
Console.WriteLine($"Redacted Text: {redactedText}");

// Only verify redaction if the original sentence had PII
if (item.Entities.Any())
{
foreach (var entity in item.Entities)
{
Assert.That(redactedText, Does.Not.Contain(entity.Text),
$"Expected entity '{entity.Text}' to be redacted but found in: {redactedText}");

// Case-insensitive pattern to match entity mask variations
string expectedMaskPattern = $@"\[{entity.Category}-?\d*\]";

// Perform case-insensitive regex match
StringAssert.IsMatch("(?i)" + expectedMaskPattern, redactedText,
$"Expected redacted text to contain an entity mask similar to '[{entity.Category}]' but got: {redactedText}");
}
}
}
}
}
}
```

### Extract PII from a conversation With Character Mask Policy

To detect and redact PII in a conversation using No Mask Policy, you can use the `AnalyzeConversationsAsync` method overload with an action of type `PiiOperationAction` and utilize `NoMaskPolicyType` as Mask Policy. The method returns a `Response<AnalyzeConversationOperationState>`::

```C# Snippet:AnalyzeConversation_ConversationPiiWithNoMaskPolicy
var redactionPolicy = new NoMaskPolicyType();

// Simulate input conversation
MultiLanguageConversationInput input = new MultiLanguageConversationInput(
new List<ConversationInput>
{
new TextConversation("1", "en", new List<TextConversationItem>
{
new TextConversationItem(id: "1", participantId: "Agent_1", text: "Can you provide your name?"),
new TextConversationItem(id: "2", participantId: "Customer_1", text: "Hi, my name is John Doe."),
new TextConversationItem(id: "3", participantId: "Agent_1", text: "Thank you John, that has been updated in our system.")
})
});

// Add action with NoMaskPolicyType
List<AnalyzeConversationOperationAction> actions = new List<AnalyzeConversationOperationAction>
{
new PiiOperationAction
{
ActionContent = new ConversationPiiActionContent
{
RedactionPolicy = redactionPolicy
},
Name = "Conversation PII with No Mask Policy"
}
};

// Create input for analysis
AnalyzeConversationOperationInput data = new AnalyzeConversationOperationInput(input, actions);

// Act: Perform the PII analysis
Response<AnalyzeConversationOperationState> analyzeConversationOperation = await client.AnalyzeConversationsAsync(data);
AnalyzeConversationOperationState operationState = analyzeConversationOperation.Value;

// Assert: Validate the results
foreach (AnalyzeConversationOperationResult operationResult in operationState.Actions.Items)
{
Console.WriteLine($"Operation action name: {operationResult.Name}");

if (operationResult is ConversationPiiOperationResult piiOperationResult)
{
foreach (ConversationalPiiResult conversation in piiOperationResult.Results.Conversations)
{
Console.WriteLine($"Conversation: #{conversation.Id}");
foreach (ConversationPiiItemResult item in conversation.ConversationItems)
{
string originalText = item.RedactedContent?.Text ?? string.Empty;
Console.WriteLine($"Original Text: {originalText}");

// Ensure PII is detected
if (item.Entities.Any())
{
foreach (var entity in item.Entities)
{
detectedEntities.Add(entity.Text);
Assert.That(originalText, Does.Contain(entity.Text),
$"Expected entity '{entity.Text}' to be present but was not found in: {originalText}");
}
}
}
}
}
}
```

### Additional samples

Browse our [samples][conversationanalysis_samples] for more examples of how to analyze conversations.
Expand Down
Loading