google-genai 1.18.0__py3-none-any.whl → 1.19.0__py3-none-any.whl
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/_api_client.py +21 -1
- google/genai/_live_converters.py +7 -1
- google/genai/_tokens_converters.py +7 -1
- google/genai/caches.py +7 -1
- google/genai/models.py +21 -2
- google/genai/tokens.py +7 -2
- google/genai/types.py +36 -5
- google/genai/version.py +1 -1
- {google_genai-1.18.0.dist-info → google_genai-1.19.0.dist-info}/METADATA +1 -1
- {google_genai-1.18.0.dist-info → google_genai-1.19.0.dist-info}/RECORD +13 -13
- {google_genai-1.18.0.dist-info → google_genai-1.19.0.dist-info}/WHEEL +0 -0
- {google_genai-1.18.0.dist-info → google_genai-1.19.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.18.0.dist-info → google_genai-1.19.0.dist-info}/top_level.txt +0 -0
google/genai/_api_client.py
CHANGED
@@ -68,6 +68,26 @@ class EphemeralTokenAPIKeyError(ValueError):
|
|
68
68
|
"""Error raised when the API key is invalid."""
|
69
69
|
|
70
70
|
|
71
|
+
# This method checks for the API key in the environment variables. Google API
|
72
|
+
# key is precedenced over Gemini API key.
|
73
|
+
def _get_env_api_key() -> Optional[str]:
|
74
|
+
"""Gets the API key from environment variables, prioritizing GOOGLE_API_KEY.
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
The API key string if found, otherwise None. Empty string is considered
|
78
|
+
invalid.
|
79
|
+
"""
|
80
|
+
env_google_api_key = os.environ.get('GOOGLE_API_KEY', None)
|
81
|
+
env_gemini_api_key = os.environ.get('GEMINI_API_KEY', None)
|
82
|
+
if env_google_api_key and env_gemini_api_key:
|
83
|
+
logger.warning(
|
84
|
+
'Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using'
|
85
|
+
' GOOGLE_API_KEY.'
|
86
|
+
)
|
87
|
+
|
88
|
+
return env_google_api_key or env_gemini_api_key or None
|
89
|
+
|
90
|
+
|
71
91
|
def _append_library_version_headers(headers: dict[str, str]) -> None:
|
72
92
|
"""Appends the telemetry header to the headers dict."""
|
73
93
|
library_label = f'google-genai-sdk/{version.__version__}'
|
@@ -371,7 +391,7 @@ class BaseApiClient:
|
|
371
391
|
# Retrieve implicitly set values from the environment.
|
372
392
|
env_project = os.environ.get('GOOGLE_CLOUD_PROJECT', None)
|
373
393
|
env_location = os.environ.get('GOOGLE_CLOUD_LOCATION', None)
|
374
|
-
env_api_key =
|
394
|
+
env_api_key = _get_env_api_key()
|
375
395
|
self.project = project or env_project
|
376
396
|
self.location = location or env_location
|
377
397
|
self.api_key = api_key or env_api_key
|
google/genai/_live_converters.py
CHANGED
@@ -981,7 +981,13 @@ def _Tool_to_vertex(
|
|
981
981
|
)
|
982
982
|
|
983
983
|
if getv(from_object, ['url_context']) is not None:
|
984
|
-
|
984
|
+
setv(
|
985
|
+
to_object,
|
986
|
+
['urlContext'],
|
987
|
+
_UrlContext_to_vertex(
|
988
|
+
api_client, getv(from_object, ['url_context']), to_object
|
989
|
+
),
|
990
|
+
)
|
985
991
|
|
986
992
|
if getv(from_object, ['code_execution']) is not None:
|
987
993
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
@@ -981,7 +981,13 @@ def _Tool_to_vertex(
|
|
981
981
|
)
|
982
982
|
|
983
983
|
if getv(from_object, ['url_context']) is not None:
|
984
|
-
|
984
|
+
setv(
|
985
|
+
to_object,
|
986
|
+
['urlContext'],
|
987
|
+
_UrlContext_to_vertex(
|
988
|
+
api_client, getv(from_object, ['url_context']), to_object
|
989
|
+
),
|
990
|
+
)
|
985
991
|
|
986
992
|
if getv(from_object, ['code_execution']) is not None:
|
987
993
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
google/genai/caches.py
CHANGED
@@ -1092,7 +1092,13 @@ def _Tool_to_vertex(
|
|
1092
1092
|
)
|
1093
1093
|
|
1094
1094
|
if getv(from_object, ['url_context']) is not None:
|
1095
|
-
|
1095
|
+
setv(
|
1096
|
+
to_object,
|
1097
|
+
['urlContext'],
|
1098
|
+
_UrlContext_to_vertex(
|
1099
|
+
api_client, getv(from_object, ['url_context']), to_object
|
1100
|
+
),
|
1101
|
+
)
|
1096
1102
|
|
1097
1103
|
if getv(from_object, ['code_execution']) is not None:
|
1098
1104
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
google/genai/models.py
CHANGED
@@ -1422,7 +1422,11 @@ def _GenerateVideosConfig_to_mldev(
|
|
1422
1422
|
)
|
1423
1423
|
|
1424
1424
|
if getv(from_object, ['enhance_prompt']) is not None:
|
1425
|
-
|
1425
|
+
setv(
|
1426
|
+
parent_object,
|
1427
|
+
['parameters', 'enhancePrompt'],
|
1428
|
+
getv(from_object, ['enhance_prompt']),
|
1429
|
+
)
|
1426
1430
|
|
1427
1431
|
if getv(from_object, ['generate_audio']) is not None:
|
1428
1432
|
raise ValueError('generate_audio parameter is not supported in Gemini API.')
|
@@ -1981,7 +1985,13 @@ def _Tool_to_vertex(
|
|
1981
1985
|
)
|
1982
1986
|
|
1983
1987
|
if getv(from_object, ['url_context']) is not None:
|
1984
|
-
|
1988
|
+
setv(
|
1989
|
+
to_object,
|
1990
|
+
['urlContext'],
|
1991
|
+
_UrlContext_to_vertex(
|
1992
|
+
api_client, getv(from_object, ['url_context']), to_object
|
1993
|
+
),
|
1994
|
+
)
|
1985
1995
|
|
1986
1996
|
if getv(from_object, ['code_execution']) is not None:
|
1987
1997
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
@@ -4294,6 +4304,15 @@ def _Candidate_from_vertex(
|
|
4294
4304
|
if getv(from_object, ['finishReason']) is not None:
|
4295
4305
|
setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
|
4296
4306
|
|
4307
|
+
if getv(from_object, ['urlContextMetadata']) is not None:
|
4308
|
+
setv(
|
4309
|
+
to_object,
|
4310
|
+
['url_context_metadata'],
|
4311
|
+
_UrlContextMetadata_from_vertex(
|
4312
|
+
api_client, getv(from_object, ['urlContextMetadata']), to_object
|
4313
|
+
),
|
4314
|
+
)
|
4315
|
+
|
4297
4316
|
if getv(from_object, ['avgLogprobs']) is not None:
|
4298
4317
|
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
|
4299
4318
|
|
google/genai/tokens.py
CHANGED
@@ -143,6 +143,7 @@ class Tokens(_api_module.BaseModule):
|
|
143
143
|
Usage:
|
144
144
|
|
145
145
|
.. code-block:: python
|
146
|
+
|
146
147
|
# Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
147
148
|
# when using the token in Live API sessions. Each session connection can
|
148
149
|
# use a different configuration.
|
@@ -154,6 +155,7 @@ class Tokens(_api_module.BaseModule):
|
|
154
155
|
auth_token = client.tokens.create(config=config)
|
155
156
|
|
156
157
|
.. code-block:: python
|
158
|
+
|
157
159
|
# Case 2: If LiveEphemeralParameters is set, lock all fields in
|
158
160
|
# LiveConnectConfig when using the token in Live API sessions. For
|
159
161
|
# example, changing `output_audio_transcription` in the Live API
|
@@ -170,7 +172,9 @@ class Tokens(_api_module.BaseModule):
|
|
170
172
|
),
|
171
173
|
)
|
172
174
|
)
|
173
|
-
|
175
|
+
|
176
|
+
.. code-block:: python
|
177
|
+
|
174
178
|
# Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
|
175
179
|
# empty, lock LiveConnectConfig with set fields (e.g.
|
176
180
|
# system_instruction in this example) when using the token in Live API
|
@@ -187,7 +191,8 @@ class Tokens(_api_module.BaseModule):
|
|
187
191
|
)
|
188
192
|
)
|
189
193
|
|
190
|
-
|
194
|
+
.. code-block:: python
|
195
|
+
|
191
196
|
# Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
|
192
197
|
# set, lock LiveConnectConfig with set and additional fields (e.g.
|
193
198
|
# system_instruction, temperature in this example) when using the token
|
google/genai/types.py
CHANGED
@@ -59,17 +59,21 @@ _is_mcp_imported = False
|
|
59
59
|
if typing.TYPE_CHECKING:
|
60
60
|
from mcp import types as mcp_types
|
61
61
|
from mcp import ClientSession as McpClientSession
|
62
|
+
from mcp.types import CallToolResult as McpCallToolResult
|
62
63
|
|
63
64
|
_is_mcp_imported = True
|
64
65
|
else:
|
65
66
|
McpClientSession: typing.Type = Any
|
67
|
+
McpCallToolResult: typing.Type = Any
|
66
68
|
try:
|
67
69
|
from mcp import types as mcp_types
|
68
70
|
from mcp import ClientSession as McpClientSession
|
71
|
+
from mcp.types import CallToolResult as McpCallToolResult
|
69
72
|
|
70
73
|
_is_mcp_imported = True
|
71
74
|
except ImportError:
|
72
75
|
McpClientSession = None
|
76
|
+
McpCallToolResult = None
|
73
77
|
|
74
78
|
logger = logging.getLogger('google_genai.types')
|
75
79
|
|
@@ -845,6 +849,21 @@ class FunctionResponse(_common.BaseModel):
|
|
845
849
|
description="""Required. The function response in JSON object format. Use "output" key to specify function output and "error" key to specify error details (if any). If "output" and "error" keys are not specified, then whole "response" is treated as function output.""",
|
846
850
|
)
|
847
851
|
|
852
|
+
@classmethod
|
853
|
+
def from_mcp_response(
|
854
|
+
cls, *, name: str, response: McpCallToolResult
|
855
|
+
) -> 'FunctionResponse':
|
856
|
+
if not _is_mcp_imported:
|
857
|
+
raise ValueError(
|
858
|
+
'MCP response is not supported. Please ensure that the MCP library is'
|
859
|
+
' imported.'
|
860
|
+
)
|
861
|
+
|
862
|
+
if response.isError:
|
863
|
+
return cls(name=name, response={'error': 'MCP response is error.'})
|
864
|
+
else:
|
865
|
+
return cls(name=name, response={'result': response.content})
|
866
|
+
|
848
867
|
|
849
868
|
class FunctionResponseDict(TypedDict, total=False):
|
850
869
|
"""A function response."""
|
@@ -1925,12 +1944,16 @@ class FunctionDeclaration(_common.BaseModel):
|
|
1925
1944
|
from . import _automatic_function_calling_util
|
1926
1945
|
|
1927
1946
|
parameters_properties = {}
|
1947
|
+
annotation_under_future = typing.get_type_hints(callable)
|
1928
1948
|
for name, param in inspect.signature(callable).parameters.items():
|
1929
1949
|
if param.kind in (
|
1930
1950
|
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
1931
1951
|
inspect.Parameter.KEYWORD_ONLY,
|
1932
1952
|
inspect.Parameter.POSITIONAL_ONLY,
|
1933
1953
|
):
|
1954
|
+
# This snippet catches the case when type hints are stored as strings
|
1955
|
+
if isinstance(param.annotation, str):
|
1956
|
+
param = param.replace(annotation=annotation_under_future[name])
|
1934
1957
|
schema = _automatic_function_calling_util._parse_schema_from_parameter(
|
1935
1958
|
api_option, param, callable.__name__
|
1936
1959
|
)
|
@@ -1952,6 +1975,7 @@ class FunctionDeclaration(_common.BaseModel):
|
|
1952
1975
|
declaration.parameters
|
1953
1976
|
)
|
1954
1977
|
)
|
1978
|
+
# TODO: b/421991354 - Remove this check once the bug is fixed.
|
1955
1979
|
if api_option == 'GEMINI_API':
|
1956
1980
|
return declaration
|
1957
1981
|
|
@@ -1959,14 +1983,21 @@ class FunctionDeclaration(_common.BaseModel):
|
|
1959
1983
|
if return_annotation is inspect._empty:
|
1960
1984
|
return declaration
|
1961
1985
|
|
1986
|
+
return_value = inspect.Parameter(
|
1987
|
+
'return_value',
|
1988
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
1989
|
+
annotation=return_annotation,
|
1990
|
+
)
|
1991
|
+
|
1992
|
+
# This snippet catches the case when type hints are stored as strings
|
1993
|
+
if isinstance(return_value.annotation, str):
|
1994
|
+
return_value = return_value.replace(
|
1995
|
+
annotation=annotation_under_future['return']
|
1996
|
+
)
|
1962
1997
|
declaration.response = (
|
1963
1998
|
_automatic_function_calling_util._parse_schema_from_parameter(
|
1964
1999
|
api_option,
|
1965
|
-
|
1966
|
-
'return_value',
|
1967
|
-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
1968
|
-
annotation=return_annotation,
|
1969
|
-
),
|
2000
|
+
return_value,
|
1970
2001
|
callable.__name__,
|
1971
2002
|
)
|
1972
2003
|
)
|
google/genai/version.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
google/genai/__init__.py,sha256=SYTxz3Ho06pP2TBlvDU0FkUJz8ytbR3MgEpS9HvVYq4,709
|
2
2
|
google/genai/_adapters.py,sha256=Kok38miNYJff2n--l0zEK_hbq0y2rWOH7k75J7SMYbQ,1744
|
3
|
-
google/genai/_api_client.py,sha256=
|
3
|
+
google/genai/_api_client.py,sha256=AOhv4_L9aTDzT6ALvH54s5ozPUPCx4w4ShLdh8qpXvM,38879
|
4
4
|
google/genai/_api_module.py,sha256=lj8eUWx8_LBGBz-49qz6_ywWm3GYp3d8Bg5JoOHbtbI,902
|
5
5
|
google/genai/_automatic_function_calling_util.py,sha256=IJkPq2fT9pYxYm5Pbu5-e0nBoZKoZla7yT4_txWRKLs,10324
|
6
6
|
google/genai/_base_url.py,sha256=E5H4dew14Y16qfnB3XRnjSCi19cJVlkaMNoM_8ip-PM,1597
|
7
7
|
google/genai/_common.py,sha256=hDqunjaAL__GXZzhr37QGOCR6z6PMc_EfiRy_ukAxHo,11545
|
8
8
|
google/genai/_extra_utils.py,sha256=_w8hB9Ag7giRR94nIOBJFTLiLEufulPXkCZpJG1XY5g,19241
|
9
|
-
google/genai/_live_converters.py,sha256=
|
9
|
+
google/genai/_live_converters.py,sha256=8J0h9JUdkwkPFugFBAW4EKTMkZATMDZWgNkc9WOh2Hg,115488
|
10
10
|
google/genai/_mcp_utils.py,sha256=khECx-DMuHemKzOQQ3msWp7FivPeEOnl3n1lvWc_b5o,3833
|
11
11
|
google/genai/_replay_api_client.py,sha256=BrnKkdUVejpuHvqVHK0V4m4TjvL4LaBLHRMv6vw0vGE,21361
|
12
12
|
google/genai/_test_api_client.py,sha256=4ruFIy5_1qcbKqqIBu3HSQbpSOBrxiecBtDZaTGFR1s,4797
|
13
|
-
google/genai/_tokens_converters.py,sha256=
|
13
|
+
google/genai/_tokens_converters.py,sha256=IUmpIC7nKjZzp_azavxXgeML35nYSC0KRkCnGG0iZao,51477
|
14
14
|
google/genai/_transformers.py,sha256=Ii8u54Ni8388jU8OAei5sixZAmFP3o-OKbxomzBul4o,35557
|
15
15
|
google/genai/batches.py,sha256=gyNb--psM7cqXEP5RsJ908ismvsFFlDNRxt7mCwhYgM,34943
|
16
|
-
google/genai/caches.py,sha256=
|
16
|
+
google/genai/caches.py,sha256=Z1DiYwZUjY9zrCapfEFOz77lwfWyCsAbnrcMF2tr24g,68038
|
17
17
|
google/genai/chats.py,sha256=Hl08SbpSCMS0kYiBNGNzPI8q3rijGEW_up0g2Wun9cY,17044
|
18
18
|
google/genai/client.py,sha256=9AWoFL2g-OQFA4Zqpecg74b7h3i5Q9ZlXF4bFePV0zA,10759
|
19
19
|
google/genai/errors.py,sha256=nLAVglUGuPdLqLcnN_VCifoi7V17u9BQ9AfxUdRzZLg,4795
|
20
20
|
google/genai/files.py,sha256=PB5Rh5WiLOPHcqPR1inGyhqL9PiE0BFHSL4Dz9HKtl8,39516
|
21
21
|
google/genai/live.py,sha256=ZpXHO7AFayOz2viISxs34rlG85dFH9qk-5-qOC9pcZE,39375
|
22
22
|
google/genai/live_music.py,sha256=lO-nDz2gEJ8bYesJC1Aru4IrsV7raEePf4sH3QQT6yI,7119
|
23
|
-
google/genai/models.py,sha256=
|
23
|
+
google/genai/models.py,sha256=B9T4g7VLUiaZbUADKJG1UrVlvwQziZbUSgOXo3yj4oA,239463
|
24
24
|
google/genai/operations.py,sha256=wWGngU4N3U2y_JteBkwqTmoNncehk2NcZgPyHaVulfI,20304
|
25
25
|
google/genai/pagers.py,sha256=nyVYxp92rS-UaewO_oBgP593knofeLU6yOn6RolNoGQ,6797
|
26
26
|
google/genai/py.typed,sha256=RsMFoLwBkAvY05t6izop4UHZtqOPLiKp3GkIEizzmQY,40
|
27
|
-
google/genai/tokens.py,sha256=
|
27
|
+
google/genai/tokens.py,sha256=31HRdGkuN1VkHn21qKBwa6PeiLFGMN-aFldPIGo9WxE,12188
|
28
28
|
google/genai/tunings.py,sha256=aEKTVfpn6rYWEKu0CRaS93mo2iLQtX5K3nSqX6UB_jM,49500
|
29
|
-
google/genai/types.py,sha256=
|
30
|
-
google/genai/version.py,sha256=
|
31
|
-
google_genai-1.
|
32
|
-
google_genai-1.
|
33
|
-
google_genai-1.
|
34
|
-
google_genai-1.
|
35
|
-
google_genai-1.
|
29
|
+
google/genai/types.py,sha256=SjZ9GaMEHn_YoOHnCLQm0Sl9AsnYPqBVbExlF6l9fo4,437412
|
30
|
+
google/genai/version.py,sha256=4Bj2qKIYUQDZnSbV8me-05HqXSvijhv-sXzln7K77wA,627
|
31
|
+
google_genai-1.19.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
32
|
+
google_genai-1.19.0.dist-info/METADATA,sha256=AdmMMUAAVkTxCNDAANY8SJsTlxBoXVKg2zdxj4-RgOs,35579
|
33
|
+
google_genai-1.19.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
34
|
+
google_genai-1.19.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
35
|
+
google_genai-1.19.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|