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

[AutoPR cognitiveservices/data-plane/AutoSuggest] Description of Autosuggest usage needs improvement. #3806

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
4 changes: 4 additions & 0 deletions azure-cognitiveservices-search-autosuggest/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include *.rst
include azure/__init__.py
include azure/cognitiveservices/__init__.py
include azure/cognitiveservices/search/__init__.py

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
# regenerated.
# --------------------------------------------------------------------------

from .auto_suggest_search_api import AutoSuggestSearchAPI
from .auto_suggest_client import AutoSuggestClient
from .version import VERSION

__all__ = ['AutoSuggestSearchAPI']
__all__ = ['AutoSuggestClient']

__version__ = VERSION

Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,57 @@
from . import models


class AutoSuggestSearchAPIConfiguration(Configuration):
"""Configuration for AutoSuggestSearchAPI
class AutoSuggestClientConfiguration(Configuration):
"""Configuration for AutoSuggestClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: "https://westus.api.cognitive.microsoft.com",
"https://api.cognitive.microsoft.com").
:type endpoint: str
:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""

def __init__(
self, credentials, base_url=None):
self, endpoint, credentials):

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if not base_url:
base_url = 'https://api.cognitive.microsoft.com/bing/v7.0'
base_url = '{Endpoint}/bing/v7.0'

super(AutoSuggestSearchAPIConfiguration, self).__init__(base_url)
super(AutoSuggestClientConfiguration, self).__init__(base_url)

self.add_user_agent('azure-cognitiveservices-search-autosuggest/{}'.format(VERSION))

self.endpoint = endpoint
self.credentials = credentials


class AutoSuggestSearchAPI(SDKClient):
"""The AutoSuggest Search API lets you send a search query to Bing and get back a list of news that are relevant to the search query. This section provides technical details about the query parameters and headers that you use to request news and the JSON response objects that contain them. For examples that show how to make requests, see [Searching the web for AutoSuggest](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-autosuggest-api-v7-reference).
class AutoSuggestClient(SDKClient):
"""Autosuggest supplies search terms derived from a root text sent to the service. The terms Autosuggest supplies are related to the root text based on similarity and their frequency or ratings of usefulness in other searches. For examples that show how to use Autosuggest, see [Search using AutoSuggest](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-autosuggest-api-v7-reference).
:ivar config: Configuration for client.
:vartype config: AutoSuggestSearchAPIConfiguration
:vartype config: AutoSuggestClientConfiguration
:param endpoint: Supported Cognitive Services endpoints (protocol and
hostname, for example: "https://westus.api.cognitive.microsoft.com",
"https://api.cognitive.microsoft.com").
:type endpoint: str
:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""

def __init__(
self, credentials, base_url=None):
self, endpoint, credentials):

self.config = AutoSuggestSearchAPIConfiguration(credentials, base_url)
super(AutoSuggestSearchAPI, self).__init__(self.config.credentials, self.config)
self.config = AutoSuggestClientConfiguration(endpoint, credentials)
super(AutoSuggestClient, self).__init__(self.config.credentials, self.config)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = '1.0'
Expand All @@ -69,9 +77,9 @@ def __init__(
def auto_suggest(
self, query, accept_language=None, pragma=None, user_agent=None, client_id=None, client_ip=None, location=None, country_code=None, market="en-us", safe_search=None, set_lang=None, response_format=None, custom_headers=None, raw=False, **operation_config):
"""The AutoSuggest API lets you send a search query to Bing and get back a
list of suggestions. This section provides technical details about the
query parameters and headers that you use to request suggestions and
the JSON response objects that contain them.
list of query suggestions. This section provides technical details
about the query parameters and headers that you use to request
suggestions and the JSON response objects that contain them.
:param query: The user's search term.
:type query: str
Expand Down Expand Up @@ -270,6 +278,10 @@ def auto_suggest(

# Construct URL
url = self.auto_suggest.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
Expand All @@ -287,7 +299,7 @@ def auto_suggest(

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
header_parameters['Accept'] = 'application/json'
if custom_headers:
header_parameters.update(custom_headers)
header_parameters['X-BingApis-SDK'] = self._serialize.header("x_bing_apis_sdk", x_bing_apis_sdk, 'str')
Expand All @@ -305,8 +317,8 @@ def auto_suggest(
header_parameters['X-Search-Location'] = self._serialize.header("location", location, 'str')

# Construct and send request
request = self._client.get(url, query_parameters)
response = self._client.send(request, header_parameters, stream=False, **operation_config)
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
raise models.ErrorResponseException(self._deserialize, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .error_response import ErrorResponse, ErrorResponseException
from .creative_work import CreativeWork
from .response_base import ResponseBase
from .auto_suggest_search_api_enums import (
from .auto_suggest_client_enums import (
ScenarioType,
SearchKind,
ErrorCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# regenerated.
# --------------------------------------------------------------------------

VERSION = "0.1.0"
VERSION = "1.0"

1 change: 1 addition & 0 deletions azure-cognitiveservices-search-autosuggest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
]),
install_requires=[
'msrest>=0.5.0',
'msrestazure>=0.4.32,<2.0.0',
'azure-common~=1.1',
],
extras_require={
Expand Down