async def test_luis_intent(self, conv_account, conv_key,
                               orchestration_project):

        # prepare data
        query = "I will have the oyako donburi please."
        target_intent = "SushiOrder"
        client = ConversationAnalysisClient(conv_account,
                                            AzureKeyCredential(conv_key))
        input = AnalysisParameters(
            query=query,
            direct_target=target_intent,
            parameters={
                # "SushiOrder": ConversationParameters(
                #     calling_options={
                #        "verbose": True,
                #     }
                # )
            })

        # analyze query
        async with client:
            result = await client.analyze_conversations(
                input,
                project_name=orchestration_project,
                deployment_name='production',
            )

        # assert
        assert isinstance(result, AnalyzeConversationResult)
        assert result.query == query
        # assert isinstance(result.prediction, OrchestratorPrediction)
        assert result.prediction.project_kind == "workflow"
        assert result.prediction.top_intent == target_intent
    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 test_kb_intent_with_model(self, conv_account, conv_key,
                                        orchestration_project):

        # prepare data
        query = "How do you make sushi rice?"
        target_intent = "SushiMaking"
        input = AnalysisParameters(
            query=query,
            direct_target=target_intent,
            parameters={
                "SushiMaking":
                QuestionAnsweringParameters(calling_options={
                    "question": query,
                    "top": 1,
                    "confidenceScoreThreshold": 0.1
                })
            })

        # analyze query
        client = ConversationAnalysisClient(conv_account,
                                            AzureKeyCredential(conv_key))
        async with client:
            result = await client.analyze_conversations(
                input,
                project_name=orchestration_project,
                deployment_name='production',
            )

        # assert
        assert isinstance(result, AnalyzeConversationResult)
        assert result.query == query
        # assert isinstance(result.prediction, OrchestratorPrediction)
        assert result.prediction.project_kind == "workflow"
        assert result.prediction.top_intent == target_intent
