-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32ef46
commit 0b8e3b8
Showing
4 changed files
with
87 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ivelanguage/azure-ai-language-conversations/samples/sample_analyze_workflow_app_direct.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters