google-genai 1.43.0__tar.gz → 1.44.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_genai-1.43.0/google_genai.egg-info → google_genai-1.44.0}/PKG-INFO +1 -1
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_api_client.py +18 -4
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_operations_converters.py +6 -6
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_transformers.py +63 -63
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/live.py +17 -4
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/models.py +38 -8
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/version.py +1 -1
- {google_genai-1.43.0 → google_genai-1.44.0/google_genai.egg-info}/PKG-INFO +1 -1
- {google_genai-1.43.0 → google_genai-1.44.0}/pyproject.toml +1 -1
- {google_genai-1.43.0 → google_genai-1.44.0}/LICENSE +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/MANIFEST.in +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/README.md +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/__init__.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_adapters.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_base_url.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_common.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_extra_utils.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_live_converters.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_replay_api_client.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_tokens_converters.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/batches.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/caches.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/chats.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/client.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/errors.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/files.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/live_music.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/local_tokenizer.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/operations.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/pagers.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/py.typed +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/tokens.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/tunings.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google/genai/types.py +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google_genai.egg-info/SOURCES.txt +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google_genai.egg-info/requires.txt +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.43.0 → google_genai-1.44.0}/setup.cfg +0 -0
|
@@ -547,6 +547,7 @@ class BaseApiClient:
|
|
|
547
547
|
http_options: Optional[HttpOptionsOrDict] = None,
|
|
548
548
|
):
|
|
549
549
|
self.vertexai = vertexai
|
|
550
|
+
self.custom_base_url = None
|
|
550
551
|
if self.vertexai is None:
|
|
551
552
|
if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI', '0').lower() in [
|
|
552
553
|
'true',
|
|
@@ -628,11 +629,17 @@ class BaseApiClient:
|
|
|
628
629
|
)
|
|
629
630
|
self.api_key = None
|
|
630
631
|
|
|
632
|
+
self.custom_base_url = (
|
|
633
|
+
validated_http_options.base_url
|
|
634
|
+
if validated_http_options.base_url
|
|
635
|
+
else None
|
|
636
|
+
)
|
|
637
|
+
|
|
631
638
|
# Skip fetching project from ADC if base url is provided in http options.
|
|
632
639
|
if (
|
|
633
640
|
not self.project
|
|
634
641
|
and not self.api_key
|
|
635
|
-
and not
|
|
642
|
+
and not self.custom_base_url
|
|
636
643
|
):
|
|
637
644
|
credentials, self.project = load_auth(project=None)
|
|
638
645
|
if not self._credentials:
|
|
@@ -640,7 +647,7 @@ class BaseApiClient:
|
|
|
640
647
|
|
|
641
648
|
has_sufficient_auth = (self.project and self.location) or self.api_key
|
|
642
649
|
|
|
643
|
-
if not has_sufficient_auth and not
|
|
650
|
+
if not has_sufficient_auth and not self.custom_base_url:
|
|
644
651
|
# Skip sufficient auth check if base url is provided in http options.
|
|
645
652
|
raise ValueError(
|
|
646
653
|
'Project and location or API key must be set when using the Vertex '
|
|
@@ -648,9 +655,11 @@ class BaseApiClient:
|
|
|
648
655
|
)
|
|
649
656
|
if self.api_key or self.location == 'global':
|
|
650
657
|
self._http_options.base_url = f'https://aiplatform.googleapis.com/'
|
|
651
|
-
elif
|
|
658
|
+
elif self.custom_base_url and not has_sufficient_auth:
|
|
652
659
|
# Avoid setting default base url and api version if base_url provided.
|
|
653
|
-
|
|
660
|
+
# API gateway proxy can use the auth in custom headers, not url.
|
|
661
|
+
# Enable custom url if auth is not sufficient.
|
|
662
|
+
self._http_options.base_url = self.custom_base_url
|
|
654
663
|
else:
|
|
655
664
|
self._http_options.base_url = (
|
|
656
665
|
f'https://{self.location}-aiplatform.googleapis.com/'
|
|
@@ -897,6 +906,11 @@ class BaseApiClient:
|
|
|
897
906
|
)
|
|
898
907
|
|
|
899
908
|
def _websocket_base_url(self) -> str:
|
|
909
|
+
has_sufficient_auth = (self.project and self.location) or self.api_key
|
|
910
|
+
if self.custom_base_url and not has_sufficient_auth:
|
|
911
|
+
# API gateway proxy can use the auth in custom headers, not url.
|
|
912
|
+
# Enable custom url if auth is not sufficient.
|
|
913
|
+
return self.custom_base_url
|
|
900
914
|
url_parts = urlparse(self._http_options.base_url)
|
|
901
915
|
return url_parts._replace(scheme='wss').geturl() # type: ignore[arg-type, return-value]
|
|
902
916
|
|
|
@@ -201,11 +201,11 @@ def _GeneratedVideo_from_mldev(
|
|
|
201
201
|
parent_object: Optional[dict[str, Any]] = None,
|
|
202
202
|
) -> dict[str, Any]:
|
|
203
203
|
to_object: dict[str, Any] = {}
|
|
204
|
-
if getv(from_object, ['
|
|
204
|
+
if getv(from_object, ['video']) is not None:
|
|
205
205
|
setv(
|
|
206
206
|
to_object,
|
|
207
207
|
['video'],
|
|
208
|
-
_Video_from_mldev(getv(from_object, ['
|
|
208
|
+
_Video_from_mldev(getv(from_object, ['video']), to_object),
|
|
209
209
|
)
|
|
210
210
|
|
|
211
211
|
return to_object
|
|
@@ -261,14 +261,14 @@ def _Video_from_mldev(
|
|
|
261
261
|
parent_object: Optional[dict[str, Any]] = None,
|
|
262
262
|
) -> dict[str, Any]:
|
|
263
263
|
to_object: dict[str, Any] = {}
|
|
264
|
-
if getv(from_object, ['
|
|
265
|
-
setv(to_object, ['uri'], getv(from_object, ['
|
|
264
|
+
if getv(from_object, ['uri']) is not None:
|
|
265
|
+
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
|
266
266
|
|
|
267
|
-
if getv(from_object, ['
|
|
267
|
+
if getv(from_object, ['encodedVideo']) is not None:
|
|
268
268
|
setv(
|
|
269
269
|
to_object,
|
|
270
270
|
['video_bytes'],
|
|
271
|
-
base_t.t_bytes(getv(from_object, ['
|
|
271
|
+
base_t.t_bytes(getv(from_object, ['encodedVideo'])),
|
|
272
272
|
)
|
|
273
273
|
|
|
274
274
|
if getv(from_object, ['encoding']) is not None:
|
|
@@ -41,28 +41,6 @@ from . import types
|
|
|
41
41
|
|
|
42
42
|
logger = logging.getLogger('google_genai._transformers')
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
def _is_duck_type_of(obj: Any, cls: type[pydantic.BaseModel]) -> bool:
|
|
46
|
-
"""Checks if an object has all of the fields of a Pydantic model.
|
|
47
|
-
|
|
48
|
-
This is a duck-typing alternative to `isinstance` to solve dual-import
|
|
49
|
-
problems. It returns False for dictionaries, which should be handled by
|
|
50
|
-
`isinstance(obj, dict)`.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
obj: The object to check.
|
|
54
|
-
cls: The Pydantic model class to duck-type against.
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
True if the object has all the fields defined in the Pydantic model, False
|
|
58
|
-
otherwise.
|
|
59
|
-
"""
|
|
60
|
-
if isinstance(obj, dict) or not hasattr(cls, 'model_fields'):
|
|
61
|
-
return False
|
|
62
|
-
|
|
63
|
-
# Check if the object has all of the Pydantic model's defined fields.
|
|
64
|
-
return all(hasattr(obj, field) for field in cls.model_fields)
|
|
65
|
-
|
|
66
44
|
if sys.version_info >= (3, 10):
|
|
67
45
|
VersionedUnionType = builtin_types.UnionType
|
|
68
46
|
_UNION_TYPES = (typing.Union, builtin_types.UnionType)
|
|
@@ -94,6 +72,28 @@ metric_name_sdk_api_map = {
|
|
|
94
72
|
metric_name_api_sdk_map = {v: k for k, v in metric_name_sdk_api_map.items()}
|
|
95
73
|
|
|
96
74
|
|
|
75
|
+
def _is_duck_type_of(obj: Any, cls: type[pydantic.BaseModel]) -> bool:
|
|
76
|
+
"""Checks if an object has all of the fields of a Pydantic model.
|
|
77
|
+
|
|
78
|
+
This is a duck-typing alternative to `isinstance` to solve dual-import
|
|
79
|
+
problems. It returns False for dictionaries, which should be handled by
|
|
80
|
+
`isinstance(obj, dict)`.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
obj: The object to check.
|
|
84
|
+
cls: The Pydantic model class to duck-type against.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
True if the object has all the fields defined in the Pydantic model, False
|
|
88
|
+
otherwise.
|
|
89
|
+
"""
|
|
90
|
+
if isinstance(obj, dict) or not hasattr(cls, 'model_fields'):
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
# Check if the object has all of the Pydantic model's defined fields.
|
|
94
|
+
return all(hasattr(obj, field) for field in cls.model_fields)
|
|
95
|
+
|
|
96
|
+
|
|
97
97
|
def _resource_name(
|
|
98
98
|
client: _api_client.BaseApiClient,
|
|
99
99
|
resource_name: str,
|
|
@@ -306,7 +306,7 @@ def t_function_response(
|
|
|
306
306
|
raise ValueError('function_response is required.')
|
|
307
307
|
if isinstance(function_response, dict):
|
|
308
308
|
return types.FunctionResponse.model_validate(function_response)
|
|
309
|
-
elif
|
|
309
|
+
elif _is_duck_type_of(function_response, types.FunctionResponse):
|
|
310
310
|
return function_response
|
|
311
311
|
else:
|
|
312
312
|
raise TypeError(
|
|
@@ -342,8 +342,8 @@ def t_blob(blob: types.BlobImageUnionDict) -> types.Blob:
|
|
|
342
342
|
if not blob:
|
|
343
343
|
raise ValueError('blob is required.')
|
|
344
344
|
|
|
345
|
-
if
|
|
346
|
-
return blob
|
|
345
|
+
if _is_duck_type_of(blob, types.Blob):
|
|
346
|
+
return blob # type: ignore[return-value]
|
|
347
347
|
|
|
348
348
|
if isinstance(blob, dict):
|
|
349
349
|
return types.Blob.model_validate(blob)
|
|
@@ -383,10 +383,10 @@ def t_part(part: Optional[types.PartUnionDict]) -> types.Part:
|
|
|
383
383
|
raise ValueError('content part is required.')
|
|
384
384
|
if isinstance(part, str):
|
|
385
385
|
return types.Part(text=part)
|
|
386
|
-
if
|
|
387
|
-
if not part.uri or not part.mime_type:
|
|
386
|
+
if _is_duck_type_of(part, types.File):
|
|
387
|
+
if not part.uri or not part.mime_type: # type: ignore[union-attr]
|
|
388
388
|
raise ValueError('file uri and mime_type are required.')
|
|
389
|
-
return types.Part.from_uri(file_uri=part.uri, mime_type=part.mime_type)
|
|
389
|
+
return types.Part.from_uri(file_uri=part.uri, mime_type=part.mime_type) # type: ignore[union-attr]
|
|
390
390
|
if isinstance(part, dict):
|
|
391
391
|
try:
|
|
392
392
|
return types.Part.model_validate(part)
|
|
@@ -449,8 +449,8 @@ def t_content(
|
|
|
449
449
|
) -> types.Content:
|
|
450
450
|
if content is None:
|
|
451
451
|
raise ValueError('content is required.')
|
|
452
|
-
if
|
|
453
|
-
return content
|
|
452
|
+
if _is_duck_type_of(content, types.Content):
|
|
453
|
+
return content # type: ignore[return-value]
|
|
454
454
|
if isinstance(content, dict):
|
|
455
455
|
try:
|
|
456
456
|
return types.Content.model_validate(content)
|
|
@@ -461,15 +461,15 @@ def t_content(
|
|
|
461
461
|
if possible_part.function_call
|
|
462
462
|
else types.UserContent(parts=[possible_part])
|
|
463
463
|
)
|
|
464
|
-
if
|
|
465
|
-
return types.UserContent(parts=[t_part(content)])
|
|
466
|
-
if
|
|
464
|
+
if _is_duck_type_of(content, types.File):
|
|
465
|
+
return types.UserContent(parts=[t_part(content)]) # type: ignore[arg-type]
|
|
466
|
+
if _is_duck_type_of(content, types.Part):
|
|
467
467
|
return (
|
|
468
|
-
types.ModelContent(parts=[content])
|
|
469
|
-
if content.function_call
|
|
470
|
-
else types.UserContent(parts=[content])
|
|
468
|
+
types.ModelContent(parts=[content]) # type: ignore[arg-type]
|
|
469
|
+
if content.function_call # type: ignore[union-attr]
|
|
470
|
+
else types.UserContent(parts=[content]) # type: ignore[arg-type]
|
|
471
471
|
)
|
|
472
|
-
return types.UserContent(parts=content)
|
|
472
|
+
return types.UserContent(parts=content) # type: ignore[arg-type]
|
|
473
473
|
|
|
474
474
|
|
|
475
475
|
def t_contents_for_embed(
|
|
@@ -516,8 +516,8 @@ def t_contents(
|
|
|
516
516
|
) -> TypeGuard[types.PartUnionDict]:
|
|
517
517
|
if (
|
|
518
518
|
isinstance(part, str)
|
|
519
|
-
or
|
|
520
|
-
or
|
|
519
|
+
or _is_duck_type_of(part, types.File)
|
|
520
|
+
or _is_duck_type_of(part, types.Part)
|
|
521
521
|
):
|
|
522
522
|
return True
|
|
523
523
|
|
|
@@ -884,12 +884,12 @@ def t_schema(
|
|
|
884
884
|
return types.Schema.model_validate(origin)
|
|
885
885
|
if isinstance(origin, EnumMeta):
|
|
886
886
|
return _process_enum(origin, client)
|
|
887
|
-
if
|
|
888
|
-
if dict(origin) == dict(types.Schema()):
|
|
887
|
+
if _is_duck_type_of(origin, types.Schema):
|
|
888
|
+
if dict(origin) == dict(types.Schema()): # type: ignore [arg-type]
|
|
889
889
|
# response_schema value was coerced to an empty Schema instance because
|
|
890
890
|
# it did not adhere to the Schema field annotation
|
|
891
891
|
_raise_for_unsupported_schema_type(origin)
|
|
892
|
-
schema = origin.model_dump(exclude_unset=True)
|
|
892
|
+
schema = origin.model_dump(exclude_unset=True) # type: ignore[union-attr]
|
|
893
893
|
process_schema(schema, client)
|
|
894
894
|
return types.Schema.model_validate(schema)
|
|
895
895
|
|
|
@@ -926,8 +926,8 @@ def t_speech_config(
|
|
|
926
926
|
) -> Optional[types.SpeechConfig]:
|
|
927
927
|
if not origin:
|
|
928
928
|
return None
|
|
929
|
-
if
|
|
930
|
-
return origin
|
|
929
|
+
if _is_duck_type_of(origin, types.SpeechConfig):
|
|
930
|
+
return origin # type: ignore[return-value]
|
|
931
931
|
if isinstance(origin, str):
|
|
932
932
|
return types.SpeechConfig(
|
|
933
933
|
voice_config=types.VoiceConfig(
|
|
@@ -943,17 +943,17 @@ def t_speech_config(
|
|
|
943
943
|
def t_live_speech_config(
|
|
944
944
|
origin: types.SpeechConfigOrDict,
|
|
945
945
|
) -> Optional[types.SpeechConfig]:
|
|
946
|
-
if
|
|
946
|
+
if _is_duck_type_of(origin, types.SpeechConfig):
|
|
947
947
|
speech_config = origin
|
|
948
948
|
if isinstance(origin, dict):
|
|
949
949
|
speech_config = types.SpeechConfig.model_validate(origin)
|
|
950
950
|
|
|
951
|
-
if speech_config.multi_speaker_voice_config is not None:
|
|
951
|
+
if speech_config.multi_speaker_voice_config is not None: # type: ignore[union-attr]
|
|
952
952
|
raise ValueError(
|
|
953
953
|
'multi_speaker_voice_config is not supported in the live API.'
|
|
954
954
|
)
|
|
955
955
|
|
|
956
|
-
return speech_config
|
|
956
|
+
return speech_config # type: ignore[return-value]
|
|
957
957
|
|
|
958
958
|
|
|
959
959
|
def t_tool(
|
|
@@ -969,7 +969,7 @@ def t_tool(
|
|
|
969
969
|
)
|
|
970
970
|
]
|
|
971
971
|
)
|
|
972
|
-
elif McpTool is not None and
|
|
972
|
+
elif McpTool is not None and _is_duck_type_of(origin, McpTool):
|
|
973
973
|
return mcp_to_gemini_tool(origin)
|
|
974
974
|
elif isinstance(origin, dict):
|
|
975
975
|
return types.Tool.model_validate(origin)
|
|
@@ -1012,13 +1012,13 @@ def t_batch_job_source(
|
|
|
1012
1012
|
) -> types.BatchJobSource:
|
|
1013
1013
|
if isinstance(src, dict):
|
|
1014
1014
|
src = types.BatchJobSource(**src)
|
|
1015
|
-
if
|
|
1015
|
+
if _is_duck_type_of(src, types.BatchJobSource):
|
|
1016
1016
|
vertex_sources = sum(
|
|
1017
|
-
[src.gcs_uri is not None, src.bigquery_uri is not None]
|
|
1017
|
+
[src.gcs_uri is not None, src.bigquery_uri is not None] # type: ignore[union-attr]
|
|
1018
1018
|
)
|
|
1019
1019
|
mldev_sources = sum([
|
|
1020
|
-
src.inlined_requests is not None,
|
|
1021
|
-
src.file_name is not None,
|
|
1020
|
+
src.inlined_requests is not None, # type: ignore[union-attr]
|
|
1021
|
+
src.file_name is not None, # type: ignore[union-attr]
|
|
1022
1022
|
])
|
|
1023
1023
|
if client.vertexai:
|
|
1024
1024
|
if mldev_sources or vertex_sources != 1:
|
|
@@ -1033,7 +1033,7 @@ def t_batch_job_source(
|
|
|
1033
1033
|
'`inlined_embed_content_requests`, or `embed_content_file_name` '
|
|
1034
1034
|
'must be set, other sources are not supported in Gemini API.'
|
|
1035
1035
|
)
|
|
1036
|
-
return src
|
|
1036
|
+
return src # type: ignore[return-value]
|
|
1037
1037
|
|
|
1038
1038
|
elif isinstance(src, list):
|
|
1039
1039
|
return types.BatchJobSource(inlined_requests=src)
|
|
@@ -1063,7 +1063,7 @@ def t_embedding_batch_job_source(
|
|
|
1063
1063
|
if isinstance(src, dict):
|
|
1064
1064
|
src = types.EmbeddingsBatchJobSource(**src)
|
|
1065
1065
|
|
|
1066
|
-
if
|
|
1066
|
+
if _is_duck_type_of(src, types.EmbeddingsBatchJobSource):
|
|
1067
1067
|
mldev_sources = sum([
|
|
1068
1068
|
src.inlined_requests is not None,
|
|
1069
1069
|
src.file_name is not None,
|
|
@@ -1098,7 +1098,7 @@ def t_batch_job_destination(
|
|
|
1098
1098
|
)
|
|
1099
1099
|
else:
|
|
1100
1100
|
raise ValueError(f'Unsupported destination: {dest}')
|
|
1101
|
-
elif
|
|
1101
|
+
elif _is_duck_type_of(dest, types.BatchJobDestination):
|
|
1102
1102
|
return dest
|
|
1103
1103
|
else:
|
|
1104
1104
|
raise ValueError(f'Unsupported destination: {dest}')
|
|
@@ -1198,13 +1198,13 @@ def t_file_name(
|
|
|
1198
1198
|
name: Optional[Union[str, types.File, types.Video, types.GeneratedVideo]],
|
|
1199
1199
|
) -> str:
|
|
1200
1200
|
# Remove the files/ prefix since it's added to the url path.
|
|
1201
|
-
if
|
|
1202
|
-
name = name.name
|
|
1203
|
-
elif
|
|
1204
|
-
name = name.uri
|
|
1205
|
-
elif
|
|
1206
|
-
if name.video is not None:
|
|
1207
|
-
name = name.video.uri
|
|
1201
|
+
if _is_duck_type_of(name, types.File):
|
|
1202
|
+
name = name.name # type: ignore[union-attr]
|
|
1203
|
+
elif _is_duck_type_of(name, types.Video):
|
|
1204
|
+
name = name.uri # type: ignore[union-attr]
|
|
1205
|
+
elif _is_duck_type_of(name, types.GeneratedVideo):
|
|
1206
|
+
if name.video is not None: # type: ignore[union-attr]
|
|
1207
|
+
name = name.video.uri # type: ignore[union-attr]
|
|
1208
1208
|
else:
|
|
1209
1209
|
name = None
|
|
1210
1210
|
|
|
@@ -1247,7 +1247,7 @@ def t_tuning_job_status(status: str) -> Union[types.JobState, str]:
|
|
|
1247
1247
|
def t_content_strict(content: types.ContentOrDict) -> types.Content:
|
|
1248
1248
|
if isinstance(content, dict):
|
|
1249
1249
|
return types.Content.model_validate(content)
|
|
1250
|
-
elif
|
|
1250
|
+
elif _is_duck_type_of(content, types.Content):
|
|
1251
1251
|
return content
|
|
1252
1252
|
else:
|
|
1253
1253
|
raise ValueError(
|
|
@@ -980,7 +980,8 @@ class AsyncLive(_api_module.BaseModule):
|
|
|
980
980
|
api_key = self._api_client.api_key
|
|
981
981
|
version = self._api_client._http_options.api_version
|
|
982
982
|
uri = f'{base_url}/ws/google.cloud.aiplatform.{version}.LlmBidiService/BidiGenerateContent'
|
|
983
|
-
|
|
983
|
+
original_headers = self._api_client._http_options.headers
|
|
984
|
+
headers = original_headers.copy() if original_headers is not None else {}
|
|
984
985
|
|
|
985
986
|
request_dict = _common.convert_to_dict(
|
|
986
987
|
live_converters._LiveConnectParameters_to_vertex(
|
|
@@ -1012,12 +1013,24 @@ class AsyncLive(_api_module.BaseModule):
|
|
|
1012
1013
|
bearer_token = creds.token
|
|
1013
1014
|
original_headers = self._api_client._http_options.headers
|
|
1014
1015
|
headers = original_headers.copy() if original_headers is not None else {}
|
|
1015
|
-
headers
|
|
1016
|
+
if not headers.get('Authorization'):
|
|
1017
|
+
headers['Authorization'] = f'Bearer {bearer_token}'
|
|
1016
1018
|
version = self._api_client._http_options.api_version
|
|
1017
|
-
|
|
1019
|
+
|
|
1020
|
+
has_sufficient_auth = (
|
|
1021
|
+
self._api_client.project and self._api_client.location
|
|
1022
|
+
)
|
|
1023
|
+
if self._api_client.custom_base_url and not has_sufficient_auth:
|
|
1024
|
+
# API gateway proxy can use the auth in custom headers, not url.
|
|
1025
|
+
# Enable custom url if auth is not sufficient.
|
|
1026
|
+
uri = self._api_client.custom_base_url
|
|
1027
|
+
# Keep the model as is.
|
|
1028
|
+
transformed_model = model
|
|
1029
|
+
else:
|
|
1030
|
+
uri = f'{base_url}/ws/google.cloud.aiplatform.{version}.LlmBidiService/BidiGenerateContent'
|
|
1018
1031
|
location = self._api_client.location
|
|
1019
1032
|
project = self._api_client.project
|
|
1020
|
-
if transformed_model.startswith('publishers/'):
|
|
1033
|
+
if transformed_model.startswith('publishers/') and project and location:
|
|
1021
1034
|
transformed_model = (
|
|
1022
1035
|
f'projects/{project}/locations/{location}/' + transformed_model
|
|
1023
1036
|
)
|
|
@@ -2262,11 +2262,11 @@ def _GeneratedVideo_from_mldev(
|
|
|
2262
2262
|
parent_object: Optional[dict[str, Any]] = None,
|
|
2263
2263
|
) -> dict[str, Any]:
|
|
2264
2264
|
to_object: dict[str, Any] = {}
|
|
2265
|
-
if getv(from_object, ['
|
|
2265
|
+
if getv(from_object, ['video']) is not None:
|
|
2266
2266
|
setv(
|
|
2267
2267
|
to_object,
|
|
2268
2268
|
['video'],
|
|
2269
|
-
_Video_from_mldev(getv(from_object, ['
|
|
2269
|
+
_Video_from_mldev(getv(from_object, ['video']), to_object),
|
|
2270
2270
|
)
|
|
2271
2271
|
|
|
2272
2272
|
return to_object
|
|
@@ -3680,14 +3680,14 @@ def _Video_from_mldev(
|
|
|
3680
3680
|
parent_object: Optional[dict[str, Any]] = None,
|
|
3681
3681
|
) -> dict[str, Any]:
|
|
3682
3682
|
to_object: dict[str, Any] = {}
|
|
3683
|
-
if getv(from_object, ['
|
|
3684
|
-
setv(to_object, ['uri'], getv(from_object, ['
|
|
3683
|
+
if getv(from_object, ['uri']) is not None:
|
|
3684
|
+
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
|
3685
3685
|
|
|
3686
|
-
if getv(from_object, ['
|
|
3686
|
+
if getv(from_object, ['encodedVideo']) is not None:
|
|
3687
3687
|
setv(
|
|
3688
3688
|
to_object,
|
|
3689
3689
|
['video_bytes'],
|
|
3690
|
-
base_t.t_bytes(getv(from_object, ['
|
|
3690
|
+
base_t.t_bytes(getv(from_object, ['encodedVideo'])),
|
|
3691
3691
|
)
|
|
3692
3692
|
|
|
3693
3693
|
if getv(from_object, ['encoding']) is not None:
|
|
@@ -3723,12 +3723,12 @@ def _Video_to_mldev(
|
|
|
3723
3723
|
) -> dict[str, Any]:
|
|
3724
3724
|
to_object: dict[str, Any] = {}
|
|
3725
3725
|
if getv(from_object, ['uri']) is not None:
|
|
3726
|
-
setv(to_object, ['
|
|
3726
|
+
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
|
3727
3727
|
|
|
3728
3728
|
if getv(from_object, ['video_bytes']) is not None:
|
|
3729
3729
|
setv(
|
|
3730
3730
|
to_object,
|
|
3731
|
-
['
|
|
3731
|
+
['encodedVideo'],
|
|
3732
3732
|
base_t.t_bytes(getv(from_object, ['video_bytes'])),
|
|
3733
3733
|
)
|
|
3734
3734
|
|
|
@@ -5448,6 +5448,36 @@ class Models(_api_module.BaseModule):
|
|
|
5448
5448
|
'Source and prompt/image/video are mutually exclusive.'
|
|
5449
5449
|
+ ' Please only use source.'
|
|
5450
5450
|
)
|
|
5451
|
+
# Gemini Developer API does not support video bytes.
|
|
5452
|
+
video_dct: dict[str, Any] = {}
|
|
5453
|
+
if not self._api_client.vertexai and video:
|
|
5454
|
+
if isinstance(video, types.Video):
|
|
5455
|
+
video_dct = video.model_dump()
|
|
5456
|
+
else:
|
|
5457
|
+
video_dct = dict(video)
|
|
5458
|
+
|
|
5459
|
+
if video_dct.get('uri') and video_dct.get('video_bytes'):
|
|
5460
|
+
video = types.Video(
|
|
5461
|
+
uri=video_dct.get('uri'), mime_type=video_dct.get('mime_type')
|
|
5462
|
+
)
|
|
5463
|
+
elif not self._api_client.vertexai and source:
|
|
5464
|
+
if isinstance(source, types.GenerateVideosSource):
|
|
5465
|
+
source_dct = source.model_dump()
|
|
5466
|
+
video_dct = source_dct.get('video', {})
|
|
5467
|
+
else:
|
|
5468
|
+
source_dct = dict(source)
|
|
5469
|
+
if isinstance(source_dct.get('video'), types.Video):
|
|
5470
|
+
video_obj: types.Video = source_dct.get('video', types.Video())
|
|
5471
|
+
video_dct = video_obj.model_dump()
|
|
5472
|
+
if video_dct and video_dct.get('uri') and video_dct.get('video_bytes'):
|
|
5473
|
+
source = types.GenerateVideosSource(
|
|
5474
|
+
prompt=source_dct.get('prompt'),
|
|
5475
|
+
image=source_dct.get('image'),
|
|
5476
|
+
video=types.Video(
|
|
5477
|
+
uri=video_dct.get('uri'),
|
|
5478
|
+
mime_type=video_dct.get('mime_type'),
|
|
5479
|
+
),
|
|
5480
|
+
)
|
|
5451
5481
|
return self._generate_videos(
|
|
5452
5482
|
model=model,
|
|
5453
5483
|
prompt=prompt,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{google_genai-1.43.0 → google_genai-1.44.0}/google/genai/_automatic_function_calling_util.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|