Esempio n. 4
0
    async def test_conversation_app_with_dictparams(self, conv_account,
                                                    conv_key, conv_project):

        # prepare data
        query = "One california maki please."
        params = {
            "query": query,
        }

        # analyze quey
        client = ConversationAnalysisClient(conv_account,
                                            AzureKeyCredential(conv_key))
        async with client:
            result = await client.analyze_conversations(
                params,
                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
Esempio n. 5
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))
Esempio n. 6
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 (
        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_authentication_api_key_async():
    # [START create_clu_client_with_key_async]
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    key = os.environ["AZURE_CONVERSATIONS_KEY"]

    clu_client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
async def sample_analyze_orchestration_app_luis_response_async():
    # [START analyze_orchestration_app_luis_response]
    # import libraries
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    # get secrets
    clu_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    clu_key = os.environ["AZURE_CONVERSATIONS_KEY"]
    project_name = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT_NAME"]
    deployment_name = os.environ["AZURE_CONVERSATIONS_WORKFLOW_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={
                "kind": "Conversation",
                "analysisInput": {
                    "conversationItem": {
                        "participantId": "1",
                        "id": "1",
                        "modality": "text",
                        "language": "en",
                        "text": query
                    },
                    "isLoggingEnabled": False
                },
                "parameters": {
                    "projectName": project_name,
                    "deploymentName": deployment_name,
                    "verbose": True
                }
            }
        )

    # view result
    print("query: {}".format(result["result"]["query"]))
    print("project kind: {}\n".format(result["result"]["prediction"]["projectKind"]))

    # top intent
    top_intent = result["result"]["prediction"]["topIntent"]
    print("top intent: {}".format(top_intent))
    top_intent_object = result["result"]["prediction"]["intents"][top_intent]
    print("confidence score: {}".format(top_intent_object["confidenceScore"]))
    print("project kind: {}".format(top_intent_object["targetProjectKind"]))

    if top_intent_object["targetProjectKind"] == "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))
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))
    async def test_orchestration_app_conv_response(self, endpoint, key, orch_project_name, orch_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={
                    "kind": "Conversation",
                    "analysisInput": {
                        "conversationItem": {
                            "participantId": "1",
                            "id": "1",
                            "modality": "text",
                            "language": "en",
                            "text": query
                        },
                        "isLoggingEnabled": False
                    },
                    "parameters": {
                        "projectName": orch_project_name,
                        "deploymentName": orch_deployment_name,
                        "verbose": True
                    }
                }
            )
        
            # assert - main object
            top_project = "EmailIntent"
            assert not result is None
            assert result["kind"] == "ConversationResult"
            assert result["result"]["query"] == query
            
            # assert - prediction type
            assert result["result"]["prediction"]["projectKind"] == "Orchestration"
            
            # assert - top matching project
            assert result["result"]["prediction"]["topIntent"] == top_project
            top_intent_object = result["result"]["prediction"]["intents"][top_project]
            assert top_intent_object["targetProjectKind"] == "Conversation"
            
            # assert intent and entities
            conversation_result = top_intent_object["result"]["prediction"]
            assert conversation_result["topIntent"] == 'Setup'
            assert len(conversation_result["intents"]) > 0
            assert conversation_result["intents"][0]["category"] == 'Setup'
            assert conversation_result["intents"][0]["confidenceScore"] > 0
            
            # assert - entities
            assert len(conversation_result["entities"]) > 0
            assert conversation_result["entities"][0]["category"] == 'Contact'
            assert conversation_result["entities"][0]["text"] == 'Carol'
            assert conversation_result["entities"][0]["confidenceScore"] > 0
    async def test_orchestration_app_qna_response(self, endpoint, key,
                                                  orch_project_name,
                                                  orch_deployment_name):

        # analyze query
        client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
        async with client:
            query = "How are you?"
            result = await client.analyze_conversation(
                task={
                    "kind": "Conversation",
                    "analysisInput": {
                        "conversationItem": {
                            "participantId": "1",
                            "id": "1",
                            "modality": "text",
                            "language": "en",
                            "text": query
                        },
                        "isLoggingEnabled": False
                    },
                    "parameters": {
                        "projectName": orch_project_name,
                        "deploymentName": orch_deployment_name,
                        "verbose": True
                    }
                })

            # assert - main object
            top_project = 'ChitChat-QnA'
            assert not result is None
            assert result["kind"] == "ConversationResult"
            assert result["result"]["query"] == query

            # assert - prediction type
            assert result["result"]["prediction"][
                "projectKind"] == "Orchestration"

            # assert - top matching project
            assert result["result"]["prediction"]["topIntent"] == top_project
            top_intent_object = result["result"]["prediction"]["intents"][
                top_project]
            assert top_intent_object[
                "targetProjectKind"] == "QuestionAnswering"

            # assert intent and entities
            qna_result = top_intent_object["result"]
            answer = qna_result["answers"][0]["answer"]
            assert not answer is None
            assert qna_result["answers"][0]["confidenceScore"] >= 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={
                    "kind": "Conversation",
                    "analysisInput": {
                        "conversationItem": {
                            "participantId": "1",
                            "id": "1",
                            "modality": "text",
                            "language": "en",
                            "text": query
                        },
                        "isLoggingEnabled": False
                    },
                    "parameters": {
                        "projectName": orch_project_name,
                        "deploymentName": orch_deployment_name,
                        "verbose": True
                    }
                }
            )
        
            # assert - main object
            top_project = "RestaurantIntent"
            assert not result is None
            assert result["kind"] == "ConversationResult"
            assert result["result"]["query"] == query
            
            # assert - prediction type
            assert result["result"]["prediction"]["projectKind"] == "Orchestration"
            
            # assert - top matching project
            assert result["result"]["prediction"]["topIntent"] == top_project
            top_intent_object = result["result"]["prediction"]["intents"][top_project]
            assert top_intent_object["targetProjectKind"] == "Luis"
            
            # assert intent and entities
            top_intent = "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
    async def test_conversation_app_with_dict_parms(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={
                    "kind": "CustomConversation",
                    "analysisInput": {
                        "conversationItem": {
                            "participantId": "1",
                            "id": "1",
                            "modality": "text",
                            "language": "en",
                            "text": query
                        },
                        "isLoggingEnabled": False
                    },
                    "parameters": {
                        "projectName": conv_project_name,
                        "deploymentName": conv_deployment_name,
                        "verbose": True
                    }
                })

            # 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
