Skip to content

Commit 40c0f81

Browse files
authored
CLU 1.0 GA SDK (Azure#24649)
* update autorest file and regen * update samples and tests and record * update samples readme * update changelog * update readme * update sdk version * tmp update for changelog * add convenience method * add sample "analyze query with conv app" * add remaining samples * fix patch file * add async operation * add async samples * remove convenience samples * revert _patch files * update changelog * update version and regen * remove unneccessary directives from autorest gen file * add projects autorest file * generate projects client * update autorest readme * regen clients * cherry-pick swagger readme * regen * minor fix * update changelog * update dev requirements * update shared requirements * add authoring samples * update readme * add reference to azure language portal * fix error in dev requirements arr * update changelog * ignore security warnings in _serialization files
1 parent b92ba2a commit 40c0f81

File tree

58 files changed

+16604
-2177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+16604
-2177
lines changed

sdk/cognitivelanguage/azure-ai-language-conversations/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
* Client now uses python dictionaries for method parameters and results instead of classes.
1111
* Many input and result parameter name changes in `analyze_conversation()` method
1212

13+
## 1.0.0 (Unreleased)
14+
15+
### Features Added
16+
* Added more resolution types for entities
17+
* Added support for authoring client
1318

1419
## 1.0.0b3 (2022-04-19)
1520

sdk/cognitivelanguage/azure-ai-language-conversations/README.md

Lines changed: 67 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
Conversational Language Understanding - aka **CLU** for short - is a cloud-based conversational AI service which provides many language understanding capabilities like:
55
- Conversation App: It's used in extracting intents and entities in conversations
66
- Workflow app: Acts like an orchestrator to select the best candidate to analyze conversations to get best response from apps like Qna, Luis, and Conversation App
7-
- Conversational Summarization: Used to summarize conversations in the form of issues, and final resolutions
8-
- Conversational PII: Used to extract and redact personally-identifiable info (PII)
7+
98

109
[Source code][conversationallanguage_client_src] | [Package (PyPI)][conversationallanguage_pypi_package] | [API reference documentation][api_reference_documentation] | [Product documentation][conversationallanguage_docs] | [Samples][conversationallanguage_samples]
1110

@@ -32,7 +31,7 @@ pip install azure-ai-language-conversations
3231
```
3332

3433
### Authenticate the client
35-
In order to interact with the CLU 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].
34+
In order to interact with the CLU service, you'll need to create an instance of the [ConversationAnalysisClient][conversationanalysis_client_class] class, or [ConversationAuthoringClient][conversationauthoring_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].
3635

3736
#### Get an API key
3837
You can get the **endpoint** and an **API key** from the Cognitive Services resource in the [Azure Portal][azure_portal].
@@ -56,12 +55,27 @@ credential = AzureKeyCredential("<api-key>")
5655
client = ConversationAnalysisClient(endpoint, credential)
5756
```
5857

58+
#### Create ConversationAuthoringClient
59+
Once you've determined your **endpoint** and **API key** you can instantiate a `ConversationAuthoringClient`:
60+
61+
```python
62+
from azure.core.credentials import AzureKeyCredential
63+
from azure.ai.language.conversations.authoring import ConversationAuthoringClient
64+
65+
endpoint = "https://<my-custom-subdomain>.cognitiveservices.azure.com/"
66+
credential = AzureKeyCredential("<api-key>")
67+
client = ConversationAuthoringClient(endpoint, credential)
68+
```
69+
5970

6071
## Key concepts
6172

6273
### ConversationAnalysisClient
6374
The [ConversationAnalysisClient][conversationanalysis_client_class] is the primary interface for making predictions using your deployed Conversations models. For asynchronous operations, an async `ConversationAnalysisClient` is in the `azure.ai.language.conversation.aio` namespace.
6475

76+
### ConversationAnalysisClient
77+
You can use the [ConversationAuthoringClient][conversationauthoring_client_class] to interface with the [Azure Language Portal][azure_language_portal] to carry out authoring operations on your language resource/project. For example, you can use it to create a project, populate with training data, train, test, and deploy. For asynchronous operations, an async `ConversationAnalysisClient` is in the `azure.ai.language.conversation.authoring.aio` namespace.
78+
6579
## Examples
6680
The `azure-ai-language-conversation` client library provides both synchronous and asynchronous APIs.
6781

@@ -134,7 +148,6 @@ for entity in result["result"]["prediction"]["entities"]:
134148
print("key: {}".format(data["key"]))
135149
if data["extraInformationKind"] == "EntitySubtype":
136150
print("value: {}".format(data["value"]))
137-
138151
```
139152

140153
### Analyze Text with an Orchestration App
@@ -197,198 +210,65 @@ if top_intent_object["targetProjectKind"] == "Luis":
197210
print("\nentities:")
198211
for entity in luis_response["entities"]:
199212
print("\n{}".format(entity))
200-
201213
```
202214

203-
### Conversational Summarization
204-
205-
You can use this sample if you need to summarize a conversation in the form of an issue, and final resolution. For example, a dialog from tech support:
215+
### Import a Conversation Project
216+
This sample shows a common scenario for the authoring part of the SDK
206217

207218
```python
208-
# import libraries
209219
import os
210220
from azure.core.credentials import AzureKeyCredential
221+
from azure.ai.language.conversations.authoring import ConversationAuthoringClient
211222

212-
from azure.ai.language.conversations import ConversationAnalysisClient
213-
214-
# get secrets
215-
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
216-
key = os.environ["AZURE_CONVERSATIONS_KEY"]
217-
218-
# analyze quey
219-
client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
220-
with client:
221-
poller = client.begin_conversation_analysis(
222-
task={
223-
"displayName": "Analyze conversations from xxx",
224-
"analysisInput": {
225-
"conversations": [
226-
{
227-
"conversationItems": [
228-
{
229-
"text": "Hello, how can I help you?",
230-
"modality": "text",
231-
"id": "1",
232-
"participantId": "Agent"
233-
},
234-
{
235-
"text": "How to upgrade Office? I am getting error messages the whole day.",
236-
"modality": "text",
237-
"id": "2",
238-
"participantId": "Customer"
239-
},
240-
{
241-
"text": "Press the upgrade button please. Then sign in and follow the instructions.",
242-
"modality": "text",
243-
"id": "3",
244-
"participantId": "Agent"
245-
}
246-
],
247-
"modality": "text",
248-
"id": "conversation1",
249-
"language": "en"
250-
},
251-
]
252-
},
253-
"tasks": [
254-
{
255-
"taskName": "analyze 1",
256-
"kind": "ConversationalSummarizationTask",
257-
"parameters": {
258-
"summaryAspects": ["Issue, Resolution"]
259-
}
260-
}
261-
]
262-
}
263-
)
223+
clu_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
224+
clu_key = os.environ["AZURE_CONVERSATIONS_KEY"]
264225

265-
# view result
266-
result = poller.result()
267-
task_result = result["tasks"]["items"][0]
268-
print("... view task status ...")
269-
print("status: {}".format(task_result["status"]))
270-
resolution_result = task_result["results"]
271-
if resolution_result["errors"]:
272-
print("... errors occured ...")
273-
for error in resolution_result["errors"]:
274-
print(error)
275-
else:
276-
conversation_result = resolution_result["conversations"][0]
277-
if conversation_result["warnings"]:
278-
print("... view warnings ...")
279-
for warning in conversation_result["warnings"]:
280-
print(warning)
281-
else:
282-
summaries = conversation_result["summaries"]
283-
print("... view task result ...")
284-
print("issue: {}".format(summaries[0]["text"]))
285-
print("resolution: {}".format(summaries[1]["text"]))
226+
project_name = "test_project"
227+
228+
exported_project_assets = {
229+
"projectKind": "Conversation",
230+
"intents": [{"category": "Read"}, {"category": "Delete"}],
231+
"entities": [{"category": "Sender"}],
232+
"utterances": [
233+
{
234+
"text": "Open Blake's email",
235+
"dataset": "Train",
236+
"intent": "Read",
237+
"entities": [{"category": "Sender", "offset": 5, "length": 5}],
238+
},
239+
{
240+
"text": "Delete last email",
241+
"language": "en-gb",
242+
"dataset": "Test",
243+
"intent": "Delete",
244+
"entities": [],
245+
},
246+
],
247+
}
248+
249+
client = ConversationAuthoringClient(
250+
clu_endpoint, AzureKeyCredential(clu_key)
251+
)
252+
poller = client.begin_import_project(
253+
project_name=project_name,
254+
project={
255+
"assets": exported_project_assets,
256+
"metadata": {
257+
"projectKind": "Conversation",
258+
"settings": {"confidenceThreshold": 0.7},
259+
"projectName": "EmailApp",
260+
"multilingual": True,
261+
"description": "Trying out CLU",
262+
"language": "en-us",
263+
},
264+
"projectFileVersion": "2022-05-01",
265+
},
266+
)
267+
response = poller.result()
268+
print(response)
286269

287270
```
288271

289-
### Conversational PII
290-
291-
You can use this sample if you need to extract and redact pii info from/in conversations
292-
293-
```python
294-
# import libraries
295-
import os
296-
from azure.core.credentials import AzureKeyCredential
297-
298-
from azure.ai.language.conversations import ConversationAnalysisClient
299-
300-
# get secrets
301-
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
302-
key = os.environ["AZURE_CONVERSATIONS_KEY"]
303-
304-
# analyze quey
305-
client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
306-
with client:
307-
308-
poller = client.begin_conversation_analysis(
309-
task={
310-
"displayName": "Analyze PII in conversation",
311-
"analysisInput": {
312-
"conversations": [
313-
{
314-
"conversationItems": [
315-
{
316-
"id": "1",
317-
"participantId": "0",
318-
"modality": "transcript",
319-
"text": "It is john doe.",
320-
"lexical": "It is john doe",
321-
"itn": "It is john doe",
322-
"maskedItn": "It is john doe"
323-
},
324-
{
325-
"id": "2",
326-
"participantId": "1",
327-
"modality": "transcript",
328-
"text": "Yes, 633-27-8199 is my phone",
329-
"lexical": "yes six three three two seven eight one nine nine is my phone",
330-
"itn": "yes 633278199 is my phone",
331-
"maskedItn": "yes 633278199 is my phone",
332-
},
333-
{
334-
"id": "3",
335-
"participantId": "1",
336-
"modality": "transcript",
337-
"text": "[email protected] is my email",
338-
"lexical": "j dot doe at yahoo dot com is my email",
339-
"maskedItn": "[email protected] is my email",
340-
"itn": "[email protected] is my email",
341-
}
342-
],
343-
"modality": "transcript",
344-
"id": "1",
345-
"language": "en"
346-
}
347-
]
348-
},
349-
"tasks": [
350-
{
351-
"kind": "ConversationalPIITask",
352-
"parameters": {
353-
"redactionSource": "lexical",
354-
"piiCategories": [
355-
"all"
356-
]
357-
}
358-
}
359-
]
360-
}
361-
)
362-
363-
# view result
364-
result = poller.result()
365-
task_result = result["tasks"]["items"][0]
366-
print("... view task status ...")
367-
print("status: {}".format(task_result["status"]))
368-
conv_pii_result = task_result["results"]
369-
if conv_pii_result["errors"]:
370-
print("... errors occured ...")
371-
for error in conv_pii_result["errors"]:
372-
print(error)
373-
else:
374-
conversation_result = conv_pii_result["conversations"][0]
375-
if conversation_result["warnings"]:
376-
print("... view warnings ...")
377-
for warning in conversation_result["warnings"]:
378-
print(warning)
379-
else:
380-
print("... view task result ...")
381-
for conversation in conversation_result["conversationItems"]:
382-
print("conversation id: {}".format(conversation["id"]))
383-
print("... entities ...")
384-
for entity in conversation["entities"]:
385-
print("text: {}".format(entity["text"]))
386-
print("category: {}".format(entity["category"]))
387-
print("confidence: {}".format(entity["confidenceScore"]))
388-
print("offset: {}".format(entity["offset"]))
389-
print("length: {}".format(entity["length"]))
390-
391-
```
392272

393273
## Optional Configuration
394274

@@ -475,5 +355,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
475355
[conversationallanguage_docs]: https://docs.microsoft.com/azure/cognitive-services/language-service/conversational-language-understanding/overview
476356
[conversationallanguage_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-conversations/samples/README.md
477357
[conversationanalysis_client_class]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-conversations/latest/azure.ai.language.conversations.html#azure.ai.language.conversations.ConversationAnalysisClient
358+
[conversationauthoring_client_class]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-conversations/latest/azure.ai.language.conversations.html#azure.ai.language.conversations.ConversationAuthoringClient
478359
[azure_core_exceptions]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
360+
[azure_language_portal]: https://language.cognitive.azure.com/home
479361
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fsdk%2Ftemplate%2Fazure-template%2FREADME.png)

sdk/cognitivelanguage/azure-ai-language-conversations/azure/ai/language/conversations/_client.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
from copy import deepcopy
1010
from typing import Any, TYPE_CHECKING
1111

12-
from msrest import Deserializer, Serializer
13-
1412
from azure.core import PipelineClient
1513
from azure.core.credentials import AzureKeyCredential
1614
from azure.core.rest import HttpRequest, HttpResponse
1715

1816
from ._configuration import ConversationAnalysisClientConfiguration
1917
from ._operations import ConversationAnalysisClientOperationsMixin
18+
from ._serialization import Deserializer, Serializer
2019

2120
if TYPE_CHECKING:
2221
# pylint: disable=unused-import,ungrouped-imports
2322
from typing import Dict
2423

25-
class ConversationAnalysisClient(ConversationAnalysisClientOperationsMixin):
24+
class ConversationAnalysisClient(ConversationAnalysisClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
2625
"""The language service conversations API is a suite of natural language processing (NLP) skills
2726
that can be used to analyze structured conversations (textual or spoken). The synchronous API
2827
in this suite accepts a request and mediates among multiple language projects, such as LUIS
@@ -35,15 +34,13 @@ class ConversationAnalysisClient(ConversationAnalysisClientOperationsMixin):
3534
Summarization and Conversational PII detection.
3635
3736
:param endpoint: Supported Cognitive Services endpoint (e.g.,
38-
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
37+
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
3938
:type endpoint: str
40-
:param credential: Credential needed for the client to connect to Azure.
39+
:param credential: Credential needed for the client to connect to Azure. Required.
4140
:type credential: ~azure.core.credentials.AzureKeyCredential
42-
:keyword api_version: Api Version. Default value is "2022-05-15-preview". Note that overriding
43-
this default value may result in unsupported behavior.
41+
:keyword api_version: Api Version. Default value is "2022-05-01". Note that overriding this
42+
default value may result in unsupported behavior.
4443
:paramtype api_version: str
45-
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
46-
Retry-After header is present.
4744
"""
4845

4946
def __init__(
@@ -74,7 +71,7 @@ def send_request(
7471
>>> response = client.send_request(request)
7572
<HttpResponse: 200 OK>
7673
77-
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
74+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
7875
7976
:param request: The network request you want to make. Required.
8077
:type request: ~azure.core.rest.HttpRequest

sdk/cognitivelanguage/azure-ai-language-conversations/azure/ai/language/conversations/_configuration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class ConversationAnalysisClientConfiguration(Configuration): # pylint: disable
2222
attributes.
2323
2424
:param endpoint: Supported Cognitive Services endpoint (e.g.,
25-
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
25+
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
2626
:type endpoint: str
27-
:param credential: Credential needed for the client to connect to Azure.
27+
:param credential: Credential needed for the client to connect to Azure. Required.
2828
:type credential: ~azure.core.credentials.AzureKeyCredential
29-
:keyword api_version: Api Version. Default value is "2022-05-15-preview". Note that overriding
30-
this default value may result in unsupported behavior.
29+
:keyword api_version: Api Version. Default value is "2022-05-01". Note that overriding this
30+
default value may result in unsupported behavior.
3131
:paramtype api_version: str
3232
"""
3333

@@ -38,7 +38,7 @@ def __init__(
3838
**kwargs: Any
3939
) -> None:
4040
super(ConversationAnalysisClientConfiguration, self).__init__(**kwargs)
41-
api_version = kwargs.pop('api_version', "2022-05-15-preview") # type: str
41+
api_version = kwargs.pop('api_version', "2022-05-01") # type: str
4242

4343
if endpoint is None:
4444
raise ValueError("Parameter 'endpoint' must not be None.")

0 commit comments

Comments
 (0)