Skip to content

Commit 25145b5

Browse files
authored
Merge pull request #5 from Azure/main
Update 7/9
2 parents 23da66e + a3f454d commit 25145b5

File tree

554 files changed

+140589
-12156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

554 files changed

+140589
-12156
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aiohttp==3.5.4
1+
aiohttp==3.7.4

doc/dev/debug_guide.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Debug
2+
3+
This guide is to help Python SDK users to get the process about how SDK call REST api
4+
5+
(1) Copy the following code in your .py file
6+
```
7+
import sys
8+
import logging
9+
10+
logger = logging.getLogger('')
11+
logger.setLevel(logging.DEBUG)
12+
handler = logging.StreamHandler(stream=sys.stdout, )
13+
logger.addHandler(handler)
14+
formatter = logging.Formatter(
15+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
16+
handler.setFormatter(formatter)
17+
```
18+
19+
![Position example](./debug_guide_position.png "Position example")
20+
21+
(2) Run your .py program and you could find the log info in screen. It is convenient to get the process about how SDK call REST api:
22+
23+
![example](./debug_guide_example.png "example")

doc/dev/debug_guide_example.png

179 KB
Loading

doc/dev/debug_guide_position.png

41.4 KB
Loading

eng/ci_tools.txt

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pyOpenSSL==19.1.0
2727
json-delta==2.0
2828
ConfigArgParse==1.2.3
2929
six==1.14.0
30-
vcrpy==3.0.0
3130
pyyaml==5.3.1
3231
pytest==5.4.2; python_version >= '3.5'
3332
pytest==4.6.9; python_version == '2.7'

eng/common/TestResources/New-TestResources.ps1

+35-7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ function MergeHashes([hashtable] $source, [psvariable] $dest) {
119119
}
120120
}
121121

