def sample_analyze_orchestration_direct_target(): # [START analyze_orchestration_app_qna_response] # import libraries import os from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations 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)) with client: query = "How are you?" qna_app = "ChitChat-QnA" result = 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"]))
def sample_analyze_conversation_with_dict_parms(): # [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 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)) with client: query = "Send an email to Carol about the tomorrow's demo" result = 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))
def test_conversational_summarization(self, endpoint, key): # analyze query client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) with client: poller = 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 = 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
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 # get secrets clu_endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"] clu_key = os.environ["AZURE_CONVERSATIONS_KEY"] project_name = os.environ["AZURE_CONVERSATIONS_PROJECT_NAME"] deployment_name = os.environ["AZURE_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={ "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"])) print("top intent: {}".format(result["result"]["prediction"]["topIntent"])) print("category: {}".format(result["result"]["prediction"]["intents"][0]["category"])) print("confidence score: {}\n".format(result["result"]["prediction"]["intents"][0]["confidenceScore"])) print("entities:") for entity in result["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"]))