diff --git a/python/semantic_kernel/connectors/search/__init__.py b/python/semantic_kernel/connectors/search/__init__.py index e69de29bb2d1..161788cf20d0 100644 --- a/python/semantic_kernel/connectors/search/__init__.py +++ b/python/semantic_kernel/connectors/search/__init__.py @@ -0,0 +1,5 @@ +# Copyright (c) Microsoft. All rights reserved. + +from semantic_kernel.connectors.search import bing, brave, google + +__all__ = ["bing", "brave", "google"] diff --git a/python/semantic_kernel/connectors/search/bing/bing_search.py b/python/semantic_kernel/connectors/search/bing.py similarity index 73% rename from python/semantic_kernel/connectors/search/bing/bing_search.py rename to python/semantic_kernel/connectors/search/bing.py index 3f2c983aa2cf..c7a7ede81435 100644 --- a/python/semantic_kernel/connectors/search/bing/bing_search.py +++ b/python/semantic_kernel/connectors/search/bing.py @@ -3,19 +3,11 @@ import logging from collections.abc import AsyncIterable from html import escape -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, ClassVar, Final from httpx import AsyncClient, HTTPStatusError, RequestError -from pydantic import ValidationError - -from semantic_kernel.connectors.search.bing.bing_search_response import BingSearchResponse -from semantic_kernel.connectors.search.bing.bing_search_settings import BingSettings -from semantic_kernel.connectors.search.bing.bing_web_page import BingWebPage -from semantic_kernel.connectors.search.bing.const import ( - DEFAULT_CUSTOM_URL, - DEFAULT_URL, - QUERY_PARAMETERS, -) +from pydantic import Field, SecretStr, ValidationError + from semantic_kernel.data.text_search import ( AnyTagsEqualTo, EqualTo, @@ -26,7 +18,7 @@ TextSearchResult, ) from semantic_kernel.exceptions import ServiceInitializationError, ServiceInvalidRequestError -from semantic_kernel.kernel_pydantic import KernelBaseModel +from semantic_kernel.kernel_pydantic import KernelBaseModel, KernelBaseSettings from semantic_kernel.utils.feature_stage_decorator import experimental from semantic_kernel.utils.telemetry.user_agent import SEMANTIC_KERNEL_USER_AGENT @@ -35,6 +27,109 @@ logger: logging.Logger = logging.getLogger(__name__) +# region Constants +DEFAULT_URL: Final[str] = "https://api.bing.microsoft.com/v7.0/search" +DEFAULT_CUSTOM_URL: Final[str] = "https://api.bing.microsoft.com/" +QUERY_PARAMETERS: Final[list[str]] = [ + "answerCount", + "cc", + "freshness", + "mkt", + "promote", + "responseFilter", + "safeSearch", + "setLang", + "textDecorations", + "textFormat", +] +QUERY_ADVANCED_SEARCH_KEYWORDS: Final[list[str]] = [ + "site", + "contains", + "ext", + "filetype", + "inanchor", + "inbody", + "intitle", + "ip", + "language", + "loc", + "location", + "prefer", + "feed", + "hasfeed", + "url", +] + + +# endregion Constants + + +# region BingSettings +class BingSettings(KernelBaseSettings): + """Bing Search settings. + + The settings are first loaded from environment variables with the prefix 'BING_'. If the + environment variables are not found, the settings can be loaded from a .env file with the + encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored; + however, validation will fail alerting that the settings are missing. + + Optional settings for prefix 'BING_' are: + - api_key: SecretStr - The Bing API key (Env var BING_API_KEY) + - custom_config: str - The Bing Custom Search instance's unique identifier (Env var BING_CUSTOM_CONFIG) + + """ + + env_prefix: ClassVar[str] = "BING_" + + api_key: SecretStr + custom_config: str | None = None + + +# endregion BingSettings + +# region BingWebPage + + +@experimental +class BingWebPage(KernelBaseModel): + """A Bing web page.""" + + id: str | None = None + name: str | None = None + url: str | None = None + display_url: str | None = None + snippet: str | None = None + date_last_crawled: str | None = None + deep_links: list["BingWebPage"] | None = None + open_graph_image: list[dict[str, str | int]] | None = None + search_tags: list[dict[str, str]] | None = None + language: str | None = None + is_family_friendly: bool | None = None + is_navigational: bool | None = None + + +@experimental +class BingWebPages(KernelBaseModel): + """The web pages from a Bing search.""" + + id: str | None = None + some_results_removed: bool | None = Field(default=None, alias="someResultsRemoved") + total_estimated_matches: int | None = Field(default=None, alias="totalEstimatedMatches") + web_search_url: str | None = Field(default=None, alias="webSearchUrl") + value: list[BingWebPage] = Field(default_factory=list) + + +@experimental +class BingSearchResponse(KernelBaseModel): + """The response from a Bing search.""" + + type_: str = Field(default="", alias="_type") + query_context: dict[str, Any] = Field(default_factory=dict, validation_alias="queryContext") + web_pages: BingWebPages | None = Field(default=None, alias="webPages") + + +# endregion BingWebPage + @experimental class BingSearch(KernelBaseModel, TextSearch): @@ -212,3 +307,6 @@ def _build_request_parameters(self, query: str, options: TextSearchOptions) -> d logger.debug("Any tag equals to filter is not supported by Bing Search API.") params["q"] = f"{query}+{f' {options.filter.group_type} '.join(extra_query_params)}".strip() return params + + +__all__ = ["BingSearch", "BingSearchResponse", "BingWebPage"] diff --git a/python/semantic_kernel/connectors/search/bing/__init__.py b/python/semantic_kernel/connectors/search/bing/__init__.py deleted file mode 100644 index 57cae52063d3..000000000000 --- a/python/semantic_kernel/connectors/search/bing/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from semantic_kernel.connectors.search.bing.bing_search import BingSearch -from semantic_kernel.connectors.search.bing.bing_web_page import BingWebPage - -__all__ = ["BingSearch", "BingWebPage"] diff --git a/python/semantic_kernel/connectors/search/bing/bing_search_response.py b/python/semantic_kernel/connectors/search/bing/bing_search_response.py deleted file mode 100644 index 784fecd7c859..000000000000 --- a/python/semantic_kernel/connectors/search/bing/bing_search_response.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import Any - -from pydantic import Field - -from semantic_kernel.connectors.search.bing.bing_web_page import BingWebPage -from semantic_kernel.kernel_pydantic import KernelBaseModel -from semantic_kernel.utils.feature_stage_decorator import experimental - - -@experimental -class BingWebPages(KernelBaseModel): - """The web pages from a Bing search.""" - - id: str | None = None - some_results_removed: bool | None = Field(default=None, alias="someResultsRemoved") - total_estimated_matches: int | None = Field(default=None, alias="totalEstimatedMatches") - web_search_url: str | None = Field(default=None, alias="webSearchUrl") - value: list[BingWebPage] = Field(default_factory=list) - - -@experimental -class BingSearchResponse(KernelBaseModel): - """The response from a Bing search.""" - - type_: str = Field(default="", alias="_type") - query_context: dict[str, Any] = Field(default_factory=dict, validation_alias="queryContext") - web_pages: BingWebPages | None = Field(default=None, alias="webPages") diff --git a/python/semantic_kernel/connectors/search/bing/bing_search_settings.py b/python/semantic_kernel/connectors/search/bing/bing_search_settings.py deleted file mode 100644 index 267d78aa91de..000000000000 --- a/python/semantic_kernel/connectors/search/bing/bing_search_settings.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import ClassVar - -from pydantic import SecretStr - -from semantic_kernel.kernel_pydantic import KernelBaseSettings - - -class BingSettings(KernelBaseSettings): - """Bing Search settings. - - The settings are first loaded from environment variables with the prefix 'BING_'. If the - environment variables are not found, the settings can be loaded from a .env file with the - encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored; - however, validation will fail alerting that the settings are missing. - - Optional settings for prefix 'BING_' are: - - api_key: SecretStr - The Bing API key (Env var BING_API_KEY) - - custom_config: str - The Bing Custom Search instance's unique identifier (Env var BING_CUSTOM_CONFIG) - - """ - - env_prefix: ClassVar[str] = "BING_" - - api_key: SecretStr - custom_config: str | None = None diff --git a/python/semantic_kernel/connectors/search/bing/bing_web_page.py b/python/semantic_kernel/connectors/search/bing/bing_web_page.py deleted file mode 100644 index 013462879bc6..000000000000 --- a/python/semantic_kernel/connectors/search/bing/bing_web_page.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - - -from semantic_kernel.kernel_pydantic import KernelBaseModel -from semantic_kernel.utils.feature_stage_decorator import experimental - - -@experimental -class BingWebPage(KernelBaseModel): - """A Bing web page.""" - - id: str | None = None - name: str | None = None - url: str | None = None - display_url: str | None = None - snippet: str | None = None - date_last_crawled: str | None = None - deep_links: list["BingWebPage"] | None = None - open_graph_image: list[dict[str, str | int]] | None = None - search_tags: list[dict[str, str]] | None = None - language: str | None = None - is_family_friendly: bool | None = None - is_navigational: bool | None = None diff --git a/python/semantic_kernel/connectors/search/bing/const.py b/python/semantic_kernel/connectors/search/bing/const.py deleted file mode 100644 index 6f755e3cd48b..000000000000 --- a/python/semantic_kernel/connectors/search/bing/const.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import Final - -DEFAULT_URL: Final[str] = "https://api.bing.microsoft.com/v7.0/search" -DEFAULT_CUSTOM_URL: Final[str] = "https://api.bing.microsoft.com/" -QUERY_PARAMETERS: Final[list[str]] = [ - "answerCount", - "cc", - "freshness", - "mkt", - "promote", - "responseFilter", - "safeSearch", - "setLang", - "textDecorations", - "textFormat", -] -QUERY_ADVANCED_SEARCH_KEYWORDS: Final[list[str]] = [ - "site", - "contains", - "ext", - "filetype", - "inanchor", - "inbody", - "intitle", - "ip", - "language", - "loc", - "location", - "prefer", - "feed", - "hasfeed", - "url", -] diff --git a/python/semantic_kernel/connectors/search/google/google_search.py b/python/semantic_kernel/connectors/search/google.py similarity index 58% rename from python/semantic_kernel/connectors/search/google/google_search.py rename to python/semantic_kernel/connectors/search/google.py index b2682c4b7b00..1b0a0eae5a8b 100644 --- a/python/semantic_kernel/connectors/search/google/google_search.py +++ b/python/semantic_kernel/connectors/search/google.py @@ -2,16 +2,12 @@ import logging from collections.abc import AsyncIterable -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, ClassVar, Final from urllib.parse import quote_plus from httpx import AsyncClient, HTTPStatusError, RequestError -from pydantic import ValidationError +from pydantic import Field, SecretStr, ValidationError -from semantic_kernel.connectors.search.google.const import CUSTOM_SEARCH_URL, QUERY_PARAMETERS -from semantic_kernel.connectors.search.google.google_search_response import GoogleSearchResponse -from semantic_kernel.connectors.search.google.google_search_result import GoogleSearchResult -from semantic_kernel.connectors.search.google.google_search_settings import GoogleSearchSettings from semantic_kernel.data.text_search import ( AnyTagsEqualTo, EqualTo, @@ -21,7 +17,7 @@ TextSearchResult, ) from semantic_kernel.exceptions import ServiceInitializationError, ServiceInvalidRequestError -from semantic_kernel.kernel_pydantic import KernelBaseModel +from semantic_kernel.kernel_pydantic import KernelBaseModel, KernelBaseSettings from semantic_kernel.utils.feature_stage_decorator import experimental from semantic_kernel.utils.telemetry.user_agent import SEMANTIC_KERNEL_USER_AGENT @@ -30,6 +26,134 @@ logger: logging.Logger = logging.getLogger(__name__) +# region Constants + +CUSTOM_SEARCH_URL: Final[str] = "https://www.googleapis.com/customsearch/v1" + +# For more info on this list: https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list +QUERY_PARAMETERS: Final[list[str]] = [ + # Country, Restricts search results to documents originating in a particular country. + # You may use Boolean operators in the cr parameter's value. + "cr", + # Date Restrict, Restricts results to URLs based on date. Supported values include: + # d[number]: requests results from the specified number of past days. + # w[number]: requests results from the specified number of past weeks. + # m[number]: requests results from the specified number of past months. + # y[number]: requests results from the specified number of past years. + "dateRestrict", + # exactTerms, Identifies a phrase that all documents in the search results must contain. + "exactTerms", + # excludeTerms, Identifies a word or phrase that should not appear in any documents in the search results. + "excludeTerms", + # fileType, Restricts results to files of a specified extension. A list of file types indexable by Google + # can be found in Search Console Help Center: https://support.google.com/webmasters/answer/35287 + "fileType", + # filter, Controls turning on or off the duplicate content filter. + "filter", + # gl, Geolocation of end user. The gl parameter value is a two-letter country code. The gl parameter boosts search + # results whose country of origin matches the parameter value. + # See the Country Codes page for a list of valid values. + "gl", + # highRange, Specifies the ending value for a search range. + "highRange", + # hl, Sets the user interface language. + "hl", + # linkSite, Specifies that all search results should contain a link to a particular URL. + "linkSite", + # Language of the result. Restricts the search to documents written in a particular language (e.g., lr=lang_ja). + "lr", + # or Terms, Provides additional search terms to check for in a document, where each document in the search results + # must contain at least one of the additional search terms. + "orTerms", + # rights, Filters based on licensing. Supported values include: + # cc_publicdomain, cc_attribute, cc_sharealike, cc_noncommercial, cc_nonderived + "rights", + # siteSearch, Specifies all search results should be pages from a given site. + "siteSearch", + # siteSearchFilter, Controls whether to include or exclude results from the site named in the siteSearch parameter. + "siteSearchFilter", +] + + +# endregion Constants + + +# region GoogleSettings +class GoogleSearchSettings(KernelBaseSettings): + """Google Search Connector settings. + + The settings are first loaded from environment variables with the prefix 'GOOGLE_'. If the + environment variables are not found, the settings can be loaded from a .env file with the + encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored; + however, validation will fail alerting that the settings are missing. + + Required settings for prefix 'GOOGLE_SEARCH_' are: + - api_key: SecretStr - The Google Search API key (Env var GOOGLE_SEARCH_API_KEY) + + Optional settings for prefix 'GOOGLE_SEARCH_' are: + - engine_id: str - The Google search engine ID (Env var GOOGLE_SEARCH_ENGINE_ID) + - env_file_path: str | None - if provided, the .env settings are read from this file path location + - env_file_encoding: str - if provided, the .env file encoding used. Defaults to "utf-8". + """ + + env_prefix: ClassVar[str] = "GOOGLE_SEARCH_" + + api_key: SecretStr + engine_id: str | None = None + + +# endregion GoogleSettings + +# region GoogleWeb + + +@experimental +class GoogleSearchInformation(KernelBaseModel): + """Information about the search.""" + + search_time: float = Field(alias="searchTime") + formatted_search_time: str = Field(alias="formattedSearchTime") + total_results: str = Field(alias="totalResults") + formatted_total_results: str = Field(alias="formattedTotalResults") + + +@experimental +class GoogleSearchResult(KernelBaseModel): + """A Google web page.""" + + kind: str = "" + title: str = "" + html_title: str = Field(default="", alias="htmlTitle") + link: str = "" + display_link: str = Field(default="", alias="displayLink") + snippet: str = "" + html_snippet: str = Field(default="", alias="htmlSnippet") + cache_id: str = Field(default="", alias="cacheId") + formatted_url: str = Field(default="", alias="formattedUrl") + html_formatted_url: str = Field(default="", alias="htmlFormattedUrl") + pagemap: dict[str, Any] = Field(default_factory=dict) + mime: str = "" + file_format: str = Field(default="", alias="fileFormat") + image: dict[str, Any] = Field(default_factory=dict) + labels: list[dict[str, Any]] = Field(default_factory=list) + + +@experimental +class GoogleSearchResponse(KernelBaseModel): + """The response from a Google search.""" + + kind: str = "" + url: dict[str, str] = Field(default_factory=dict) + queries: dict[str, list[dict[str, str | int]]] = Field(default_factory=dict) + context: dict[str, Any] = Field(default_factory=dict) + search_information: GoogleSearchInformation | None = None + spelling: dict[str, Any] = Field(default_factory=dict) + promotions: list[dict[str, Any]] = Field(default_factory=list) + items: list[GoogleSearchResult] | None = Field(None) + + +# endregion GoogleWeb + @experimental class GoogleSearch(KernelBaseModel, TextSearch): @@ -194,3 +318,10 @@ def _build_query(self, query: str, options: TextSearchOptions) -> str: elif isinstance(filter, AnyTagsEqualTo): logger.debug("AnyTagEqualTo filter is not supported by Google Search API.") return f"?q={quote_plus(query)}&{'&'.join(f'{k}={v}' for k, v in params.items())}" + + +__all__ = [ + "GoogleSearch", + "GoogleSearchResponse", + "GoogleSearchResult", +] diff --git a/python/semantic_kernel/connectors/search/google/__init__.py b/python/semantic_kernel/connectors/search/google/__init__.py deleted file mode 100644 index cd7cd98d6592..000000000000 --- a/python/semantic_kernel/connectors/search/google/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from semantic_kernel.connectors.search.google.google_search import GoogleSearch -from semantic_kernel.connectors.search.google.google_search_response import GoogleSearchResponse -from semantic_kernel.connectors.search.google.google_search_result import GoogleSearchResult - -__all__ = [ - "GoogleSearch", - "GoogleSearchResponse", - "GoogleSearchResult", -] diff --git a/python/semantic_kernel/connectors/search/google/const.py b/python/semantic_kernel/connectors/search/google/const.py deleted file mode 100644 index aff413293044..000000000000 --- a/python/semantic_kernel/connectors/search/google/const.py +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - - -from typing import Final - -CUSTOM_SEARCH_URL: Final[str] = "https://www.googleapis.com/customsearch/v1" - -# For more info on this list: https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list -QUERY_PARAMETERS: Final[list[str]] = [ - # Country, Restricts search results to documents originating in a particular country. - # You may use Boolean operators in the cr parameter's value. - "cr", - # Date Restrict, Restricts results to URLs based on date. Supported values include: - # d[number]: requests results from the specified number of past days. - # w[number]: requests results from the specified number of past weeks. - # m[number]: requests results from the specified number of past months. - # y[number]: requests results from the specified number of past years. - "dateRestrict", - # exactTerms, Identifies a phrase that all documents in the search results must contain. - "exactTerms", - # excludeTerms, Identifies a word or phrase that should not appear in any documents in the search results. - "excludeTerms", - # fileType, Restricts results to files of a specified extension. A list of file types indexable by Google - # can be found in Search Console Help Center: https://support.google.com/webmasters/answer/35287 - "fileType", - # filter, Controls turning on or off the duplicate content filter. - "filter", - # gl, Geolocation of end user. The gl parameter value is a two-letter country code. The gl parameter boosts search - # results whose country of origin matches the parameter value. - # See the Country Codes page for a list of valid values. - "gl", - # highRange, Specifies the ending value for a search range. - "highRange", - # hl, Sets the user interface language. - "hl", - # linkSite, Specifies that all search results should contain a link to a particular URL. - "linkSite", - # Language of the result. Restricts the search to documents written in a particular language (e.g., lr=lang_ja). - "lr", - # or Terms, Provides additional search terms to check for in a document, where each document in the search results - # must contain at least one of the additional search terms. - "orTerms", - # rights, Filters based on licensing. Supported values include: - # cc_publicdomain, cc_attribute, cc_sharealike, cc_noncommercial, cc_nonderived - "rights", - # siteSearch, Specifies all search results should be pages from a given site. - "siteSearch", - # siteSearchFilter, Controls whether to include or exclude results from the site named in the siteSearch parameter. - "siteSearchFilter", -] diff --git a/python/semantic_kernel/connectors/search/google/google_search_response.py b/python/semantic_kernel/connectors/search/google/google_search_response.py deleted file mode 100644 index 06c34f8f4bbf..000000000000 --- a/python/semantic_kernel/connectors/search/google/google_search_response.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import Any - -from pydantic import Field - -from semantic_kernel.connectors.search.google.google_search_result import GoogleSearchResult -from semantic_kernel.kernel_pydantic import KernelBaseModel -from semantic_kernel.utils.feature_stage_decorator import experimental - - -@experimental -class GoogleSearchInformation(KernelBaseModel): - """Information about the search.""" - - search_time: float = Field(alias="searchTime") - formatted_search_time: str = Field(alias="formattedSearchTime") - total_results: str = Field(alias="totalResults") - formatted_total_results: str = Field(alias="formattedTotalResults") - - -@experimental -class GoogleSearchResponse(KernelBaseModel): - """The response from a Google search.""" - - kind: str = "" - url: dict[str, str] = Field(default_factory=dict) - queries: dict[str, list[dict[str, str | int]]] = Field(default_factory=dict) - context: dict[str, Any] = Field(default_factory=dict) - search_information: GoogleSearchInformation | None = None - spelling: dict[str, Any] = Field(default_factory=dict) - promotions: list[dict[str, Any]] = Field(default_factory=list) - items: list[GoogleSearchResult] | None = Field(None) diff --git a/python/semantic_kernel/connectors/search/google/google_search_result.py b/python/semantic_kernel/connectors/search/google/google_search_result.py deleted file mode 100644 index ce273ef208af..000000000000 --- a/python/semantic_kernel/connectors/search/google/google_search_result.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import Any - -from pydantic import Field - -from semantic_kernel.kernel_pydantic import KernelBaseModel -from semantic_kernel.utils.feature_stage_decorator import experimental - - -@experimental -class GoogleSearchResult(KernelBaseModel): - """A Google web page.""" - - kind: str = "" - title: str = "" - html_title: str = Field(default="", alias="htmlTitle") - link: str = "" - display_link: str = Field(default="", alias="displayLink") - snippet: str = "" - html_snippet: str = Field(default="", alias="htmlSnippet") - cache_id: str = Field(default="", alias="cacheId") - formatted_url: str = Field(default="", alias="formattedUrl") - html_formatted_url: str = Field(default="", alias="htmlFormattedUrl") - pagemap: dict[str, Any] = Field(default_factory=dict) - mime: str = "" - file_format: str = Field(default="", alias="fileFormat") - image: dict[str, Any] = Field(default_factory=dict) - labels: list[dict[str, Any]] = Field(default_factory=list) diff --git a/python/semantic_kernel/connectors/search/google/google_search_settings.py b/python/semantic_kernel/connectors/search/google/google_search_settings.py deleted file mode 100644 index 31993318f825..000000000000 --- a/python/semantic_kernel/connectors/search/google/google_search_settings.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from typing import ClassVar - -from pydantic import SecretStr - -from semantic_kernel.kernel_pydantic import KernelBaseSettings - - -class GoogleSearchSettings(KernelBaseSettings): - """Google Search Connector settings. - - The settings are first loaded from environment variables with the prefix 'GOOGLE_'. If the - environment variables are not found, the settings can be loaded from a .env file with the - encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored; - however, validation will fail alerting that the settings are missing. - - Required settings for prefix 'GOOGLE_SEARCH_' are: - - api_key: SecretStr - The Google Search API key (Env var GOOGLE_SEARCH_API_KEY) - - Optional settings for prefix 'GOOGLE_SEARCH_' are: - - engine_id: str - The Google search engine ID (Env var GOOGLE_SEARCH_ENGINE_ID) - - env_file_path: str | None - if provided, the .env settings are read from this file path location - - env_file_encoding: str - if provided, the .env file encoding used. Defaults to "utf-8". - """ - - env_prefix: ClassVar[str] = "GOOGLE_SEARCH_" - - api_key: SecretStr - engine_id: str | None = None diff --git a/python/tests/unit/connectors/search/bing/test_bing_search.py b/python/tests/unit/connectors/search/bing/test_bing_search.py index 40c2403c4e29..646b1d9915bc 100644 --- a/python/tests/unit/connectors/search/bing/test_bing_search.py +++ b/python/tests/unit/connectors/search/bing/test_bing_search.py @@ -5,9 +5,7 @@ import httpx import pytest -from semantic_kernel.connectors.search.bing.bing_search import BingSearch -from semantic_kernel.connectors.search.bing.bing_search_response import BingSearchResponse, BingWebPages -from semantic_kernel.connectors.search.bing.bing_web_page import BingWebPage +from semantic_kernel.connectors.search.bing import BingSearch, BingSearchResponse, BingWebPage, BingWebPages from semantic_kernel.data.text_search import KernelSearchResults, SearchFilter, TextSearchOptions, TextSearchResult from semantic_kernel.exceptions import ServiceInitializationError, ServiceInvalidRequestError @@ -22,9 +20,7 @@ def bing_search(bing_unit_test_env): def async_client_mock(): """Set up the fixture to mock AsyncClient.""" async_client_mock = AsyncMock() - with patch( - "semantic_kernel.connectors.search.bing.bing_search.AsyncClient.__aenter__", return_value=async_client_mock - ): + with patch("semantic_kernel.connectors.search.bing.AsyncClient.__aenter__", return_value=async_client_mock): yield async_client_mock diff --git a/python/tests/unit/connectors/search/google/test_google_search.py b/python/tests/unit/connectors/search/google/test_google_search.py index 3a16b9010a0e..f7e5f8cf6341 100644 --- a/python/tests/unit/connectors/search/google/test_google_search.py +++ b/python/tests/unit/connectors/search/google/test_google_search.py @@ -5,12 +5,12 @@ import pytest from httpx import HTTPStatusError, RequestError, Response -from semantic_kernel.connectors.search.google.google_search import GoogleSearch -from semantic_kernel.connectors.search.google.google_search_response import ( +from semantic_kernel.connectors.search.google import ( + GoogleSearch, GoogleSearchInformation, GoogleSearchResponse, + GoogleSearchResult, ) -from semantic_kernel.connectors.search.google.google_search_result import GoogleSearchResult from semantic_kernel.data.text_search import AnyTagsEqualTo, EqualTo, TextSearchOptions from semantic_kernel.exceptions import ServiceInitializationError, ServiceInvalidRequestError