Skip to content

Commit

Permalink
adding remaining samples
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaban-msft committed Oct 1, 2021
1 parent b32ef46 commit 0b8e3b8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
Set the environment variables with your own values before running the sample:
1) AZURE_CONVERSATIONS_ENDPOINT - the endpoint to your CLU resource.
2) AZURE_CONVERSATIONS_KEY - your CLU API key.
3) AZURE_CONVERSATIONS_PROJECT - the name of your CLU conversations project.
4) AZURE_CONVERSATIONS_WORKFLOW_PROJECT - the name of your CLU workflow project.
3) AZURE_CONVERSATIONS_WORKFLOW_PROJECT - the name of your CLU workflow project.
"""

def sample_analyze_workflow_app(self, conv_account, conv_key, workflow_project):
def sample_analyze_workflow_app():
# [START analyze_workflow_app]
# import libraries
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

"""
FILE: sample_analyze_workflow_app_direct.py
DESCRIPTION:
This sample demonstrates how to analyze user query using an orchestration/workflow project.
In this sample, we direct the orchestrator project to use a specifc subproject using the "direct_target" parameter.
The "direct_target" in our case will be a Qna project.
For more info about how to setup a CLU workflow project, see the README.
USAGE:
python sample_analyze_workflow_app_direct.py
Set the environment variables with your own values before running the sample:
1) AZURE_CONVERSATIONS_ENDPOINT - the endpoint to your CLU resource.
2) AZURE_CONVERSATIONS_KEY - your CLU API key.
3) AZURE_CONVERSATIONS_WORKFLOW_PROJECT - the name of your CLU workflow project.
"""

def sample_analyze_workflow_app_direct():
# [START analyze_workflow_app_direct]
# import libraries
import os
from azure.core.credentials import AzureKeyCredential

from azure.ai.language.conversations import ConversationAnalysisClient
from azure.ai.language.conversations.models import AnalyzeConversationOptions

# get secrets
conv_endpoint = os.environ.get("AZURE_CONVERSATIONS_ENDPOINT"),
conv_key = os.environ.get("AZURE_CONVERSATIONS_KEY"),
workflow_project = os.environ.get("AZURE_CONVERSATIONS_WORKFLOW_PROJECT")

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

# analyze query
client = ConversationAnalysisClient(conv_endpoint, AzureKeyCredential(conv_key))
with client:
result = client.analyze_conversations(
input,
project_name=workflow_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("top 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 qna result:")
print("\tresult: {}\n".format(result.prediction.intents[0].result))
# [START analyze_workflow_app_direct]


if __name__ == '__main__':
sample_analyze_workflow_app_direct()
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
Set the environment variables with your own values before running the sample:
1) AZURE_CONVERSATIONS_ENDPOINT - the endpoint to your CLU resource.
2) AZURE_CONVERSATIONS_KEY - your CLU API key.
3) AZURE_CONVERSATIONS_PROJECT - the name of your CLU conversations project.
4) AZURE_CONVERSATIONS_WORKFLOW_PROJECT - the name of your CLU workflow project.
3) AZURE_CONVERSATIONS_WORKFLOW_PROJECT - the name of your CLU workflow project.
"""

def sample_analyze_workflow_app_with_parms(self, conv_account, conv_key, workflow_project):
def sample_analyze_workflow_app_with_parms():
# [START analyze_workflow_app_with_parms]
# import libraries
import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def sample_authentication_api_key():


def sample_authentication_with_azure_active_directory():
# [START create_dt_client_with_aad]
# [START create_clu_client_with_aad]
"""DefaultAzureCredential will use the values from these environment
variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
"""
Expand All @@ -61,7 +61,7 @@ def sample_authentication_with_azure_active_directory():
credential = DefaultAzureCredential()

clu_client = ConversationAnalysisClient(endpoint, credential)
# [END create_dt_client_with_aad]
# [END create_clu_client_with_aad]


if __name__ == '__main__':
Expand Down

0 comments on commit 0b8e3b8

Please sign in to comment.