Esempio n. 14
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))
Esempio n. 15
0
    async def test_orchestration_app_conv_response(self, endpoint, key,
                                                   orch_project_name,
                                                   orch_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=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
Esempio n. 16
0
async def sample_analyze_conversation_app_language_parm_async():
    # [START analyze_conversation_app_language_parm_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"]
    conv_project = os.environ["AZURE_CONVERSATIONS_PROJECT"]

    # prepare data
    query = "One california maki please."
    input = ConversationAnalysisOptions(query=query, language="en")

    # analyze quey
    client = ConversationAnalysisClient(conv_endpoint,
                                        AzureKeyCredential(conv_key))
    async with client:
        result = await 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))
Esempio n. 17
0
    async def test_orchestration_app_qna_response(self, endpoint, key, orch_project_name, orch_deployment_name):

        # analyze query
        client = ConversationAnalysisClient(endpoint, AzureKeyCredential(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=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_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
Esempio n. 19
0
    async def test_orchestration_app(self, conv_account, conv_key,
                                     orchestration_project):

        client = ConversationAnalysisClient(conv_account,
                                            AzureKeyCredential(conv_key))
        async with client:

            # analyze query
            query = "How do you make sushi rice?"
            result = await client.analyze_conversations(
                {"query": query},
                project_name=orchestration_project,
                deployment_name='production',
            )

            # assert
            top_intent = "SushiMaking"
            assert isinstance(result, AnalyzeConversationResult)
            assert result.query == query
            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)

            # analyze query
            query = "I will have sashimi"
            result = await client.analyze_conversations(
                {"query": query},
                project_name=orchestration_project,
                deployment_name='production',
            )

            # assert
            assert isinstance(result, AnalyzeConversationResult)
            assert result.query == query
            assert isinstance(result.prediction, OrchestratorPrediction)
            assert result.prediction.project_kind == "workflow"
Esempio n. 20
0
    async 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))
        async with client:
            result = await 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 sample_analyze_orchestration_app_conv_response_async():
    # [START analyze_orchestration_app_conv_response]
    # import libraries
    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    # get secrets
    clu_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    clu_key = os.environ["AZURE_CONVERSATIONS_KEY"]
    project_name = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT_NAME"]
    deployment_name = os.environ[
        "AZURE_CONVERSATIONS_WORKFLOW_DEPLOYMENT_NAME"]

    # analyze query
    client = ConversationAnalysisClient(clu_endpoint,
                                        AzureKeyCredential(clu_key))
    async with client:
        query = "Send an email to Carol about the tomorrow's demo"
        result = await client.analyze_conversation(
            task={
                "kind": "Conversation",
                "analysisInput": {
                    "conversationItem": {
                        "participantId": "1",
                        "id": "1",
                        "modality": "text",
                        "language": "en",
                        "text": query
                    },
                    "isLoggingEnabled": False
                },
                "parameters": {
                    "projectName": project_name,
                    "deploymentName": deployment_name,
                    "verbose": True
                }
            })

    # view result
    print("query: {}".format(result["result"]["query"]))
    print("project kind: {}\n".format(
        result["result"]["prediction"]["projectKind"]))

    # top intent
    top_intent = result["result"]["prediction"]["topIntent"]
    print("top intent: {}".format(top_intent))
    top_intent_object = result["result"]["prediction"]["intents"][top_intent]
    print("confidence score: {}".format(top_intent_object["confidenceScore"]))
    print("project kind: {}".format(top_intent_object["targetProjectKind"]))

    # conversation result
    if top_intent_object["targetProjectKind"] == "Conversation":
        print("\nview conversation result:")

        print("\ntop intent: {}".format(
            top_intent_object["result"]["prediction"]["topIntent"]))
        print("category: {}".format(top_intent_object["result"]["prediction"]
                                    ["intents"][0]["category"]))
        print("confidence score: {}\n".format(
            top_intent_object["result"]["prediction"]["intents"][0]
            ["confidenceScore"]))

        print("\nview entities:")
        for entity in top_intent_object["result"]["prediction"]["entities"]:
            print("\ncategory: {}".format(entity["category"]))
            print("text: {}".format(entity["text"]))
            print("confidence score: {}".format(entity["confidenceScore"]))
            if "resolutions" in entity:
                print("resolutions")
                for resolution in entity["resolutions"]:
                    print("kind: {}".format(resolution["resolutionKind"]))
                    print("value: {}".format(resolution["value"]))
            if "extraInformation" in entity:
                print("extra info")
                for data in entity["extraInformation"]:
                    print("kind: {}".format(data["extraInformationKind"]))
                    if data["extraInformationKind"] == "ListKey":
                        print("key: {}".format(data["key"]))
                    if data["extraInformationKind"] == "EntitySubtype":
                        print("value: {}".format(data["value"]))
    async def test_conversational_summarization(self, endpoint, key):
        # analyze query
        client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
        async with client:
            poller = await client.begin_conversation_analysis(
                task={
                    "displayName":
                    "Analyze conversations from xxx",
                    "analysisInput": {
                        "conversations": [
                            {
                                "conversationItems":
                                [{
                                    "text": "Hello, how can I help you?",
                                    "modality": "text",
                                    "id": "1",
                                    "participantId": "Agent"
                                }, {
                                    "text":
                                    "How to upgrade Office? I am getting error messages the whole day.",
                                    "modality": "text",
                                    "id": "2",
                                    "participantId": "Customer"
                                }, {
                                    "text":
                                    "Press the upgrade button please. Then sign in and follow the instructions.",
                                    "modality": "text",
                                    "id": "3",
                                    "participantId": "Agent"
                                }],
                                "modality":
                                "text",
                                "id":
                                "conversation1",
                                "language":
                                "en"
                            },
                        ]
                    },
                    "tasks": [{
                        "taskName": "analyze 1",
                        "kind": "ConversationalSummarizationTask",
                        "parameters": {
                            "summaryAspects": ["Issue, Resolution"]
                        }
                    }]
                })

            # assert - main object
            result = await 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 is not None