122+
function BuildBicepFile([System.IO.FileSystemInfo] $file) {
123+
if (!(Get-Command bicep -ErrorAction Ignore)) {
124+
Write-Error "A bicep file was found at '$($file.FullName)' but the Azure Bicep CLI is not installed. See https://aka.ms/install-bicep-pwsh"
125+
throw
126+
}
127+
128+
$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
129+
$templateFilePath = Join-Path $tmp "test-resources.$(New-Guid).compiled.json"
130+
131+
# Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
132+
# outputted json for mismatched parameter declarations.
133+
bicep build $file.FullName --outfile $templateFilePath
134+
if ($LASTEXITCODE) {
135+
Write-Error "Failure building bicep file '$($file.FullName)'"
136+
throw
137+
}
138+
139+
return $templateFilePath
140+
}
141+
122142
# Support actions to invoke on exit.
123143
$exitActions = @({
124144
if ($exitActions.Count -gt 1) {
@@ -140,15 +160,18 @@ try {
140160
# Enumerate test resources to deploy. Fail if none found.
141161
$repositoryRoot = "$PSScriptRoot/../../.." | Resolve-Path
142162
$root = [System.IO.Path]::Combine($repositoryRoot, "sdk", $ServiceDirectory) | Resolve-Path
143-
$templateFileName = 'test-resources.json'
144163
$templateFiles = @()
145164

146-
Write-Verbose "Checking for '$templateFileName' files under '$root'"
147-
Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object {
148-
$templateFile = $_.FullName
149-
150-
Write-Verbose "Found template '$templateFile'"
151-
$templateFiles += $templateFile
165+
'test-resources.json', 'test-resources.bicep' | ForEach-Object {
166+
Write-Verbose "Checking for '$_' files under '$root'"
167+
Get-ChildItem -Path $root -Filter "$_" -Recurse | ForEach-Object {
168+
Write-Verbose "Found template '$($_.FullName)'"
169+
if ($_.Extension -eq '.bicep') {
170+
$templateFiles += (BuildBicepFile $_)
171+
} else {
172+
$templateFiles += $_.FullName
173+
}
174+
}
152175
}
153176

154177
if (!$templateFiles) {
@@ -556,6 +579,11 @@ try {
556579
Log "Invoking post-deployment script '$postDeploymentScript'"
557580
&$postDeploymentScript -ResourceGroupName $ResourceGroupName -DeploymentOutputs $deploymentOutputs @PSBoundParameters
558581
}
582+
583+
if ($templateFile.EndsWith('.compiled.json')) {
584+
Write-Verbose "Removing compiled bicep file $templateFile"
585+
Remove-Item $templateFile
586+
}
559587
}
560588

561589
} finally {

eng/common/TestResources/deploy-test-resources.yml

+2
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ steps:
5858
-Force `
5959
-Verbose | Out-Null
6060
displayName: Deploy test resources
61+
env:
62+
TEMP: $(Agent.TempDirectory)

eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ parameters:
2727
default: []
2828
- name: Pool
2929
type: string
30-
default: azsdk-pool-mms-ubuntu-1804-general
30+
default: azsdk-pool-mms-ubuntu-2004-general
3131
- name: OsVmImage
3232
type: string
33-
default: MMSUbuntu18.04
33+
default: MMSUbuntu20.04
3434
# This parameter is only necessary if there are multiple invocations of this template within the SAME STAGE.
3535
# When that occurs, provide a name other than the default value.
3636
- name: GenerateJobName

eng/common/pipelines/templates/steps/sparse-checkout.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ steps:
3939
Write-Host "Repository $($repository.Name) has already been initialized. Skipping this step."
4040
} else {
4141
Write-Host "Repository $($repository.Name) is being initialized."
42+
43+
Write-Host "git clone --no-checkout --filter=tree:0 git://github.com/$($repository.Name) ."
4244
git clone --no-checkout --filter=tree:0 git://github.com/$($repository.Name) .
45+
46+
Write-Host "git sparse-checkout init"
4347
git sparse-checkout init
44-
git sparse-checkout set eng
48+
49+
Write-Host "git sparse-checkout set '/*' '!/*/' '/eng'"
50+
git sparse-checkout set '/*' '!/*/' '/eng'
4551
}
4652
4753
$gitsparsecmd = "git sparse-checkout add $paths"

eng/test_tools.txt

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pyOpenSSL==19.1.0
1818
json-delta==2.0
1919
ConfigArgParse==1.2.3
2020
six==1.14.0
21-
vcrpy==3.0.0
2221
pyyaml==5.3.1
2322
packaging==20.4
2423
wheel==0.34.2

eng/tox/allowed_pylint_failures.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
"azure-purview-catalog",
5757
"azure-messaging-nspkg",
5858
"azure-agrifood-farming",
59-
"azure-eventhub"
59+
"azure-eventhub",
60+
"azure-ai-language-questionanswering"
6061
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Release History
2+
3+
## 1.0.0b1 (unreleased)
4+
5+
### Features Added
6+
* Initial release.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include _meta.json
2+
include *.md
3+
include azure/__init__.py
4+
include azure/ai/__init__.py
5+
include azure/ai/language/__init__.py
6+
recursive-include tests *.py
7+
recursive-include samples *.py *.md
8+
include azure/ai/language/questionanswering/py.typed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
[![Build Status](https://dev.azure.com/azure-sdk/public/_apis/build/status/azure-sdk-for-python.client?branchName=main)](https://dev.azure.com/azure-sdk/public/_build/latest?definitionId=46?branchName=main)
2+
3+
# Azure Cognitive Language Services Question Answering client library for Python
4+
5+
Question Answering is a cloud-based API service that lets you create a conversational question-and-answer layer over your existing data. Use it to build a knowledge base by extracting questions and answers from your semi-structured content, including FAQ, manuals, and documents. Answer users’ questions with the best answers from the QnAs in your knowledge base—automatically. Your knowledge base gets smarter, too, as it continually learns from users' behavior.
6+
7+
[Source code][questionanswering_client_src] | [Package (PyPI)][questionanswering_pypi_package] | [API reference documentation][questionanswering_refdocs] | [Product documentation][questionanswering_docs] | [Samples][questionanswering_samples]
8+
9+
## Getting started
10+
11+
### Prerequisites
12+
13+
* Python 2.7, or 3.6 or later is required to use this package.
14+
* An [Azure subscription][azure_subscription]
15+
* An existing Question Answering resource
16+
17+
> Note: the new unified Cognitive Language Services are not currently available for deployment.
18+
19+
### Install the package
20+
21+
Install the Azure QuestionAnswering client library for Python with [pip][pip_link]:
22+
23+
```bash
24+
pip install azure-ai-language-questionanswering
25+
```
26+
27+
### Authenticate the client
28+
29+
In order to interact with the Question Answering service, you'll need to create an instance of the [`QuestionAnsweringClient`][questionanswering_client_class] class. You will need an **endpoint**, and an **API key** instantiate a client object. For more information regarding authenticating with Cognitive Services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth].
30+
31+
#### Get an API key
32+
33+
You can get the **endpoint** and an **API key** from the Cognitive Services resource or Question Answering resource in the [Azure Portal][azure_portal].
34+
35+
Alternatively, use the [Azure CLI][azure_cli] command shown below to get the API key from the Question Answering resource.
36+
37+
```powershell
38+
az cognitiveservices account keys list --resource-group <resource-group-name> --name <resource-name>
39+
```
40+
41+
#### Create QuestionAnsweringClient
42+
43+
Once you've determined your **endpoint** and **API key** you can instantiate a `QuestionAnsweringClient`:
44+
45+
```python
46+
from azure.core.credentials import AzureKeyCredential
47+
from azure.ai.language.questionanswering import QuestionAnsweringClient
48+
49+
endpoint = "https://{myaccount}.api.cognitive.microsoft.com"
50+
credential = AzureKeyCredential("{api-key}")
51+
52+
client = QuestionAnsweringClient(endpoint, credential)
53+
```
54+
55+
## Key concepts
56+
57+
### QuestionAnsweringClient
58+
59+
The [`QuestionAnsweringClient`][questionanswering_client_class] is the primary interface for asking questions using a knowledge base with your own information, or text input using pre-trained models.
60+
For asynchronous operations, an async `QuestionAnsweringClient` is in the `azure.ai.language.questionanswering.aio` namespace.
61+
62+
## Examples
63+
64+
The `azure-ai-language-questionanswering` client library provides both synchronous and asynchronous APIs.
65+
66+
The following examples show common scenarios using the `client` [created above](#create-questionansweringclient).
67+
- [Ask a question](#ask-a-question)
68+
- [Ask a follow-up question](#ask-a-follow-up-question)
69+
- [Asynchronous operations](#asynchronous-operations)
70+
71+
### Ask a question
72+
73+
The only input required to ask a question using a knowledgebase is just the question itself:
74+
75+
```python
76+
from azure.ai.language.questionanswering import models as qna
77+
78+
params = qna.KnowledgebaseQueryParameters(
79+
question="How long should my Surface battery last?"
80+
)
81+
82+
output = client.query_knowledgebase(
83+
project_name="FAQ",
84+
knowledgebase_query_parameters=params
85+
)
86+
for candidate in output.answers:
87+
print("({}) {}".format(candidate.confidence_score, candidate.answer))
88+
print("Source: {}".format(candidate.source))
89+
90+
```
91+
92+
You can set additional properties on `KnowledgebaseQueryParameters` to limit the number of answers, specify a minimum confidence score, and more.
93+
94+
### Ask a follow-up question
95+
96+
If your knowledgebase is configured for [chit-chat][questionanswering_docs_chat], you can ask a follow-up question provided the previous question-answering ID and, optionally, the exact question the user asked:
97+
98+
```python
99+
params = qna.models.KnowledgebaseQueryParameters(
100+
question="How long should charging take?"
101+
context=qna.models.KnowledgebaseAnswerRequestContext(
102+
previous_user_query="How long should my Surface battery last?",
103+
previous_qna_id=previous_answer.id
104+
)
105+
)
106+
107+
output = client.query_knowledgebase(
108+
project_name="FAQ",
109+
knowledgebase_query_parameters=params
110+
)
111+
for candidate in output.answers:
112+
print("({}) {}".format(candidate.confidence_score, candidate.answer))
113+
print("Source: {}".format(candidate.source))
114+
115+
```
116+
### Asynchronous operations
117+
118+
The above examples can also be run asynchronously using the client in the `aio` namespace:
119+
```python
120+
from azure.core.credentials import AzureKeyCredential
121+
from azure.ai.language.questionanswering.aio import QuestionAnsweringClient
122+
from azure.ai.language.questionanswering import models as qna
123+
124+
client = QuestionAnsweringClient(endpoint, credential)
125+
126+
params = qna.KnowledgebaseQueryParameters(
127+
question="How long should my Surface battery last?"
128+
)
129+
130+
output = await client.query_knowledgebase(
131+
project_name="FAQ",
132+
knowledgebase_query_parameters=params
133+
)
134+
```
135+
136+
## Optional Configuration
137+
Optional keyword arguments can be passed in at the client and per-operation level. The azure-core [reference documentation][azure_core_ref_docs] describes available configurations for retries, logging, transport protocols, and more.
138+
139+
## Troubleshooting
140+
141+
### General
142+
Azure QuestionAnswering clients raise exceptions defined in [Azure Core][azure_core_readme].
143+
When you interact with the Cognitive Language Services Question Answering client library using the .Python SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API][questionanswering_rest_docs] requests.
144+
145+
For example, if you submit a question to a non-existant knowledge base, a `400` error is returned indicating "Bad Request".
146+
147+
```python
148+
from azure.core.exceptions import HttpResponseError
149+
150+
try:
151+
client.query_knowledgebase(
152+
project_name="invalid-knowledgebase",
153+
knowledgebase_query_parameters=params
154+
)
155+
except HttpResponseError as error:
156+
print("Query failed: {}".format(error.message))
157+
```
158+
159+
### Logging
160+
This library uses the standard
161+
[logging][python_logging] library for logging.
162+
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
163+
level.
164+
165+
Detailed DEBUG level logging, including request/response bodies and unredacted
166+
headers, can be enabled on a client with the `logging_enable` argument.
167+
168+
See full SDK logging documentation with examples [here][sdk_logging_docs].
169+
170+
## Next steps
171+
172+
* View our [samples][questionanswering_samples].
173+
* Read about the different [features][questionanswering_docs_features] of the Question Answering service.
174+
* Try our service [demos][questionanswering_docs_demos].
175+
176+
## Contributing
177+
178+
See the [CONTRIBUTING.md][contributing] for details on building, testing, and contributing to this library.
179+
180+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].
181+
182+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
183+
184+
This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments.
185+
186+
<!-- LINKS -->
187+
[azure_cli]: https://docs.microsoft.com/cli/azure/
188+
[azure_portal]: https://portal.azure.com/
189+
[azure_subscription]: https://azure.microsoft.com/free/
190+
[cla]: https://cla.microsoft.com
191+
[coc_contact]: mailto:[email protected]
192+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
193+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
194+
[cognitive_auth]: https://docs.microsoft.com/azure/cognitive-services/authentication/
195+
[contributing]: https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md
196+
[python_logging]: https://docs.python.org/3/library/logging.html
197+
[sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/azure-sdk-logging
198+
[azure_core_ref_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html
199+
[azure_core_readme]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
200+
[pip_link]:https://pypi.org/project/pip/
201+
[questionanswering_client_class]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_question_answering_client.py#L27
202+
[questionanswering_client_src]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
203+
[questionanswering_docs]: https://azure.microsoft.com/services/cognitive-services/qna-maker/
204+
[questionanswering_docs_chat]: https://docs.microsoft.com/azure/cognitive-services/qnamaker/how-to/chit-chat-knowledge-base
205+
[questionanswering_docs_demos]: https://azure.microsoft.com/services/cognitive-services/qna-maker/#demo
206+
[questionanswering_docs_features]: https://azure.microsoft.com/services/cognitive-services/qna-maker/#features
207+
[questionanswering_pypi_package]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
208+
[questionanswering_refdocs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
209+
[questionanswering_rest_docs]: https://docs.microsoft.com/rest/api/cognitiveservices-qnamaker/
210+
[questionanswering_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/README.md
211+
212+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fsdk%2Ftemplate%2Fazure-template%2FREADME.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

0 commit comments

Comments
 (0)