Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 1.0.0b1 (unreleased)
## 1.0.0b1 (2021-07-27)

### Features Added
* Initial release.
* Initial release - supports querying from text records and knowledge bases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I should probably do something like that.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install azure-ai-language-questionanswering

### Authenticate the client

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].
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** to instantiate a client object. For more information regarding authenticating with Cognitive Services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth].

#### Get an API key

Expand Down Expand Up @@ -56,7 +56,7 @@ client = QuestionAnsweringClient(endpoint, credential)

### QuestionAnsweringClient

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.
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.
For asynchronous operations, an async `QuestionAnsweringClient` is in the `azure.ai.language.questionanswering.aio` namespace.

## Examples
Expand Down Expand Up @@ -140,7 +140,7 @@ Optional keyword arguments can be passed in at the client and per-operation leve

### General
Azure QuestionAnswering clients raise exceptions defined in [Azure Core][azure_core_readme].
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.
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.

For example, if you submit a question to a non-existant knowledge base, a `400` error is returned indicating "Bad Request".

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@


class QuestionAnsweringClient(QuestionAnsweringClientOperationsMixin):
"""The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, language detection and question answering. Further documentation can be found in :code:`<a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview">https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview</a>`.
"""The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, language detection and question answering. Further documentation can be found in https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for review purposes, would be great - if heredoc supports it (I actually don't know) - if this was separated on multiple lines. GH doesn't make this easy to review otherwise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - this is in autorest, there were a couple of docs quirks I had to manually edit - but they're rendering okay.


:param endpoint: Supported Cognitive Services endpoint (e.g.,
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
https://<resource-name>.api.cognitiveservices.azure.com).
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.AzureKeyCredential
Expand Down Expand Up @@ -57,21 +57,8 @@ def send_request(
):
# type: (...) -> HttpResponse
"""Runs the network request through the client's chained policies.

We have helper methods to create requests specific to this service in `azure.ai.language.questionanswering.rest`.
Use these helper methods to create the request you pass to this method. See our example below:

>>> from azure.ai.language.questionanswering.rest import build_query_knowledgebase_request
>>> request = build_query_knowledgebase_request(project_name=project_name, json=json, content=content, deployment_name=deployment_name, **kwargs)
<HttpRequest [POST], url: '/:query-knowledgebases'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart

For advanced cases, you can also create your own :class:`~azure.core.rest.HttpRequest`
and pass it in.

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@


class QuestionAnsweringClient(QuestionAnsweringClientOperationsMixin):
"""The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, language detection and question answering. Further documentation can be found in :code:`<a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview">https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview</a>`.
"""The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, language detection and question answering. Further documentation can be found in https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview.

:param endpoint: Supported Cognitive Services endpoint (e.g.,
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
https://<resource-name>.api.cognitiveservices.azure.com).
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.AzureKeyCredential
Expand All @@ -41,10 +41,7 @@ def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any)

def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]:
"""Runs the network request through the client's chained policies.

For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
For advanced cases, you can also create your own :class:`~azure.core.rest.HttpRequest`
and pass it in.

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,43 @@ async def query_knowledgebase(
*args,
**kwargs: Any
) -> "_models.KnowledgeBaseAnswers":
"""Answers the specified question using your knowledge base.

:param knowledge_base_query_options: Post body of the request. Provide either `knowledge_base_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:type knowledge_base_query_options:
~azure.ai.language.questionanswering.models.KnowledgeBaseQueryOptions
:keyword project_name: The name of the project to use.
:paramtype project_name: str
:keyword deployment_name: The name of the specific deployment of the project to use.
:paramtype deployment_name: str
:keyword qna_id: Exact QnA ID to fetch from the knowledge base, this field takes priority over question.
:paramtype qna_id: int
:keyword question: User question to query against the knowledge base. Provide either `knowledge_base_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:paramtype question: str
:keyword top: Max number of answers to be returned for the question.
:paramtype top: int
:keyword user_id: Unique identifier for the user.
:paramtype user_id: str
:keyword confidence_score_threshold: Minimum threshold score for answers, value ranges from 0 to 1.
:paramtype confidence_score_threshold: float
:keyword context: Context object with previous QnA's information.
:paramtype context: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswerRequestContext
:keyword ranker_type: (Optional) Set to 'QuestionOnly' for using a question only Ranker. Possible
values include: "Default", "QuestionOnly".
:paramtype ranker_type: str or ~azure.ai.language.questionanswering.models.RankerType
:keyword strict_filters: Filter QnAs based on give metadata list and knowledge base source names.
:paramtype strict_filters: ~azure.ai.language.questionanswering.models.StrictFilters
:keyword answer_span_request: To configure Answer span prediction feature.
:paramtype answer_span_request: ~azure.ai.language.questionanswering.models.AnswerSpanRequest
:keyword include_unstructured_sources: (Optional) Flag to enable Query over Unstructured Sources.
:paramtype include_unstructured_sources: bool
:keyword callable cls: A custom type or function that will be passed the direct response
:return: KnowledgeBaseAnswers, or the result of cls(response)
:rtype: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswers
:raises: ~azure.core.exceptions.HttpResponseError
"""
if args:
knowledge_base_query_options = args[0]
else:
Expand Down Expand Up @@ -216,6 +253,30 @@ async def query_text(
async def query_text(
self, *args, **kwargs: Any
) -> "_models.TextAnswers":
"""Answers the specified question using the provided text in the body.

:param text_query_options: Post body of the request. Provide either `text_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:type text_query_options: ~azure.ai.language.questionanswering.models.TextQueryOptions
:keyword question: User question to query against the given text records. Provide either `text_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:paramtype question: str
:keyword records: Text records to be searched for given question. Provide either `text_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:paramtype records: list[~azure.ai.language.questionanswering.models.TextRecord]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it these can't also just be strings, right? From the implementation I don't see any auto-incrementing like Text Analytics did, which I copied for .NET.

Probably don't need to worry about it now, but you might open an issue to consider for beta 2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will open an issue for this.

:keyword language: Language of the text records. This is BCP-47 representation of a language. For
example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default.
:paramtype language: str
:keyword string_index_type: Specifies the method used to interpret string offsets. Defaults to
Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see
https://aka.ms/text-analytics-offsets. Possible values include: "TextElements_v8",
"UnicodeCodePoint", "Utf16CodeUnit". Default value: "TextElements_v8".
:paramtype string_index_type: str or ~azure.ai.language.questionanswering.models.StringIndexType
:keyword callable cls: A custom type or function that will be passed the direct response
:return: TextAnswers, or the result of cls(response)
:rtype: ~azure.ai.language.questionanswering.models.TextAnswers
:raises: ~azure.core.exceptions.HttpResponseError
"""
if args:
text_query_options = args[0]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ def query_knowledgebase(
**kwargs # type: Any
):
# type: (...) -> "_models.KnowledgeBaseAnswers"
"""Answers the specified question using your knowledge base.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the method now be query_knowledge_base? I'm using QueryKnowledgeBase in .NET.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm that's a good point - I think this happened because my swagger readme file was redefining the operations IDs of the APIs - and so the capitalization change in the operation was ignored. I will open an issue for this.


:param knowledge_base_query_options: Post body of the request. Provide either `knowledge_base_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:type knowledge_base_query_options:
~azure.ai.language.questionanswering.models.KnowledgeBaseQueryOptions
:keyword project_name: The name of the project to use.
:paramtype project_name: str
:keyword deployment_name: The name of the specific deployment of the project to use.
:paramtype deployment_name: str
:keyword question: User question to query against the knowledge base. Provide either `knowledge_base_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:paramtype question: str
:keyword qna_id: Exact QnA ID to fetch from the knowledge base, this field takes priority over question.
:paramtype qna_id: int
:keyword top: Max number of answers to be returned for the question.
:paramtype top: int
:keyword user_id: Unique identifier for the user.
:paramtype user_id: str
:keyword confidence_score_threshold: Minimum threshold score for answers, value ranges from 0 to 1.
:paramtype confidence_score_threshold: float
:keyword context: Context object with previous QnA's information.
:paramtype context: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswerRequestContext
:keyword ranker_type: (Optional) Set to 'QuestionOnly' for using a question only Ranker. Possible
values include: "Default", "QuestionOnly".
:paramtype ranker_type: str or ~azure.ai.language.questionanswering.models.RankerType
:keyword strict_filters: Filter QnAs based on give metadata list and knowledge base source names.
:paramtype strict_filters: ~azure.ai.language.questionanswering.models.StrictFilters
:keyword answer_span_request: To configure Answer span prediction feature.
:paramtype answer_span_request: ~azure.ai.language.questionanswering.models.AnswerSpanRequest
:keyword include_unstructured_sources: (Optional) Flag to enable Query over Unstructured Sources.
:paramtype include_unstructured_sources: bool
:keyword callable cls: A custom type or function that will be passed the direct response
:return: KnowledgeBaseAnswers, or the result of cls(response)
:rtype: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswers
:raises: ~azure.core.exceptions.HttpResponseError
"""
if args:
knowledge_base_query_options = args[0]
else:
Expand Down Expand Up @@ -207,6 +244,30 @@ def query_text(
**kwargs # type: Any
):
# type: (...) -> "_models.TextAnswers"
"""Answers the specified question using the provided text in the body.

:param text_query_options: Post body of the request. Provide either `text_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:type text_query_options: ~azure.ai.language.questionanswering.models.TextQueryOptions
:keyword question: User question to query against the given text records. Provide either `text_query_options`,
OR individual keyword arguments. If both are provided, only the options object will be used.
:paramtype question: str
:keyword records: Text records to be searched for given question. Provide either `text_query_options`, OR
individual keyword arguments. If both are provided, only the options object will be used.
:paramtype records: list[~azure.ai.language.questionanswering.models.TextInput]
:keyword language: Language of the text records. This is BCP-47 representation of a language. For
example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default.
:paramtype language: str
:keyword string_index_type: Specifies the method used to interpret string offsets. Defaults to
Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see
https://aka.ms/text-analytics-offsets. Possible values include: "TextElements_v8",
"UnicodeCodePoint", "Utf16CodeUnit". Default value: "TextElements_v8".
:paramtype string_index_type: str or ~azure.ai.language.questionanswering.models.StringIndexType
:keyword callable cls: A custom type or function that will be passed the direct response
:return: TextAnswers, or the result of cls(response)
:rtype: ~azure.ai.language.questionanswering.models.TextAnswers
:raises: ~azure.core.exceptions.HttpResponseError
"""
if args:
text_query_options = args[0]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ These sample programs show common scenarios for the QuestionAnswering client's o

## Setup

1. Install the Azure QuestionAnswering client library for Python with [pip][pip]):
1. Install the Azure QuestionAnswering client library for Python with [pip][pip]:
```bash
pip install --pre azure-ai-language-questionanswering
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
# This means any folder structure that only consists of a __init__.py.
# For example, for storage, this would mean adding 'azure.storage'
# in addition to the default 'azure' that is seen here.
'azure'
'azure',
'azure.ai',
'azure.ai.language',
]),
install_requires=[
'azure-core<2.0.0,>=1.16.0',
"msrest>=0.6.21"
'msrest>=0.6.21',
'chardet>=3.0.2,<5'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: trailing comma makes the diff cleaner next time, like you did on line 66 above.

],
extras_require={
":python_version<'3.0'": ['futures', 'azure-ai-language-nspkg'],
Expand Down
2 changes: 1 addition & 1 deletion sdk/nspkg/azure-ai-language-nspkg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Release History

## 1.0.0 (unreleased)
## 1.0.0 (2021-07-27)
3 changes: 3 additions & 0 deletions sdk/nspkg/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ extends:
- name: azure-ai-translation-nspkg
safeName: azureaitranslationnspkg
skipVerifyChangeLog: true
- name: azure-ai-language-nspkg
safeName: azureailanguagenspkg
skipVerifyChangeLog: true
- name: azure-communication-nspkg
safeName: azurecommunicationnspkg
skipVerifyChangeLog: true
Expand Down
1 change: 1 addition & 0 deletions shared_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ six>=1.11.0
isodate>=0.6.0
avro<2.0.0,>=1.10.0
pyjwt>=1.7.1
chardet<5,>=3.0.2
#override azure azure-keyvault~=1.0
#override azure-mgmt-core azure-core<2.0.0,>=1.15.0
#override azure-containerregistry azure-core>=1.4.0,<2.0.0
Expand Down