async def sample_analyze_orchestration_direct_target_async():
    # [START analyze_orchestration_app_qna_response]
    # import libraries
    import os
    from azure.core.credentials import AzureKeyCredential

    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    # get secrets
    clu_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    clu_key = os.environ["AZURE_CONVERSATIONS_KEY"]
    project_name = os.environ["AZURE_CONVERSATIONS_WORKFLOW_PROJECT_NAME"]
    deployment_name = os.environ[
        "AZURE_CONVERSATIONS_WORKFLOW_DEPLOYMENT_NAME"]

    # analyze query
    client = ConversationAnalysisClient(clu_endpoint,
                                        AzureKeyCredential(clu_key))
    async with client:
        query = "How are you?"
        qna_app = "ChitChat-QnA"
        result = await client.analyze_conversation(
            task={
                "kind": "Conversation",
                "analysisInput": {
                    "conversationItem": {
                        "participantId": "1",
                        "id": "1",
                        "modality": "text",
                        "language": "en",
                        "text": query
                    },
                    "isLoggingEnabled": False
                },
                "parameters": {
                    "projectName": project_name,
                    "deploymentName": deployment_name,
                    "directTarget": qna_app,
                    "targetProjectParameters": {
                        "ChitChat-QnA": {
                            "targetProjectKind": "QuestionAnswering",
                            "callingOptions": {
                                "question": query
                            }
                        }
                    }
                }
            })

    # view result
    print("query: {}".format(result["result"]["query"]))
    print("project kind: {}\n".format(
        result["result"]["prediction"]["projectKind"]))

    # top intent
    top_intent = result["result"]["prediction"]["topIntent"]
    print("top intent: {}".format(top_intent))
    top_intent_object = result["result"]["prediction"]["intents"][top_intent]
    print("confidence score: {}".format(top_intent_object["confidenceScore"]))
    print("project kind: {}".format(top_intent_object["targetProjectKind"]))

    if top_intent_object["targetProjectKind"] == "QuestionAnswering":
        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["confidenceScore"]))
