Skip to content

Commit

Permalink
refactor: Moved the BaseModule class into it's own file, this helps b…
Browse files Browse the repository at this point in the history
…reak a circular dependency issue on a later change

PiperOrigin-RevId: 718548595
  • Loading branch information
google-genai-bot authored and copybara-github committed Jan 22, 2025
1 parent 76fdde7 commit 2f32d02
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
24 changes: 24 additions & 0 deletions google/genai/_api_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

"""Utilities for the API Modules of the Google Gen AI SDK."""

from . import _api_client


class BaseModule:

def __init__(self, api_client_: _api_client.ApiClient):
self._api_client = api_client_
6 changes: 0 additions & 6 deletions google/genai/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ def get_value_by_path(data: object, keys: list[str]):
return data


class BaseModule:

def __init__(self, api_client_: _api_client.ApiClient):
self._api_client = api_client_


def convert_to_dict(obj: dict[str, object]) -> dict[str, object]:
"""Recursively converts a given object to a dictionary.
Expand Down
5 changes: 3 additions & 2 deletions google/genai/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from typing import Optional, Union
from urllib.parse import urlencode
from . import _api_module
from . import _common
from . import _extra_utils
from . import _transformers as t
Expand Down Expand Up @@ -609,7 +610,7 @@ def _DeleteResourceJob_from_vertex(
return to_object


class Batches(_common.BaseModule):
class Batches(_api_module.BaseModule):

def _create(
self,
Expand Down Expand Up @@ -926,7 +927,7 @@ def list(
)


class AsyncBatches(_common.BaseModule):
class AsyncBatches(_api_module.BaseModule):

async def _create(
self,
Expand Down
5 changes: 3 additions & 2 deletions google/genai/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from typing import Optional, Union
from urllib.parse import urlencode
from . import _api_module
from . import _common
from . import _transformers as t
from . import types
Expand Down Expand Up @@ -1150,7 +1151,7 @@ def _ListCachedContentsResponse_from_vertex(
return to_object


class Caches(_common.BaseModule):
class Caches(_api_module.BaseModule):

def create(
self,
Expand Down Expand Up @@ -1473,7 +1474,7 @@ def list(
)


class AsyncCaches(_common.BaseModule):
class AsyncCaches(_api_module.BaseModule):

async def create(
self,
Expand Down
5 changes: 3 additions & 2 deletions google/genai/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pathlib
from typing import Optional, Union
from urllib.parse import urlencode
from . import _api_module
from . import _common
from . import _transformers as t
from . import types
Expand Down Expand Up @@ -499,7 +500,7 @@ def _DeleteFileResponse_from_vertex(
return to_object


class Files(_common.BaseModule):
class Files(_api_module.BaseModule):

def _list(
self, *, config: Optional[types.ListFilesConfigOrDict] = None
Expand Down Expand Up @@ -915,7 +916,7 @@ def download(
return data


class AsyncFiles(_common.BaseModule):
class AsyncFiles(_api_module.BaseModule):

async def _list(
self, *, config: Optional[types.ListFilesConfigOrDict] = None
Expand Down
3 changes: 2 additions & 1 deletion google/genai/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import google.auth
from websockets import ConnectionClosed

from . import _api_module
from . import _common
from . import _transformers as t
from . import client
Expand Down Expand Up @@ -470,7 +471,7 @@ async def close(self):
await self._ws.close()


class AsyncLive(_common.BaseModule):
class AsyncLive(_api_module.BaseModule):
"""AsyncLive."""

def _LiveSetup_to_mldev(
Expand Down
5 changes: 3 additions & 2 deletions google/genai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
from typing import AsyncIterator, Iterator, Optional, Union
from urllib.parse import urlencode
from . import _api_module
from . import _common
from . import _extra_utils
from . import _transformers as t
Expand Down Expand Up @@ -3716,7 +3717,7 @@ def _ComputeTokensResponse_from_vertex(
return to_object


class Models(_common.BaseModule):
class Models(_api_module.BaseModule):

def _generate_content(
self,
Expand Down Expand Up @@ -4685,7 +4686,7 @@ def list(
)


class AsyncModels(_common.BaseModule):
class AsyncModels(_api_module.BaseModule):

async def _generate_content(
self,
Expand Down
5 changes: 3 additions & 2 deletions google/genai/tunings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from typing import Optional, Union
from urllib.parse import urlencode
from . import _api_module
from . import _common
from . import _transformers as t
from . import types
Expand Down Expand Up @@ -902,7 +903,7 @@ def _TuningJobOrOperation_from_vertex(
return to_object


class Tunings(_common.BaseModule):
class Tunings(_api_module.BaseModule):

def _get(
self,
Expand Down Expand Up @@ -1186,7 +1187,7 @@ def tune(
return result


class AsyncTunings(_common.BaseModule):
class AsyncTunings(_api_module.BaseModule):

async def _get(
self,
Expand Down

0 comments on commit 2f32d02

Please sign in to comment.