def test_orchestration_app_qna_response(self, endpoint, key, orch_project_name, orch_deployment_name): # analyze query client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) with client: query = "How are you?" result = client.analyze_conversation(task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query)), parameters=CustomConversationTaskParameters( project_name=orch_project_name, deployment_name=orch_deployment_name))) # assert - main object top_project = 'ChitChat-QnA' assert not result is None assert isinstance(result, CustomConversationalTaskResult) assert result.results.query == query # assert - prediction type assert isinstance(result.results.prediction, OrchestratorPrediction) assert result.results.prediction.project_kind == "workflow" # assert - top matching project assert result.results.prediction.top_intent == top_project top_intent_object = result.results.prediction.intents[top_project] assert isinstance(top_intent_object, QuestionAnsweringTargetIntentResult) assert top_intent_object.target_kind == "question_answering" # assert intent and entities qna_result = top_intent_object.result answer = qna_result.answers[0].answer assert not answer is None
async def test_conversation_app(self, endpoint, key, conv_project_name, conv_deployment_name): # analyze query client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) async with client: query = "Send an email to Carol about the tomorrow's demo" result = await client.analyze_conversation( task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query)), parameters=CustomConversationTaskParameters( project_name=conv_project_name, deployment_name=conv_deployment_name))) # assert - main object assert not result is None assert isinstance(result, CustomConversationalTaskResult) # assert - prediction type assert result.results.query == query assert isinstance(result.results.prediction, ConversationPrediction) assert result.results.prediction.project_kind == 'conversation' # assert - top intent assert result.results.prediction.top_intent == 'Read' assert len(result.results.prediction.intents) > 0 assert result.results.prediction.intents[0].category == 'Read' assert result.results.prediction.intents[0].confidence > 0 # assert - entities assert len(result.results.prediction.entities) > 0 assert result.results.prediction.entities[0].category == 'Contact' assert result.results.prediction.entities[0].text == 'Carol' assert result.results.prediction.entities[0].confidence > 0
async def sample_analyze_orchestration_app_luis_response_async(): # [START analyze_orchestration_app_luis_response_async] # import libraries import os from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations.aio import ConversationAnalysisClient from azure.ai.language.conversations.models import ( CustomConversationalTask, ConversationAnalysisOptions, CustomConversationTaskParameters, TextConversationItem ) # get secrets clu_endpoint = os.environ["AZURE_CLU_ENDPOINT"] clu_key = os.environ["AZURE_CLU_KEY"] project_name = os.environ["AZURE_CLU_ORCHESTRATION_PROJECT_NAME"] deployment_name = os.environ["AZURE_CLU_ORCHESTRATION_DEPLOYMENT_NAME"] # analyze query client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_key)) async with client: query = "Reserve a table for 2 at the Italian restaurant" result = await client.analyze_conversation( task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query ) ), parameters=CustomConversationTaskParameters( project_name=project_name, deployment_name=deployment_name ) ) ) # view result print("query: {}".format(result.results.query)) print("project kind: {}\n".format(result.results.prediction.project_kind)) # top intent top_intent = result.results.prediction.top_intent print("top intent: {}".format(top_intent)) top_intent_object = result.results.prediction.intents[top_intent] print("confidence score: {}".format(top_intent_object.confidence)) print("project kind: {}".format(top_intent_object.target_kind)) if top_intent_object.target_kind == "luis": print("\nluis response:") luis_response = top_intent_object.result["prediction"] print("top intent: {}".format(luis_response["topIntent"])) print("\nentities:") for entity in luis_response["entities"]: print("\n{}".format(entity))
def sample_analyze_conversation_app(): # [START analyze_conversation_app] # import libraries import os from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations import ConversationAnalysisClient from azure.ai.language.conversations.models import ( CustomConversationalTask, ConversationAnalysisOptions, CustomConversationTaskParameters, TextConversationItem) # get secrets clu_endpoint = os.environ["AZURE_CLU_ENDPOINT"] clu_key = os.environ["AZURE_CLU_KEY"] project_name = os.environ["AZURE_CLU_CONVERSATIONS_PROJECT_NAME"] deployment_name = os.environ["AZURE_CLU_CONVERSATIONS_DEPLOYMENT_NAME"] # analyze quey client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_key)) with client: query = "Send an email to Carol about the tomorrow's demo" result = client.analyze_conversation(task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query)), parameters=CustomConversationTaskParameters( project_name=project_name, deployment_name=deployment_name))) # view result print("query: {}".format(result.results.query)) print("project kind: {}\n".format(result.results.prediction.project_kind)) print("top intent: {}".format(result.results.prediction.top_intent)) print("category: {}".format(result.results.prediction.intents[0].category)) print("confidence score: {}\n".format( result.results.prediction.intents[0].confidence)) print("entities:") for entity in result.results.prediction.entities: print("\ncategory: {}".format(entity.category)) print("text: {}".format(entity.text)) print("confidence score: {}".format(entity.confidence)) if entity.resolutions: print("resolutions") for resolution in entity.resolutions: print("kind: {}".format(resolution.resolution_kind)) print("value: {}".format( resolution.additional_properties["value"])) if entity.extra_information: print("extra info") for data in entity.extra_information: print("kind: {}".format(data.extra_information_kind)) if data.extra_information_kind == "ListKey": print("key: {}".format(data.key)) if data.extra_information_kind == "EntitySubtype": print("value: {}".format(data.value))
async def sample_analyze_orchestration_app_qna_response_async(): # [START analyze_orchestration_app_qna_response_async] # import libraries import os from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations.aio import ConversationAnalysisClient from azure.ai.language.conversations.models import ( CustomConversationalTask, ConversationAnalysisOptions, CustomConversationTaskParameters, TextConversationItem ) # get secrets clu_endpoint = os.environ["AZURE_CLU_ENDPOINT"] clu_key = os.environ["AZURE_CLU_KEY"] project_name = os.environ["AZURE_CLU_ORCHESTRATION_PROJECT_NAME"] deployment_name = os.environ["AZURE_CLU_ORCHESTRATION_DEPLOYMENT_NAME"] # analyze query client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_key)) async with client: query = "How are you?" result = await client.analyze_conversation( task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query ) ), parameters=CustomConversationTaskParameters( project_name=project_name, deployment_name=deployment_name ) ) ) # view result print("query: {}".format(result.results.query)) print("project kind: {}\n".format(result.results.prediction.project_kind)) # top intent top_intent = result.results.prediction.top_intent print("top intent: {}".format(top_intent)) top_intent_object = result.results.prediction.intents[top_intent] print("confidence score: {}".format(top_intent_object.confidence)) print("project kind: {}".format(top_intent_object.target_kind)) if top_intent_object.target_kind == "question_answering": print("\nview qna result:") qna_result = top_intent_object.result for answer in qna_result.answers: print("\nanswer: {}".format(answer.answer)) print("answer: {}".format(answer.confidence))
def test_orchestration_app_conv_response(self, endpoint, key, orch_project_name, orch_deployment_name): # analyze query client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) with client: query = "Send an email to Carol about the tomorrow's demo" result = client.analyze_conversation( task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query ) ), parameters=CustomConversationTaskParameters( project_name=orch_project_name, deployment_name=orch_deployment_name ) ) ) # assert - main object top_project = "EmailIntent" assert not result is None assert isinstance(result, CustomConversationalTaskResult) assert result.results.query == query # assert - prediction type assert isinstance(result.results.prediction, OrchestratorPrediction) assert result.results.prediction.project_kind == "workflow" # assert - top matching project assert result.results.prediction.top_intent == top_project top_intent_object = result.results.prediction.intents[top_project] assert isinstance(top_intent_object, ConversationTargetIntentResult) assert top_intent_object.target_kind == "conversation" # assert intent and entities conversation_result = top_intent_object.result.prediction assert conversation_result.top_intent == 'SendEmail' assert len(conversation_result.intents) > 0 assert conversation_result.intents[0].category == 'SendEmail' assert conversation_result.intents[0].confidence > 0 # assert - entities assert len(conversation_result.entities) > 0 assert conversation_result.entities[0].category == 'ContactName' assert conversation_result.entities[0].text == 'Carol' assert conversation_result.entities[0].confidence > 0
async def test_orchestration_app_luis_response(self, endpoint, key, orch_project_name, orch_deployment_name): # analyze query client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) async with client: query = "Reserve a table for 2 at the Italian restaurant" result = await client.analyze_conversation( task=CustomConversationalTask( analysis_input=ConversationAnalysisOptions( conversation_item=TextConversationItem( id=1, participant_id=1, text=query)), parameters=CustomConversationTaskParameters( project_name=orch_project_name, deployment_name=orch_deployment_name))) # assert - main object top_project = "RestaurantIntent" assert not result is None assert isinstance(result, CustomConversationalTaskResult) assert result.results.query == query # assert - prediction type assert isinstance(result.results.prediction, OrchestratorPrediction) assert result.results.prediction.project_kind == "workflow" # assert - top matching project assert result.results.prediction.top_intent == top_project top_intent_object = result.results.prediction.intents[top_project] assert isinstance(top_intent_object, LUISTargetIntentResult) assert top_intent_object.target_kind == "luis" # assert intent and entities top_intent = "RestaurantReservation.Reserve" luis_result = top_intent_object.result["prediction"] assert luis_result["topIntent"] == top_intent assert len(luis_result["intents"]) > 0 assert luis_result["intents"][top_intent]["score"] > 0 # assert - entities assert len(luis_result["entities"]) > 0