Esempio n. 24
0
async def sample_conv_pii_transcript_input_async():
    # [START analyze_conversation_app]
    # import libraries
    import os
    from azure.core.credentials import AzureKeyCredential

    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    # get secrets
    endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    key = os.environ["AZURE_CONVERSATIONS_KEY"]

    # analyze quey
    client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
    async with client:

        poller = await client.begin_conversation_analysis(
            task={
                "displayName": "Analyze PII in conversation",
                "analysisInput": {
                    "conversations": [
                        {
                            "conversationItems": [
                                {
                                    "id": "1",
                                    "participantId": "0",
                                    "modality": "transcript",
                                    "text": "It is john doe.",
                                    "lexical": "It is john doe",
                                    "itn": "It is john doe",
                                    "maskedItn": "It is john doe"
                                },
                                {
                                    "id": "2",
                                    "participantId": "1",
                                    "modality": "transcript",
                                    "text": "Yes, 633-27-8199 is my phone",
                                    "lexical": "yes six three three two seven eight one nine nine is my phone",
                                    "itn": "yes 633278199 is my phone",
                                    "maskedItn": "yes 633278199 is my phone",
                                },
                                {
                                    "id": "3",
                                    "participantId": "1",
                                    "modality": "transcript",
                                    "text": "[email protected] is my email",
                                    "lexical": "j dot doe at yahoo dot com is my email",
                                    "maskedItn": "[email protected] is my email",
                                    "itn": "[email protected] is my email",
                                }
                            ],
                            "modality": "transcript",
                            "id": "1",
                            "language": "en"
                        }
                    ]
                },
                "tasks": [
                    {
                        "kind": "ConversationalPIITask",
                        "parameters": {
                            "redactionSource": "lexical",
                            "piiCategories": [
                                "all"
                            ]
                        }
                    }
                ]
            }
        )

        # view result
        result = await poller.result()
        task_result = result["tasks"]["items"][0]
        print("... view task status ...")
        print("status: {}".format(task_result["status"]))
        conv_pii_result = task_result["results"]
        if conv_pii_result["errors"]:
            print("... errors occured ...")
            for error in conv_pii_result["errors"]:
                print(error)
        else:
            conversation_result = conv_pii_result["conversations"][0]
            if conversation_result["warnings"]:
                print("... view warnings ...")
                for warning in conversation_result["warnings"]:
                    print(warning)
            else:
                print("... view task result ...")
                for conversation in conversation_result["conversationItems"]:
                    print("conversation id: {}".format(conversation["id"]))
                    print("... entities ...")
                    for entity in conversation["entities"]:
                        print("text: {}".format(entity["text"]))
                        print("category: {}".format(entity["category"]))
                        print("confidence: {}".format(entity["confidenceScore"]))
                        print("offset: {}".format(entity["offset"]))
                        print("length: {}".format(entity["length"]))
    async def test_conversational_pii(self, endpoint, key):
        # analyze query
        client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
        async with client:
            poller = await client.begin_conversation_analysis(
                task={
                    "displayName":
                    "Analyze PII in conversation",
                    "analysisInput": {
                        "conversations": [{
                            "conversationItems":
                            [{
                                "id": "1",
                                "participantId": "0",
                                "modality": "transcript",
                                "text": "It is john doe.",
                                "lexical": "It is john doe",
                                "itn": "It is john doe",
                                "maskedItn": "It is john doe"
                            }, {
                                "id": "2",
                                "participantId": "1",
                                "modality": "transcript",
                                "text": "Yes, 633-27-8199 is my phone",
                                "lexical":
                                "yes six three three two seven eight one nine nine is my phone",
                                "itn": "yes 633278199 is my phone",
                                "maskedItn": "yes 633278199 is my phone",
                            }, {
                                "id": "3",
                                "participantId": "1",
                                "modality": "transcript",
                                "text": "[email protected] is my email",
                                "lexical":
                                "j dot doe at yahoo dot com is my email",
                                "maskedItn": "[email protected] is my email",
                                "itn": "[email protected] is my email",
                            }],
                            "modality":
                            "transcript",
                            "id":
                            "1",
                            "language":
                            "en"
                        }]
                    },
                    "tasks": [{
                        "kind": "ConversationalPIITask",
                        "parameters": {
                            "redactionSource": "lexical",
                            "piiCategories": ["all"]
                        }
                    }]
                })

            # assert - main object
            result = await 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"] == "conversationalPIIResults"

            # assert - conv result
            conversation_items = task_result["results"]["conversations"][0][
                "conversationItems"]
            assert not conversation_items is None
            for conversation in conversation_items:
                assert not conversation["redactedContent"] is None
                assert not conversation["entities"] is None
