def test_conversation_app(self, conv_account, conv_key, conv_project): # prepare data query = "One california maki please." input = ConversationAnalysisOptions( query=query, ) # analyze quey client = ConversationAnalysisClient(conv_account, AzureKeyCredential(conv_key)) with client: result = client.analyze_conversations( input, project_name=conv_project, deployment_name='production' ) # assert assert isinstance(result, AnalyzeConversationResult) assert result.query == query assert isinstance(result.prediction, ConversationPrediction) assert result.prediction.project_kind == 'conversation' assert result.prediction.top_intent == 'Order' assert len(result.prediction.entities) > 0 assert len(result.prediction.intents) > 0 assert result.prediction.intents[0].category == 'Order' assert result.prediction.intents[0].confidence_score > 0 assert result.prediction.entities[0].category == 'OrderItem' assert result.prediction.entities[0].text == 'california maki' assert result.prediction.entities[0].confidence_score > 0
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))
async def sample_analyze_orchestration_app_with_params_async(): # [START analyze_orchestration_app_with_params] # 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 ( ConversationAnalysisOptions, QuestionAnsweringParameters, ConversationParameters, ) # get secrets conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"] conv_key = os.environ["AZURE_CONVERSATIONS_KEY"] orchestration_project = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT"] # prepare data query = "How do you make sushi rice?", input = ConversationAnalysisOptions( query=query, parameters={ "SushiMaking": QuestionAnsweringParameters(calling_options={ "question": query, "top": 1, "confidenceScoreThreshold": 0.1 }), "SushiOrder": ConversationParameters(calling_options={"verbose": True}) }) # analyze query client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key)) async with client: result = await client.analyze_conversations( input, project_name=orchestration_project, deployment_name='production', ) # view result print("query: {}".format(result.query)) print("project kind: {}\n".format(result.prediction.project_kind)) print("view top intent:") top_intent = result.prediction.top_intent print("\ttop intent: {}".format(top_intent)) top_intent_object = result.prediction.intents[top_intent] print("\tconfidence score: {}\n".format( top_intent_object.confidence_score)) print("view Question Answering result:") print("\tresult: {}\n".format(top_intent_object.result))
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 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 ConversationAnalysisOptions # get secrets conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"] conv_key = os.environ["AZURE_CONVERSATIONS_KEY"] orchestration_project = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT"] # prepare data query = "How do you make sushi rice?", input = ConversationAnalysisOptions(query=query) # analyze query client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key)) async with client: result = await client.analyze_conversations( input, project_name=orchestration_project, deployment_name='production', ) # view result print("query: {}".format(result.query)) print("project kind: {}\n".format(result.prediction.project_kind)) print("view top intent:") top_intent = result.prediction.top_intent print("\ttop intent: {}".format(top_intent)) top_intent_object = result.prediction.intents[top_intent] print("\tconfidence score: {}\n".format( top_intent_object.confidence_score)) print("view qna result:") qna_result = result.prediction.intents[top_intent].result for answer in qna_result.answers: print("\tanswer: {}\n".format(answer.answer))
def sample_analyze_orchestration_app_luis_response(): # [START analyze_orchestration_app_luis_response] # import libraries import os from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations import ConversationAnalysisClient from azure.ai.language.conversations.models import ConversationAnalysisOptions # get secrets conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"] conv_key = os.environ["AZURE_CONVERSATIONS_KEY"] orchestration_project = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT"] # prepare data query = "book me a flight ticket to Bali", input = ConversationAnalysisOptions(query=query) # analyze query client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key)) with client: result = client.analyze_conversations( input, project_name=orchestration_project, deployment_name='production', ) # view result print("query: {}".format(result.query)) print("project kind: {}\n".format(result.prediction.project_kind)) print("view top intent:") top_intent = result.prediction.top_intent print("\ttop intent: {}".format(top_intent)) top_intent_object = result.prediction.intents[top_intent] print("\tconfidence score: {}\n".format( top_intent_object.confidence_score)) print("view luis response:") luis_response = result.prediction.intents[top_intent].result print("\tluis response: {}\n".format(luis_response))
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 ConversationAnalysisOptions # get secrets conv_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"] conv_key = os.environ["AZURE_CONVERSATIONS_KEY"] conv_project = os.environ["AZURE_CONVERSATIONS_PROJECT"] # prepare data query = "One california maki please." input = ConversationAnalysisOptions(query=query) # analyze quey client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key)) with client: result = client.analyze_conversations(input, project_name=conv_project, deployment_name='production') # view result print("query: {}".format(result.query)) print("project kind: {}\n".format(result.prediction.project_kind)) print("view top intent:") print("\ttop intent: {}".format(result.prediction.top_intent)) print("\tcategory: {}".format(result.prediction.intents[0].category)) print("\tconfidence score: {}\n".format( result.prediction.intents[0].confidence_score)) print("view entities:") for entity in result.prediction.entities: print("\tcategory: {}".format(entity.category)) print("\ttext: {}".format(entity.text)) print("\tconfidence score: {}".format(entity.confidence_score))
def test_orchestration_app_with_parameters(self, conv_account, conv_key, orchestration_project): # prepare data query = "How do you make sushi rice?", input = ConversationAnalysisOptions( query=query, parameters={ "SushiMaking": QuestionAnsweringParameters( calling_options={ "question": query, "top": 1, "confidenceScoreThreshold": 0.1 } ), "SushiOrder": ConversationParameters( calling_options={ "verbose": True } ) } ) # analyze query client = ConversationAnalysisClient(conv_account, AzureKeyCredential(conv_key)) with client: result = client.analyze_conversations( input, project_name=orchestration_project, deployment_name='production', ) # assert top_intent = "SushiMaking" assert isinstance(result, AnalyzeConversationResult) # assert result.query == query --> weird behavior here! assert isinstance(result.prediction, OrchestratorPrediction) assert result.prediction.project_kind == "workflow" assert result.prediction.top_intent == top_intent assert isinstance(result.prediction.intents[top_intent], QuestionAnsweringTargetIntentResult)
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