forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generating LLC client * adding version file * Update swagger directives * Python 2 support for now * update swagger reference * regenerate client * add version file * regen llc client * regen with authoring * regen with export fix update * create and deploy project sample * export import samples * some changes * knowledge source samples * update "create and deploy" sample * tmp commit * update "export import sample" * update "update knowledge sources sample" * update samples * fix "export_import" sample * minor fix * update sample for "create and deploy" * fix list sources * update "update knowledge sources" sample * fix synonyms sample * update main readme * update samples readme * remove u" python 2.7 support * adding async samples * restructure * update samples readme Co-authored-by: antisch <antisch@microsoft.com>
- Loading branch information
1 parent
fc33ffc
commit 6974494
Showing
8 changed files
with
815 additions
and
5 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
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
111 changes: 111 additions & 0 deletions
111
...estionanswering/samples/authoring/async_samples/sample_create_and_deploy_project_async.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,111 @@ | ||
# coding=utf-8 | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
""" | ||
FILE: sample_create_and_deploy_project_async.py | ||
DESCRIPTION: | ||
This sample demonstrates how to create and deploy a Qna project. | ||
USAGE: | ||
python sample_create_and_deploy_project_async.py | ||
Set the environment variables with your own values before running the sample: | ||
1) AZURE_QUESTIONANSWERING_ENDPOINT - the endpoint to your QuestionAnswering resource. | ||
2) AZURE_QUESTIONANSWERING_KEY - your QuestionAnswering API key. | ||
""" | ||
|
||
import asyncio | ||
|
||
async def sample_create_and_deploy_project_async(): | ||
# [START create_and_deploy_project] | ||
import os | ||
from azure.core.credentials import AzureKeyCredential | ||
from azure.ai.language.questionanswering.projects.aio import QuestionAnsweringProjectsClient | ||
|
||
# get service secrets | ||
endpoint = os.environ["AZURE_QUESTIONANSWERING_ENDPOINT"] | ||
key = os.environ["AZURE_QUESTIONANSWERING_KEY"] | ||
|
||
# create client | ||
client = QuestionAnsweringProjectsClient(endpoint, AzureKeyCredential(key)) | ||
async with client: | ||
|
||
# create project | ||
project_name = "IssacNewton" | ||
project = await client.create_project( | ||
project_name=project_name, | ||
options={ | ||
"description": "biography of Sir Issac Newton", | ||
"language": "en", | ||
"multilingualResource": True, | ||
"settings": { | ||
"defaultAnswer": "no answer" | ||
} | ||
}) | ||
|
||
print("view created project info:") | ||
print("\tname: {}".format(project["projectName"])) | ||
print("\tlanguage: {}".format(project["language"])) | ||
print("\tdescription: {}".format(project["description"])) | ||
|
||
# list projects | ||
print("find created project ..") | ||
qna_projects = client.list_projects() | ||
async for p in qna_projects: | ||
if p["projectName"] == project_name: | ||
print("project: {}".format(p["projectName"])) | ||
print("\tlanguage: {}".format(p["language"])) | ||
print("\tdescription: {}".format(p["description"])) | ||
|
||
# update sources (REQUIRED TO DEPLOY PROJECT) | ||
update_sources_poller = await client.begin_update_sources( | ||
project_name=project_name, | ||
sources=[ | ||
{ | ||
"op": "add", | ||
"value": { | ||
"displayName": "Issac Newton Bio", | ||
"sourceUri": "https://wikipedia.org/wiki/Isaac_Newton", | ||
"sourceKind": "url" | ||
} | ||
} | ||
] | ||
) | ||
await update_sources_poller.result() | ||
|
||
# list sources | ||
print("list project sources") | ||
sources = client.list_sources( | ||
project_name=project_name | ||
) | ||
async for source in sources: | ||
print("project: {}".format(source["displayName"])) | ||
print("\tsource: {}".format(source["source"])) | ||
print("\tsource Uri: {}".format(source["sourceUri"])) | ||
print("\tsource kind: {}".format(source["sourceKind"])) | ||
|
||
# deploy project | ||
deployment_poller = await client.begin_deploy_project( | ||
project_name=project_name, | ||
deployment_name="production" | ||
) | ||
await deployment_poller.result() | ||
|
||
# list all deployments | ||
deployments = client.list_deployments( | ||
project_name=project_name | ||
) | ||
|
||
print("view project deployments") | ||
async for d in deployments: | ||
print(d) | ||
|
||
# [END create_and_deploy_project] | ||
|
||
if __name__ == '__main__': | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(sample_create_and_deploy_project_async()) |
Oops, something went wrong.