async def sample_conv_summarization_async():
    # [START analyze_conversation_app]
    # import libraries
    import os
    from azure.core.credentials import AzureKeyCredential

    from azure.ai.language.conversations.aio import ConversationAnalysisClient

    # get secrets
    endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
    key = os.environ["AZURE_CONVERSATIONS_KEY"]

    # analyze quey
    client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
    async with client:
        poller = await client.begin_conversation_analysis(
            task={
                "displayName":
                "Analyze conversations from xxx",
                "analysisInput": {
                    "conversations": [
                        {
                            "conversationItems": [{
                                "text": "Hello, how can I help you?",
                                "modality": "text",
                                "id": "1",
                                "participantId": "Agent"
                            }, {
                                "text":
                                "How to upgrade Office? I am getting error messages the whole day.",
                                "modality": "text",
                                "id": "2",
                                "participantId": "Customer"
                            }, {
                                "text":
                                "Press the upgrade button please. Then sign in and follow the instructions.",
                                "modality": "text",
                                "id": "3",
                                "participantId": "Agent"
                            }],
                            "modality":
                            "text",
                            "id":
                            "conversation1",
                            "language":
                            "en"
                        },
                    ]
                },
                "tasks": [{
                    "taskName": "analyze 1",
                    "kind": "ConversationalSummarizationTask",
                    "parameters": {
                        "summaryAspects": ["Issue, Resolution"]
                    }
                }]
            })

        # view result
        result = await poller.result()
        task_result = result["tasks"]["items"][0]
        print("... view task status ...")
        print("status: {}".format(task_result["status"]))
        resolution_result = task_result["results"]
        if resolution_result["errors"]:
            print("... errors occured ...")
            for error in resolution_result["errors"]:
                print(error)
        else:
            conversation_result = resolution_result["conversations"][0]
            if conversation_result["warnings"]:
                print("... view warnings ...")
                for warning in conversation_result["warnings"]:
                    print(warning)
            else:
                summaries = conversation_result["summaries"]
                print("... view task result ...")
                print("issue: {}".format(summaries[0]["text"]))
                print("resolution: {}".format(summaries[1]["text"]))
async def sample_analyze_conversation_app_async():
    # [START analyze_conversation_app_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_CONVERSATIONS_PROJECT_NAME"]
    deployment_name = os.environ["AZURE_CLU_CONVERSATIONS_DEPLOYMENT_NAME"]

    # analyze quey
    client = ConversationAnalysisClient(clu_endpoint, AzureKeyCredential(clu_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=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_conversation_with_dict_parms_async():
    # [START analyze_conversation_app_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 DateTimeResolution

    # 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))
    async with client:
        query = "Send an email to Carol about the tomorrow's demo"
        result = await client.analyze_conversation(
            task={
                "kind": "CustomConversation",
                "analysisInput": {
                    "conversationItem": {
                        "participantId": "1",
                        "id": "1",
                        "modality": "text",
                        "language": "en",
                        "text": query
                    },
                    "isLoggingEnabled": False
                },
                "parameters": {
                    "projectName": project_name,
                    "deploymentName": deployment_name,
                    "verbose": True
                }
            })

        # 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))