Skip to content

Commit 608ce6c

Browse files
authored
[CLU March Preview] Tests (Azure#23524)
* add swagger.md * generate client * update swagger.md * regenerate client * samples - add conversation project sample * tmp commit * update conversations samples in both conversations and orchestration projects * update samples * update sync samples * update samples - file names and secrets * update samples readme * add async samples * update async samples * update samples * add some tests * add qna test * add async tests * update tests * update tests * fix sync tests * fixed async tests * add recorded tests * update changelog * rename body to task * update samples * update conversation samples * fix rebase * re-record tests * update samples to use input models * update and re-record tests * update swagger reference * rename confidence score * update samples * updating samples for extra info * update readme
1 parent 877b65a commit 608ce6c

File tree

71 files changed

+4086
-3885
lines changed

Some content is hidden

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

71 files changed

+4086
-3885
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release History
22

3+
## 1.0.0b3 (2022-03-01)
4+
5+
### Features Added
6+
* Entity resolutions
7+
* Extra features
8+
9+
### Breaking Changes
10+
Input and output structures are different from previous release.
11+
312
## 1.0.0b2 (Unreleased)
413

514
### Features Added

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

Lines changed: 96 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The `azure-ai-language-conversation` client library provides both synchronous an
6767

6868
The following examples show common scenarios using the `client` [created above](#create-conversationanalysisclient).
6969

70-
### Analyze a conversation with a Conversation App
70+
### Analyze Text with a Conversation App
7171
If you would like to extract custom intents and entities from a user utterance, you can call the `client.analyze_conversations()` method with your conversation's project name as follows:
7272

7373
```python
@@ -76,45 +76,68 @@ import os
7676
from azure.core.credentials import AzureKeyCredential
7777

7878
from azure.ai.language.conversations import ConversationAnalysisClient
79-
from azure.ai.language.conversations.models import ConversationAnalysisOptions
79+
from azure.ai.language.conversations.models import (
80+
CustomConversationalTask,
81+
ConversationAnalysisOptions,
82+
CustomConversationTaskParameters,
83+
TextConversationItem
84+
)
8085

8186
# get secrets
82-
conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
83-
conv_key = os.environ["AZURE_CONVERSATIONS_KEY"]
84-
conv_project = os.environ["AZURE_CONVERSATIONS_PROJECT"]
85-
86-
# prepare data
87-
query = "One california maki please."
88-
input = ConversationAnalysisOptions(
89-
query=query
90-
)
87+
clu_endpoint = os.environ["AZURE_CLU_ENDPOINT"]
88+
clu_key = os.environ["AZURE_CLU_KEY"]
89+
project_name = os.environ["AZURE_CLU_CONVERSATIONS_PROJECT_NAME"]
90+
deployment_name = os.environ["AZURE_CLU_CONVERSATIONS_DEPLOYMENT_NAME"]
9191

9292
# analyze quey
93-
client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key))
93+
client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_key))
9494
with client:
95-
result = client.analyze_conversations(
96-
input,
97-
project_name=conv_project,
98-
deployment_name='production'
99-
)
95+
query = "Send an email to Carol about the tomorrow's demo"
96+
result = client.analyze_conversation(
97+
task=CustomConversationalTask(
98+
analysis_input=ConversationAnalysisOptions(
99+
conversation_item=TextConversationItem(
100+
id=1,
101+
participant_id=1,
102+
text=query
103+
)
104+
),
105+
parameters=CustomConversationTaskParameters(
106+
project_name=project_name,
107+
deployment_name=deployment_name
108+
)
109+
)
110+
)
100111

101112
# view result
102-
print("query: {}".format(result.query))
103-
print("project kind: {}\n".format(result.prediction.project_kind))
104-
105-
print("view top intent:")
106-
print("\ttop intent: {}".format(result.prediction.top_intent))
107-
print("\tcategory: {}".format(result.prediction.intents[0].category))
108-
print("\tconfidence score: {}\n".format(result.prediction.intents[0].confidence_score))
109-
110-
print("view entities:")
111-
for entity in result.prediction.entities:
112-
print("\tcategory: {}".format(entity.category))
113-
print("\ttext: {}".format(entity.text))
114-
print("\tconfidence score: {}".format(entity.confidence_score))
113+
print("query: {}".format(result.results.query))
114+
print("project kind: {}\n".format(result.results.prediction.project_kind))
115+
116+
print("top intent: {}".format(result.results.prediction.top_intent))
117+
print("category: {}".format(result.results.prediction.intents[0].category))
118+
print("confidence score: {}\n".format(result.results.prediction.intents[0].confidence))
119+
120+
print("entities:")
121+
for entity in result.results.prediction.entities:
122+
print("\ncategory: {}".format(entity.category))
123+
print("text: {}".format(entity.text))
124+
print("confidence score: {}".format(entity.confidence))
125+
if entity.resolutions:
126+
print("resolutions")
127+
for resolution in entity.resolutions:
128+
print("kind: {}".format(resolution.resolution_kind))
129+
print("value: {}".format(resolution.additional_properties["value"]))
130+
if entity.extra_information:
131+
print("extra info")
132+
for data in entity.extra_information:
133+
print("kind: {}".format(data.extra_information_kind))
134+
if data.extra_information_kind == "ListKey":
135+
print("key: {}".format(data.key))
136+
if data.extra_information_kind == "EntitySubtype":
137+
print("value: {}".format(data.value))
115138
```
116139

117-
### Analyze conversation with a Orchestration App
140+
### Analyze Text with an Orchestration App
118141

119142
If you would like to pass the user utterance to your orchestrator (worflow) app, you can call the `client.analyze_conversations()` method with your orchestration's project name. The orchestrator project simply orchestrates the submitted user utterance between your language apps (Luis, Conversation, and Question Answering) to get the best response according to the user intent. See the next example:
120143

@@ -124,98 +147,58 @@ import os
124147
from azure.core.credentials import AzureKeyCredential
125148

126149
from azure.ai.language.conversations import ConversationAnalysisClient
127-
from azure.ai.language.conversations.models import ConversationAnalysisOptions
128-
129-
# get secrets
130-
conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
131-
conv_key = os.environ["AZURE_CONVERSATIONS_KEY"]
132-
orchestration_project = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT")
133-
134-
# prepare data
135-
query = "How do you make sushi rice?",
136-
input = ConversationAnalysisOptions(
137-
query=query
150+
from azure.ai.language.conversations.models import (
151+
CustomConversationalTask,
152+
ConversationAnalysisOptions,
153+
CustomConversationTaskParameters,
154+
TextConversationItem
138155
)
139156

140-
# analyze query
141-
client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key))
142-
with client:
143-
result = client.analyze_conversations(
144-
input,
145-
project_name=orchestration_project,
146-
deployment_name='production',
147-
)
148-
149-
# view result
150-
print("query: {}".format(result.query))
151-
print("project kind: {}\n".format(result.prediction.project_kind))
152-
153-
print("view top intent:")
154-
print("\ttop intent: {}".format(result.prediction.top_intent))
155-
print("\tcategory: {}".format(result.prediction.intents[0].category))
156-
print("\tconfidence score: {}\n".format(result.prediction.intents[0].confidence_score))
157-
158-
print("view Question Answering result:")
159-
print("\tresult: {}\n".format(result.prediction.intents[0].result))
160-
```
161-
162-
### Analyze conversation with a Orchestration (Direct) App
163-
164-
If you would like to use an orchestrator (orchestration) app, and you want to call a specific one of your language apps directly, you can call the `client.analyze_conversations()` method with your orchestration's project name and the diirect target name which corresponds to your one of you language apps as follows:
165-
166-
```python
167-
# import libraries
168-
import os
169-
from azure.core.credentials import AzureKeyCredential
170-
171-
from azure.ai.language.conversations import ConversationAnalysisClient
172-
from azure.ai.language.conversations.models import ConversationAnalysisOptions
173-
174157
# get secrets
175-
conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
176-
conv_key = os.environ["AZURE_CONVERSATIONS_KEY"]
177-
orchestration_project = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT")
178-
179-
# prepare data
180-
query = "How do you make sushi rice?",
181-
target_intent = "SushiMaking"
182-
input = ConversationAnalysisOptions(
183-
query=query,
184-
direct_target=target_intent,
185-
parameters={
186-
"SushiMaking": QuestionAnsweringParameters(
187-
calling_options={
188-
"question": query,
189-
"top": 1,
190-
"confidenceScoreThreshold": 0.1
191-
}
192-
)
193-
}
194-
)
158+
clu_endpoint = os.environ["AZURE_CLU_ENDPOINT"]
159+
clu_key = os.environ["AZURE_CLU_KEY"]
160+
project_name = os.environ["AZURE_CLU_ORCHESTRATION_PROJECT_NAME"]
161+
deployment_name = os.environ["AZURE_CLU_ORCHESTRATION_DEPLOYMENT_NAME"]
195162

196163
# analyze query
197-
client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key))
164+
client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_key))
198165
with client:
199-
result = client.analyze_conversations(
200-
input,
201-
project_name=orchestration_project,
202-
deployment_name='production',
203-
)
166+
query = "How are you?"
167+
result = client.analyze_conversation(
168+
task=CustomConversationalTask(
169+
analysis_input=ConversationAnalysisOptions(
170+
conversation_item=TextConversationItem(
171+
id=1,
172+
participant_id=1,
173+
text=query
174+
)
175+
),
176+
parameters=CustomConversationTaskParameters(
177+
project_name=project_name,
178+
deployment_name=deployment_name
179+
)
180+
)
181+
)
204182

