google-genai 1.18.0__tar.gz → 1.19.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.
Files changed (41) hide show
  1. {google_genai-1.18.0/google_genai.egg-info → google_genai-1.19.0}/PKG-INFO +1 -1
  2. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_api_client.py +21 -1
  3. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_live_converters.py +7 -1
  4. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_tokens_converters.py +7 -1
  5. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/caches.py +7 -1
  6. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/models.py +21 -2
  7. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/tokens.py +7 -2
  8. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/types.py +36 -5
  9. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/version.py +1 -1
  10. {google_genai-1.18.0 → google_genai-1.19.0/google_genai.egg-info}/PKG-INFO +1 -1
  11. {google_genai-1.18.0 → google_genai-1.19.0}/pyproject.toml +1 -1
  12. {google_genai-1.18.0 → google_genai-1.19.0}/LICENSE +0 -0
  13. {google_genai-1.18.0 → google_genai-1.19.0}/MANIFEST.in +0 -0
  14. {google_genai-1.18.0 → google_genai-1.19.0}/README.md +0 -0
  15. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/__init__.py +0 -0
  16. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_adapters.py +0 -0
  17. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_api_module.py +0 -0
  18. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_automatic_function_calling_util.py +0 -0
  19. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_base_url.py +0 -0
  20. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_common.py +0 -0
  21. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_extra_utils.py +0 -0
  22. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_mcp_utils.py +0 -0
  23. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_replay_api_client.py +0 -0
  24. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_test_api_client.py +0 -0
  25. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/_transformers.py +0 -0
  26. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/batches.py +0 -0
  27. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/chats.py +0 -0
  28. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/client.py +0 -0
  29. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/errors.py +0 -0
  30. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/files.py +0 -0
  31. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/live.py +0 -0
  32. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/live_music.py +0 -0
  33. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/operations.py +0 -0
  34. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/pagers.py +0 -0
  35. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/py.typed +0 -0
  36. {google_genai-1.18.0 → google_genai-1.19.0}/google/genai/tunings.py +0 -0
  37. {google_genai-1.18.0 → google_genai-1.19.0}/google_genai.egg-info/SOURCES.txt +0 -0
  38. {google_genai-1.18.0 → google_genai-1.19.0}/google_genai.egg-info/dependency_links.txt +0 -0
  39. {google_genai-1.18.0 → google_genai-1.19.0}/google_genai.egg-info/requires.txt +0 -0
  40. {google_genai-1.18.0 → google_genai-1.19.0}/google_genai.egg-info/top_level.txt +0 -0
  41. {google_genai-1.18.0 → google_genai-1.19.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.18.0
3
+ Version: 1.19.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -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 = os.environ.get('GOOGLE_API_KEY', None)
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
@@ -981,7 +981,13 @@ def _Tool_to_vertex(
981
981
  )
982
982
 
983
983
  if getv(from_object, ['url_context']) is not None:
984
- raise ValueError('url_context parameter is not supported in Vertex AI.')
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
- raise ValueError('url_context parameter is not supported in Vertex AI.')
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']))
@@ -1092,7 +1092,13 @@ def _Tool_to_vertex(
1092
1092
  )
1093
1093
 
1094
1094
  if getv(from_object, ['url_context']) is not None:
1095
- raise ValueError('url_context parameter is not supported in Vertex AI.')
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']))
@@ -1422,7 +1422,11 @@ def _GenerateVideosConfig_to_mldev(
1422
1422
  )
1423
1423
 
1424
1424
  if getv(from_object, ['enhance_prompt']) is not None:
1425
- raise ValueError('enhance_prompt parameter is not supported in Gemini API.')
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
- raise ValueError('url_context parameter is not supported in Vertex AI.')
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
 
@@ -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
- .. code-block:: python
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
- .. code-block:: python
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
@@ -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
- inspect.Parameter(
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
  )
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- __version__ = '1.18.0' # x-release-please-version
16
+ __version__ = '1.19.0' # x-release-please-version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.18.0
3
+ Version: 1.19.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -3,7 +3,7 @@ requires = ["setuptools", "wheel", "twine>=6.1.0", "packaging>=24.2", "pkginfo>=
3
3
 
4
4
  [project]
5
5
  name = "google-genai"
6
- version = "1.18.0"
6
+ version = "1.19.0"
7
7
  description = "GenAI Python SDK"
8
8
  readme = "README.md"
9
9
  license = {text = "Apache-2.0"}
File without changes
File without changes
File without changes
File without changes