From d80a54d542ae45b6ad3c3e3be37d9cf960427d4b Mon Sep 17 00:00:00 2001 From: Andrei Markin Date: Mon, 27 Jan 2025 19:30:49 +0400 Subject: [PATCH 1/3] [fl] Update server entrypoint Change-Id: Idec9657f0e19750f99abf7120d3e150f7dc4b8ec --- libs/filonov/filonov/entrypoints/server.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/filonov/filonov/entrypoints/server.py b/libs/filonov/filonov/entrypoints/server.py index b72096f..94b6f74 100644 --- a/libs/filonov/filonov/entrypoints/server.py +++ b/libs/filonov/filonov/entrypoints/server.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Provides HTTP endpoint for media similarity requests.""" +"""Provides HTTP endpoint for filonov requests.""" # pylint: disable=C0330, g-bad-import-order, g-multiple-import import os @@ -41,10 +41,13 @@ class CreativeMapPostRequest(pydantic.BaseModel): - """Specifies structure of request for tagging media. + """Specifies structure of request for returning creative map. Attributes: - media_paths: Identifiers or media to cluster (file names or links). + source: Source of getting data for creative map. + media_type: Type of media to get. + input_parameters: Parameters to get data from the source. + tagger: Type of tagger to use. normalize: Whether to apply normalization threshold. """ @@ -59,7 +62,7 @@ class CreativeMapPostRequest(pydantic.BaseModel): async def generate_creative_map( request: CreativeMapPostRequest, ) -> filonov.creative_map.CreativeMapJson: - """Performs media clustering.""" + """Generates Json with creative map data.""" input_service = filonov.MediaInputService(request.source) media_info, context = input_service.generate_media_info( request.media_type, request.input_parameters From 0ddc032adeb5f2c34197541c55f350dc809dd0c4 Mon Sep 17 00:00:00 2001 From: Andrei Markin Date: Mon, 27 Jan 2025 19:34:43 +0400 Subject: [PATCH 2/3] [fl] Provide specific error messages in MediaInputService Change-Id: I319ac4648b6692ab3dbd8f5d12bfbabeb9b134e8 --- libs/filonov/filonov/inputs/input_service.py | 59 ++++++++++++-------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/libs/filonov/filonov/inputs/input_service.py b/libs/filonov/filonov/inputs/input_service.py index f017276..ea039e8 100644 --- a/libs/filonov/filonov/inputs/input_service.py +++ b/libs/filonov/filonov/inputs/input_service.py @@ -16,7 +16,7 @@ """Module responsible for extracting media dimensions and metrics.""" -from typing import Literal +from typing import Literal, get_args from filonov.inputs import google_ads, interfaces, youtube @@ -24,11 +24,20 @@ Context = dict[str, str] +class MediaInputServiceError(Exception): + """Base exception for MediaInputService.""" + + class MediaInputService: """Extracts media information from a specified source.""" - def __init__(self, source: InputSource) -> None: + def __init__(self, source: InputSource = 'googleads') -> None: """Initializes InputService.""" + if source not in get_args(InputSource): + raise MediaInputServiceError( + f'Incorrect source: {source}. Only {get_args(InputSource)} ' + 'are supported.' + ) self.source = source def generate_media_info( @@ -46,10 +55,15 @@ def generate_media_info( Returns: Tuple with mapping between media identifiers and media info and a context. + + Raises: + MediaInputServiceError: When incomplete input parameters are supplied. """ if self.source == 'youtube': if not (channel := input_parameters.get('channel')): - raise ValueError + raise MediaInputServiceError( + 'Missing required argument `channel` for source `youtube`' + ) context = {'channel': channel} return ( youtube.ExtraInfoFetcher(channel).generate_extra_info(), @@ -57,7 +71,10 @@ def generate_media_info( ) if self.source == 'file': if 'performance_results_path' not in input_parameters: - raise ValueError + raise MediaInputServiceError( + 'Missing required argument `performance_results_path` ' + 'for source `file`' + ) return ( google_ads.from_file( media_type=media_type, @@ -66,21 +83,19 @@ def generate_media_info( ), {}, ) - if self.source == 'googleads': - if 'ads_config_path' in input_parameters: - ads_config = input_parameters.pop('ads_config_path') - if 'account' in input_parameters: - accounts = input_parameters.pop('account') - fetcher = google_ads.ExtraInfoFetcher( - accounts=accounts, ads_config=ads_config - ) - fetching_request = google_ads.FetchingRequest( - media_type=media_type, - **input_parameters, - ) - context = {**fetching_request.to_dict(), 'account': accounts} - return ( - fetcher.generate_extra_info(fetching_request, with_size_base), - context, - ) - raise ValueError + if 'ads_config_path' in input_parameters: + ads_config = input_parameters.pop('ads_config_path') + if 'account' in input_parameters: + accounts = input_parameters.pop('account') + fetcher = google_ads.ExtraInfoFetcher( + accounts=accounts, ads_config=ads_config + ) + fetching_request = google_ads.FetchingRequest( + media_type=media_type, + **input_parameters, + ) + context = {**fetching_request.to_dict(), 'account': accounts} + return ( + fetcher.generate_extra_info(fetching_request, with_size_base), + context, + ) From 8b1eb6f43cf29bf5a796cf77b2a9b01fef9afb26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 05:37:30 +0000 Subject: [PATCH 3/3] Bump the npm_and_yarn group across 1 directory with 2 updates Bumps the npm_and_yarn group with 2 updates in the /ui/creative-maps directory: [nanoid](https://github.com/ai/nanoid) and [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite). Updates `nanoid` from 3.3.7 to 3.3.8 - [Release notes](https://github.com/ai/nanoid/releases) - [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md) - [Commits](https://github.com/ai/nanoid/compare/3.3.7...3.3.8) Updates `vite` from 5.4.8 to 5.4.14 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v5.4.14/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.4.14/packages/vite) --- updated-dependencies: - dependency-name: nanoid dependency-type: indirect dependency-group: npm_and_yarn - dependency-name: vite dependency-type: indirect dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] --- ui/creative-maps/package-lock.json | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/creative-maps/package-lock.json b/ui/creative-maps/package-lock.json index c8727a5..87bedb7 100644 --- a/ui/creative-maps/package-lock.json +++ b/ui/creative-maps/package-lock.json @@ -7679,15 +7679,16 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -10602,10 +10603,11 @@ } }, "node_modules/vite": { - "version": "5.4.8", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.8.tgz", - "integrity": "sha512-FqrItQ4DT1NC4zCUqMB4c4AZORMKIa0m8/URVCZ77OZ/QSNeJ54bU1vrFADbDsuwfIPcgknRkmqakQcgnL4GiQ==", + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz", + "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==", "dev": true, + "license": "MIT", "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43",