Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QnA] Added method overloads #19876

Merged
merged 7 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -80,8 +80,8 @@ params = qna.KnowledgeBaseQueryOptions(
)

output = client.query_knowledgebase(
params,
project_name="FAQ",
knowledge_base_query_options=params
)
for candidate in output.answers:
print("({}) {}".format(candidate.confidence_score, candidate.answer))
Expand All @@ -105,8 +105,8 @@ params = qna.models.KnowledgeBaseQueryOptions(
)

output = client.query_knowledgebase(
project_name="FAQ",
knowledge_base_query_options=params
params,
project_name="FAQ"
)
for candidate in output.answers:
print("({}) {}".format(candidate.confidence_score, candidate.answer))
Expand All @@ -128,8 +128,8 @@ params = qna.KnowledgeBaseQueryOptions(
)

output = await client.query_knowledgebase(
project_name="FAQ",
knowledge_base_query_options=params
params,
project_name="FAQ"
)
```

Expand All @@ -149,8 +149,8 @@ from azure.core.exceptions import HttpResponseError

try:
client.query_knowledgebase(
project_name="invalid-knowledge-base",
knowledge_base_query_options=params
params,
project_name="invalid-knowledge-base"
)
except HttpResponseError as error:
print("Query failed: {}".format(error.message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import functools
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
from typing import Any, Callable, Dict, Generic, Optional, TypeVar, overload, Union, List
import warnings

from azure.core.exceptions import (
Expand All @@ -27,6 +27,7 @@


class QuestionAnsweringClientOperationsMixin:
@overload
async def query_knowledgebase(
self,
knowledge_base_query_options: "_models.KnowledgeBaseQueryOptions",
Expand All @@ -37,24 +38,100 @@ async def query_knowledgebase(
) -> "_models.KnowledgeBaseAnswers":
"""Answers the specified question using your knowledge base.

Answers the specified question using your knowledge base.

:keyword project_name: The name of the project to use.
annatisch marked this conversation as resolved.
Show resolved Hide resolved
:paramtype project_name: str
:param knowledge_base_query_options: Post body of the request.
:type knowledge_base_query_options:
~azure.ai.language.questionanswering.models.KnowledgeBaseQueryOptions
:keyword deployment_name: The name of the specific deployment of the project to use.
:paramtype deployment_name: str
: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
"""
...

@overload
async def query_knowledgebase(
self,
*,
project_name: str,
deployment_name: Optional[str] = None,
qna_id: Optional[int] = None,
question: Optional[str] = None,
top: Optional[int] = None,
user_id: Optional[str] = None,
confidence_score_threshold: Optional[float] = None,
context: Optional["_models.KnowledgeBaseAnswerRequestContext"] = None,
ranker_type: Optional[Union[str, "_models.RankerType"]] = None,
strict_filters: Optional["_models.StrictFilters"] = None,
answer_span_request: Optional["_models.AnswerSpanRequest"] = None,
include_unstructured_sources: Optional[bool] = None,
**kwargs: Any
) -> "_models.KnowledgeBaseAnswers":
"""Answers the specified question using your knowledge base.

: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.
: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
"""
...

async def query_knowledgebase(
self,
*args,
**kwargs: Any
) -> "_models.KnowledgeBaseAnswers":
if args:
knowledge_base_query_options = args[0]
else:
knowledge_base_query_options = _models.KnowledgeBaseQueryOptions(
qna_id=kwargs.pop("qna_id", None),
question=kwargs.pop("question", None),
top=kwargs.pop("top", None),
user_id=kwargs.pop("user_id", None),
confidence_score_threshold=kwargs.pop("confidence_score_threshold", None),
context=kwargs.pop("context", None),
ranker_type=kwargs.pop("ranker_type", None),
strict_filters=kwargs.pop("strict_filters", None),
answer_span_request=kwargs.pop("answer_span_request", None),
include_unstructured_sources=kwargs.pop("include_unstructured_sources", None)
)
cls = kwargs.pop("cls", None) # type: ClsType["_models.KnowledgeBaseAnswers"]
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
error_map.update(kwargs.pop("error_map", {}))
content_type = kwargs.pop("content_type", "application/json") # type: Optional[str]
project_name = kwargs.pop("project_name") # type: str
deployment_name = kwargs.pop("deployment_name", None) # type: Optional[str]

json = self._serialize.body(knowledge_base_query_options, "KnowledgeBaseQueryOptions")

Expand Down Expand Up @@ -89,18 +166,65 @@ async def query_knowledgebase(

query_knowledgebase.metadata = {"url": "/:query-knowledgebases"} # type: ignore

async def query_text(self, text_query_options: "_models.TextQueryOptions", **kwargs: Any) -> "_models.TextAnswers":
@overload
async def query_text(
self, text_query_options: "_models.TextQueryOptions", **kwargs: Any
) -> "_models.TextAnswers":
"""Answers the specified question using the provided text in the body.

Answers the specified question using the provided text in the body.

:param text_query_options: Post body of the request.
:type text_query_options: ~azure.ai.language.questionanswering.models.TextQueryOptions
: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
"""
...

@overload
async def query_text(
self,
*,
question: str,
records: List["_models.TextRecord"],
language: Optional[str] = None,
string_index_type: Optional[Union[str, "_models.StringIndexType"]] = "TextElements_v8",
**kwargs: Any
) -> "_models.TextAnswers":
"""Answers the specified question using the provided text in the body.

:keyword question: Required. User question to query against the given text records.
:paramtype question: str
:keyword records: Required. Text records to be searched for given question.
:paramtype records: list[~azure.ai.language.questionanswering.models.TextRecord]
: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
"""
...

async def query_text(
self, *args, **kwargs: Any
) -> "_models.TextAnswers":
if args:
text_query_options = args[0]
else:
text_query_options = _models.TextQueryOptions(
question=kwargs.pop("question"),
records=kwargs.pop("records"),
language=kwargs.pop("language", None),
string_index_type=kwargs.pop("string_index_type", "TextElements_v8")
)
cls = kwargs.pop("cls", None) # type: ClsType["_models.TextAnswers"]
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
error_map.update(kwargs.pop("error_map", {}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import functools
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, overload
import warnings

from azure.core.exceptions import (
Expand All @@ -31,6 +31,7 @@


class QuestionAnsweringClientOperationsMixin(object):
@overload
def query_knowledgebase(
self,
knowledge_base_query_options, # type: "_models.KnowledgeBaseQueryOptions"
Expand All @@ -39,8 +40,6 @@ def query_knowledgebase(
# type: (...) -> "_models.KnowledgeBaseAnswers"
"""Answers the specified question using your knowledge base.

Answers the specified question using your knowledge base.

:param knowledge_base_query_options: Post body of the request.
:type knowledge_base_query_options:
~azure.ai.language.questionanswering.models.KnowledgeBaseQueryOptions
Expand All @@ -53,6 +52,71 @@ def query_knowledgebase(
:rtype: ~azure.ai.language.questionanswering.models.KnowledgeBaseAnswers
:raises: ~azure.core.exceptions.HttpResponseError
"""
pass

@overload
def query_knowledgebase(
self,
**kwargs # type: Any
):
# type: (...) -> "_models.KnowledgeBaseAnswers"
"""Answers the specified question using your knowledge base.

: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.
: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
"""
pass

def query_knowledgebase(
self,
*args, # type: "_models.KnowledgeBaseQueryOptions"
**kwargs # type: Any
):
# type: (...) -> "_models.KnowledgeBaseAnswers"
if args:
knowledge_base_query_options = args[0]
else:
knowledge_base_query_options = _models.KnowledgeBaseQueryOptions(
qna_id=kwargs.pop("qna_id", None),
question=kwargs.pop("question", None),
top=kwargs.pop("top", None),
user_id=kwargs.pop("user_id", None),
confidence_score_threshold=kwargs.pop("confidence_score_threshold", None),
context=kwargs.pop("context", None),
ranker_type=kwargs.pop("ranker_type", None),
strict_filters=kwargs.pop("strict_filters", None),
answer_span_request=kwargs.pop("answer_span_request", None),
include_unstructured_sources=kwargs.pop("include_unstructured_sources", None)
)
cls = kwargs.pop("cls", None) # type: ClsType["_models.KnowledgeBaseAnswers"]
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
error_map.update(kwargs.pop("error_map", {}))
Expand Down Expand Up @@ -91,6 +155,7 @@ def query_knowledgebase(

query_knowledgebase.metadata = {"url": "/:query-knowledgebases"} # type: ignore

@overload
def query_text(
self,
text_query_options, # type: "_models.TextQueryOptions"
Expand All @@ -99,15 +164,58 @@ def query_text(
# type: (...) -> "_models.TextAnswers"
"""Answers the specified question using the provided text in the body.

Answers the specified question using the provided text in the body.

:param text_query_options: Post body of the request.
:type text_query_options: ~azure.ai.language.questionanswering.models.TextQueryOptions
: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
"""
pass

@overload
def query_text(
self,
**kwargs # type: Any
):
# type: (...) -> "_models.TextAnswers"
"""Answers the specified question using the provided text in the body.

:keyword question: Required. User question to query against the given text records.
:paramtype question: str
:keyword records: Required. Text records to be searched for given question.
: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
"""
pass

def query_text(
self,
*args, # type: "_models.TextQueryOptions"
**kwargs # type: Any
):
# type: (...) -> "_models.TextAnswers"
if args:
text_query_options = args[0]
else:
text_query_options = _models.TextQueryOptions(
question=kwargs.pop("question"),
records=kwargs.pop("records"),
language=kwargs.pop("language", None),
string_index_type=kwargs.pop("string_index_type", "TextElements_v8")
)
cls = kwargs.pop("cls", None) # type: ClsType["_models.TextAnswers"]
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
error_map.update(kwargs.pop("error_map", {}))
Expand Down
Loading