205183
# view result
206-
print("query: {}".format(result.query))
207-
print("project kind: {}\n".format(result.prediction.project_kind))
208-
209-
print("view top intent:")
210-
print("\ttop intent: {}".format(result.prediction.top_intent))
211-
print("\tcategory: {}".format(result.prediction.intents[0].category))
212-
print("\tconfidence score: {}\n".format(result.prediction.intents[0].confidence_score))
213-
214-
print("view Question Answering result:")
215-
print("\tresult: {}\n".format(result.prediction.intents[0].result))
184+
print("query: {}".format(result.results.query))
185+
print("project kind: {}\n".format(result.results.prediction.project_kind))
186+
187+
# top intent
188+
top_intent = result.results.prediction.top_intent
189+
print("top intent: {}".format(top_intent))
190+
top_intent_object = result.results.prediction.intents[top_intent]
191+
print("confidence score: {}".format(top_intent_object.confidence))
192+
print("project kind: {}".format(top_intent_object.target_kind))
193+
194+
if top_intent_object.target_kind == "question_answering":
195+
print("\nview qna result:")
196+
qna_result = top_intent_object.result
197+
for answer in qna_result.answers:
198+
print("\nanswer: {}".format(answer.answer))
199+
print("answer: {}".format(answer.confidence))
216200
```
217201

218-
219202
## Optional Configuration
220203

221204
Optional keyword arguments can be passed in at the client and per-operation level. The azure-core [reference documentation][azure_core_ref_docs] describes available configurations for retries, logging, transport protocols, and more.

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
__version__ = VERSION
1313
__all__ = ['ConversationAnalysisClient']
1414

15-
try:
16-
from ._patch import patch_sdk # type: ignore
17-
patch_sdk()
18-
except ImportError:
19-
pass
15+
# `._patch.py` is used for handwritten extensions to the generated code
16+
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
17+
from ._patch import patch_sdk
18+
patch_sdk()

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,48 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from typing import TYPE_CHECKING
9+
from typing import Any
1010

1111
from azure.core.configuration import Configuration
12+
from azure.core.credentials import AzureKeyCredential
1213
from azure.core.pipeline import policies
1314

1415
from ._version import VERSION
1516

16-
if TYPE_CHECKING:
17-
# pylint: disable=unused-import,ungrouped-imports
18-
from typing import Any
1917

20-
from azure.core.credentials import AzureKeyCredential
21-
22-
23-
class ConversationAnalysisClientConfiguration(Configuration):
18+
class ConversationAnalysisClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
2419
"""Configuration for ConversationAnalysisClient.
2520
2621
Note that all parameters used to create this instance are saved as instance
2722
attributes.
2823
29-
:param endpoint: Supported Cognitive Services endpoint (e.g., https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
24+
:param endpoint: Supported Cognitive Services endpoint (e.g.,
25+
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
3026
:type endpoint: str
3127
:param credential: Credential needed for the client to connect to Azure.
3228
:type credential: ~azure.core.credentials.AzureKeyCredential
29+
:keyword api_version: Api Version. Default value is "2022-03-01-preview". Note that overriding
30+
this default value may result in unsupported behavior.
31+
:paramtype api_version: str
3332
"""
3433

3534
def __init__(
3635
self,
37-
endpoint, # type: str
38-
credential, # type: AzureKeyCredential
39-
**kwargs # type: Any
40-
):
41-
# type: (...) -> None
36+
endpoint: str,
37+
credential: AzureKeyCredential,
38+
**kwargs: Any
39+
) -> None:
40+
super(ConversationAnalysisClientConfiguration, self).__init__(**kwargs)
41+
api_version = kwargs.pop('api_version', "2022-03-01-preview") # type: str
42+
4243
if endpoint is None:
4344
raise ValueError("Parameter 'endpoint' must not be None.")
4445
if credential is None:
4546
raise ValueError("Parameter 'credential' must not be None.")
46-
super(ConversationAnalysisClientConfiguration, self).__init__(**kwargs)
4747

4848
self.endpoint = endpoint
4949
self.credential = credential
50-
self.api_version = "2021-11-01-preview"
50+
self.api_version = api_version
5151
kwargs.setdefault('sdk_moniker', 'ai-language-conversations/{}'.format(VERSION))
5252
self._configure(**kwargs)
5353

0 commit comments

Comments
 (0)