1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import pytest
from azure.ai.language.conversations import ConversationAnalysisClient
from azure.core.credentials import AzureKeyCredential
from devtools_testutils import AzureRecordedTestCase
class TestConversationalSummarization(AzureRecordedTestCase):
def test_polling_interval(self, conversation_creds):
# test default
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]))
assert client._config.polling_interval == 5
# test override
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]), polling_interval=1)
assert client._config.polling_interval == 1
def test_conversational_summarization(self, recorded_test, conversation_creds):
# analyze query
client = ConversationAnalysisClient(
conversation_creds["endpoint"],
AzureKeyCredential(conversation_creds["key"])
)
with client:
poller = client.begin_conversation_analysis(
task={
"displayName": "Analyze conversations from xxx",
"analysisInput": {
"conversations": [
{
"conversationItems": [
{
"text": "Hello, how can I help you?",
"modality": "text",
"id": "1",
"role": "Agent",
"participantId": "Agent"
},
{
"text": "How to upgrade Office? I am getting error messages the whole day.",
"modality": "text",
"id": "2",
"role": "Customer",
"participantId": "Customer"
},
{
"text": "Press the upgrade button please. Then sign in and follow the instructions.",
"modality": "text",
"id": "3",
"role": "Agent",
"participantId": "Agent"
}
],
"modality": "text",
"id": "conversation1",
"language": "en"
},
]
},
"tasks": [
{
"taskName": "Issue task",
"kind": "ConversationalSummarizationTask",
"parameters": {
"summaryAspects": ["issue"]
}
},
{
"taskName": "Resolution task",
"kind": "ConversationalSummarizationTask",
"parameters": {
"summaryAspects": ["resolution"]
}
},
]
}
)
# assert - main object
result = poller.result()
assert not result is None
assert result["status"] == "succeeded"
# assert - task result
task_result = result["tasks"]["items"][0]
assert task_result["status"] == "succeeded"
assert task_result["kind"] == "conversationalSummarizationResults"
# assert - conv result
conversation_result = task_result["results"]["conversations"][0]
summaries = conversation_result["summaries"]
assert summaries
for summary in summaries:
assert summary["aspect"] in ["issue", "resolution"]
assert summary["text"]
def test_conv_summ_chapter_narrative(self, recorded_test, conversation_creds):
# analyze query
client = ConversationAnalysisClient(
conversation_creds["endpoint"],
AzureKeyCredential(conversation_creds["key"])
)
with client:
poller = client.begin_conversation_analysis(
task={
"displayName": "Conversation Summarization Example",
"analysisInput": {
"conversations": [
{
"id": "1",
"language": "en",
"modality": "transcript",
"conversationItems": [
{
"participantId": "speaker 1",
"id": "1",
"text": "Let's get started.",
"lexical": "",
"itn": "",
"maskedItn": "",
"conversationItemLevelTiming": {
"offset": 0,
"duration": 20000000
}
},
{
"participantId": "speaker 2",
"id": "2",
"text": "OK. How many remaining bugs do we have now?",
"lexical": "",
"itn": "",
"maskedItn": "",
"conversationItemLevelTiming": {
"offset": 20000000,
"duration": 50000000
}
},
{
"participantId": "speaker 3",
"id": "3",
"text": "Only 3.",
"lexical": "",
"itn": "",
"maskedItn": "",
"conversationItemLevelTiming": {
"offset": 50000000,
"duration": 60000000
}
}
]
}
]
},
"tasks": [
{
"taskName": "Conversation Summarization Task 1",
"kind": "ConversationalSummarizationTask",
"parameters": {
"summaryAspects": [
"chapterTitle",
"narrative"
]
}
}
]
}
)
# assert - main object
result = poller.result()
assert result is not None
assert result["status"] == "succeeded"
# assert - task result
task_result = result["tasks"]["items"][0]
assert task_result["status"] == "succeeded"
assert task_result["kind"] == "conversationalSummarizationResults"
# assert - conv result
conversation_result = task_result["results"]["conversations"][0]
summaries = conversation_result["summaries"]
assert summaries
for summary in summaries:
assert summary["aspect"] in ["chapterTitle", "narrative"]
assert summary["text"]
assert summary["contexts"]
|