Skip to content

Commit

Permalink
Merge branch 'switch_to_protocol' of https://github.com/iscai-msft/az…
Browse files Browse the repository at this point in the history
…ure-sdk-for-python into switch_to_rest

* 'switch_to_protocol' of https://github.com/iscai-msft/azure-sdk-for-python:
  switch from protocol to abc
  add initial tests
  update changelog
  switch to protocol
  ensure test principal creation succeeds properly (Azure#20446)
  Update question-answering readme links (Azure#20439)
  Stip empty changelog sections before release (Azure#20437)
  [AutoRelease] t2-healthcareapis-2021-08-26-27542 (Azure#20422)
  [AutoRelease] t2-iothub-2021-08-25-25696 (Azure#20409)
  Get rid of LogsBatchQueryResult (Azure#20418)
  • Loading branch information
iscai-msft committed Aug 29, 2021
2 parents 7fb1e18 + 324f1ae commit c8cc257
Show file tree
Hide file tree
Showing 195 changed files with 24,250 additions and 1,536 deletions.
2 changes: 1 addition & 1 deletion eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ try {
$AzureTestPrincipal
} else {
Log "TestApplicationId was not specified; creating a new service principal in subscription '$SubscriptionId'"
$global:AzureTestPrincipal = New-AzADServicePrincipal -Role Owner -Scope "/subscriptions/$SubscriptionId"
$global:AzureTestPrincipal = New-AzADServicePrincipal -Role Owner -Scope "/subscriptions/$SubscriptionId" -DisplayName "test-resources-$($baseName).microsoft.com"
$global:AzureTestSubscription = $SubscriptionId

Log "Created service principal '$($AzureTestPrincipal.ApplicationId)'"
Expand Down
7 changes: 7 additions & 0 deletions eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ else
exit 1
}

$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true

if (!$changelogIsValid)
{
Write-Host "The changelog [$($packageProperties.ChangeLogPath)] is not valid for release. Please make sure it is valid before queuing release build." -ForegroundColor Red
}

git diff -s --exit-code $packageProperties.DirectoryPath
if ($LASTEXITCODE -ne 0)
{
Expand Down
42 changes: 41 additions & 1 deletion eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,47 @@ if ($LatestsSorted[0] -ne $Version) {

if ($ReplaceLatestEntryTitle)
{
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $ChangeLogEntries[$LatestVersion].ReleaseContent
# Remove empty sections from content
$sanitizedContent = @()
$sectionContent = @()
$sectionContentCount = 0
$latesVersionContent = $ChangeLogEntries[$LatestVersion].ReleaseContent

foreach ($line in $latesVersionContent)
{
if ($line.StartsWith("### ") -or $sectionContentCount -gt 0)
{
if ($line.StartsWith("#") -and $sectionContentCount -gt 1)
{
$sanitizedContent += $sectionContent
$sectionContent = @()
$sectionContentCount = 0
}

if ($line.StartsWith("#") -and $sectionContentCount -eq 1)
{
$sectionContent = @()
$sectionContentCount = 0
}

$sectionContent += $line
if (-not [System.String]::IsNullOrWhiteSpace($line))
{
$sectionContentCount++
}
}
elseif ($sectionContent.Count -eq 0)
{
$sanitizedContent += $line
}
}

if ($sectionContentCount -gt 1)
{
$sanitizedContent += $sectionContent
}

$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $sanitizedContent
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
$ChangeLogEntries.Remove($LatestVersion)
if ($newChangeLogEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ params = qna.KnowledgeBaseQueryOptions(
question="How long should my Surface battery last?"
)

output = client.query_knowledge_base(
output = client.query_knowledgebase(
params,
project_name="FAQ",
)
Expand All @@ -93,18 +93,17 @@ You can set additional properties on `KnowledgeBaseQueryOptions` to limit the nu

### Ask a follow-up question

If your knowledge base 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:
If your knowledge base is configured for [chit-chat][questionanswering_docs_chat], the answers from the knowledge base may include suggested [prompts for follow-up questions][questionanswering_refdocs_prompts] to initiate a conversation. You can ask a follow-up question by providing the ID of your chosen answer as the context for the continued conversation:

```python
params = qna.models.KnowledgeBaseQueryOptions(
question="How long should charging take?"
context=qna.models.KnowledgeBaseAnswerRequestContext(
previous_user_query="How long should my Surface battery last?",
previous_qna_id=previous_answer.id
)
)

output = client.query_knowledge_base(
output = client.query_knowledgebase(
params,
project_name="FAQ"
)
Expand All @@ -127,7 +126,7 @@ params = qna.KnowledgeBaseQueryOptions(
question="How long should my Surface battery last?"
)

output = await client.query_knowledge_base(
output = await client.query_knowledgebase(
params,
project_name="FAQ"
)
Expand All @@ -148,7 +147,7 @@ For example, if you submit a question to a non-existant knowledge base, a `400`
from azure.core.exceptions import HttpResponseError

try:
client.query_knowledge_base(
client.query_knowledgebase(
params,
project_name="invalid-knowledge-base"
)
Expand Down Expand Up @@ -198,14 +197,15 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[azure_core_ref_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html
[azure_core_readme]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
[pip_link]:https://pypi.org/project/pip/
[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
[questionanswering_client_class]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-questionanswering/1.0.0b1/azure.ai.language.questionanswering.html#azure.ai.language.questionanswering.QuestionAnsweringClient
[questionanswering_refdocs_prompts]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-questionanswering/1.0.0b1/azure.ai.language.questionanswering.models.html#azure.ai.language.questionanswering.models.KnowledgeBaseAnswerDialog
[questionanswering_client_src]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
[questionanswering_docs]: https://azure.microsoft.com/services/cognitive-services/qna-maker/
[questionanswering_docs_chat]: https://docs.microsoft.com/azure/cognitive-services/qnamaker/how-to/chit-chat-knowledge-base
[questionanswering_docs_demos]: https://azure.microsoft.com/services/cognitive-services/qna-maker/#demo
[questionanswering_docs_features]: https://azure.microsoft.com/services/cognitive-services/qna-maker/#features
[questionanswering_pypi_package]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
[questionanswering_refdocs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/
[questionanswering_pypi_package]: https://pypi.org/project/azure-ai-language-questionanswering/
[questionanswering_refdocs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-language-questionanswering/1.0.0b1/azure.ai.language.questionanswering.html
[questionanswering_rest_docs]: https://docs.microsoft.com/rest/api/cognitiveservices-qnamaker/
[questionanswering_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitivelanguage/azure-ai-language-questionanswering/samples/README.md

Expand Down
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- The `text` property on `azure.core.rest.HttpResponse` and `azure.core.rest.AsyncHttpResponse` has changed to a method, which also takes
an `encoding` parameter.
- `azure.core.rest.HttpResponse` and `azure.core.rest.AsyncHttpResponse` are now abstract base classes. They should not be initialized directly, instead
your transport responses should inherit from them and implement them.

### Bugs Fixed

Expand Down
31 changes: 25 additions & 6 deletions sdk/core/azure-core/azure/core/_pipeline_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# --------------------------------------------------------------------------

import logging
from collections.abc import Iterable
import collections.abc
from typing import Any, Awaitable
from .configuration import Configuration
from .pipeline import AsyncPipeline
Expand Down Expand Up @@ -61,6 +61,26 @@

_LOGGER = logging.getLogger(__name__)

class _AsyncContextManager(collections.abc.Awaitable):

def __init__(self, wrapped: collections.abc.Awaitable):
super().__init__()
self.wrapped = wrapped
self.response = None

def __await__(self):
return self.wrapped.__await__()

async def __aenter__(self):
self.response = await self
return self.response

async def __aexit__(self, *args):
await self.response.__aexit__(*args)

async def close(self):
await self.response.close()


class AsyncPipelineClient(PipelineClientBase):
"""Service client core methods.
Expand Down Expand Up @@ -124,7 +144,7 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
config.proxy_policy,
ContentDecodePolicy(**kwargs)
]
if isinstance(per_call_policies, Iterable):
if isinstance(per_call_policies, collections.abc.Iterable):
policies.extend(per_call_policies)
else:
policies.append(per_call_policies)
Expand All @@ -133,7 +153,7 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
config.retry_policy,
config.authentication_policy,
config.custom_hook_policy])
if isinstance(per_retry_policies, Iterable):
if isinstance(per_retry_policies, collections.abc.Iterable):
policies.extend(per_retry_policies)
else:
policies.append(per_retry_policies)
Expand All @@ -142,13 +162,13 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
DistributedTracingPolicy(**kwargs),
config.http_logging_policy or HttpLoggingPolicy(**kwargs)])
else:
if isinstance(per_call_policies, Iterable):
if isinstance(per_call_policies, collections.abc.Iterable):
per_call_policies_list = list(per_call_policies)
else:
per_call_policies_list = [per_call_policies]
per_call_policies_list.extend(policies)
policies = per_call_policies_list
if isinstance(per_retry_policies, Iterable):
if isinstance(per_retry_policies, collections.abc.Iterable):
per_retry_policies_list = list(per_retry_policies)
else:
per_retry_policies_list = [per_retry_policies]
Expand Down Expand Up @@ -204,6 +224,5 @@ def send_request(
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.AsyncHttpResponse
"""
from .rest._rest_py3 import _AsyncContextManager
wrapped = self._make_pipeline_call(request, stream=stream, **kwargs)
return _AsyncContextManager(wrapped=wrapped)
3 changes: 1 addition & 2 deletions sdk/core/azure-core/azure/core/pipeline/_tools_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def _get_response_type(pipeline_transport_response):
return RestTrioRequestsTransportResponse
except ImportError:
pass
from ..rest import AsyncHttpResponse
return AsyncHttpResponse
raise ValueError("Unknown transport response")

async def read_in_response(response, is_stream_response: Optional[bool]) -> None:
try:
Expand Down
Loading

0 comments on commit c8cc257

Please sign in to comment.