google-genai 0.8.0__py3-none-any.whl → 1.0.0rc0__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/_automatic_function_calling_util.py +13 -17
- google/genai/_transformers.py +32 -14
- google/genai/files.py +3 -3
- google/genai/models.py +40 -28
- google/genai/types.py +43 -3
- google/genai/version.py +1 -1
- {google_genai-0.8.0.dist-info → google_genai-1.0.0rc0.dist-info}/METADATA +9 -45
- {google_genai-0.8.0.dist-info → google_genai-1.0.0rc0.dist-info}/RECORD +11 -11
- {google_genai-0.8.0.dist-info → google_genai-1.0.0rc0.dist-info}/LICENSE +0 -0
- {google_genai-0.8.0.dist-info → google_genai-1.0.0rc0.dist-info}/WHEEL +0 -0
- {google_genai-0.8.0.dist-info → google_genai-1.0.0rc0.dist-info}/top_level.txt +0 -0
@@ -22,9 +22,9 @@ import pydantic
|
|
22
22
|
from . import types
|
23
23
|
|
24
24
|
if sys.version_info >= (3, 10):
|
25
|
-
|
25
|
+
VersionedUnionType = builtin_types.UnionType
|
26
26
|
else:
|
27
|
-
|
27
|
+
VersionedUnionType = typing._UnionGenericAlias
|
28
28
|
|
29
29
|
_py_builtin_type_to_schema_type = {
|
30
30
|
str: 'STRING',
|
@@ -45,7 +45,8 @@ def _is_builtin_primitive_or_compound(
|
|
45
45
|
def _raise_for_any_of_if_mldev(schema: types.Schema):
|
46
46
|
if schema.any_of:
|
47
47
|
raise ValueError(
|
48
|
-
'AnyOf is not supported in function declaration schema for
|
48
|
+
'AnyOf is not supported in function declaration schema for'
|
49
|
+
' the Gemini API.'
|
49
50
|
)
|
50
51
|
|
51
52
|
|
@@ -53,15 +54,7 @@ def _raise_for_default_if_mldev(schema: types.Schema):
|
|
53
54
|
if schema.default is not None:
|
54
55
|
raise ValueError(
|
55
56
|
'Default value is not supported in function declaration schema for'
|
56
|
-
'
|
57
|
-
)
|
58
|
-
|
59
|
-
|
60
|
-
def _raise_for_nullable_if_mldev(schema: types.Schema):
|
61
|
-
if schema.nullable:
|
62
|
-
raise ValueError(
|
63
|
-
'Nullable is not supported in function declaration schema for'
|
64
|
-
' Google AI.'
|
57
|
+
' the Gemini API.'
|
65
58
|
)
|
66
59
|
|
67
60
|
|
@@ -69,7 +62,6 @@ def _raise_if_schema_unsupported(client, schema: types.Schema):
|
|
69
62
|
if not client.vertexai:
|
70
63
|
_raise_for_any_of_if_mldev(schema)
|
71
64
|
_raise_for_default_if_mldev(schema)
|
72
|
-
_raise_for_nullable_if_mldev(schema)
|
73
65
|
|
74
66
|
|
75
67
|
def _is_default_value_compatible(
|
@@ -82,10 +74,10 @@ def _is_default_value_compatible(
|
|
82
74
|
if (
|
83
75
|
isinstance(annotation, _GenericAlias)
|
84
76
|
or isinstance(annotation, builtin_types.GenericAlias)
|
85
|
-
or isinstance(annotation,
|
77
|
+
or isinstance(annotation, VersionedUnionType)
|
86
78
|
):
|
87
79
|
origin = get_origin(annotation)
|
88
|
-
if origin in (Union,
|
80
|
+
if origin in (Union, VersionedUnionType):
|
89
81
|
return any(
|
90
82
|
_is_default_value_compatible(default_value, arg)
|
91
83
|
for arg in get_args(annotation)
|
@@ -141,7 +133,7 @@ def _parse_schema_from_parameter(
|
|
141
133
|
_raise_if_schema_unsupported(client, schema)
|
142
134
|
return schema
|
143
135
|
if (
|
144
|
-
isinstance(param.annotation,
|
136
|
+
isinstance(param.annotation, VersionedUnionType)
|
145
137
|
# only parse simple UnionType, example int | str | float | bool
|
146
138
|
# complex UnionType will be invoked in raise branch
|
147
139
|
and all(
|
@@ -229,7 +221,11 @@ def _parse_schema_from_parameter(
|
|
229
221
|
schema.type = 'OBJECT'
|
230
222
|
unique_types = set()
|
231
223
|
for arg in args:
|
232
|
-
|
224
|
+
# The first check is for NoneType in Python 3.9, since the __name__
|
225
|
+
# attribute is not available in Python 3.9
|
226
|
+
if type(arg) is type(None) or (
|
227
|
+
hasattr(arg, '__name__') and arg.__name__ == 'NoneType'
|
228
|
+
): # Optional type
|
233
229
|
schema.nullable = True
|
234
230
|
continue
|
235
231
|
schema_in_any_of = _parse_schema_from_parameter(
|
google/genai/_transformers.py
CHANGED
@@ -34,10 +34,12 @@ import pydantic
|
|
34
34
|
from . import _api_client
|
35
35
|
from . import types
|
36
36
|
|
37
|
-
if sys.version_info >= (3,
|
38
|
-
|
37
|
+
if sys.version_info >= (3, 10):
|
38
|
+
VersionedUnionType = typing.types.UnionType
|
39
|
+
_UNION_TYPES = (typing.Union, typing.types.UnionType)
|
39
40
|
else:
|
40
|
-
|
41
|
+
VersionedUnionType = typing._UnionGenericAlias
|
42
|
+
_UNION_TYPES = (typing.Union,)
|
41
43
|
|
42
44
|
|
43
45
|
def _resource_name(
|
@@ -225,6 +227,7 @@ PartType = Union[types.Part, types.PartDict, str, 'PIL.Image.Image']
|
|
225
227
|
def t_part(client: _api_client.ApiClient, part: PartType) -> types.Part:
|
226
228
|
try:
|
227
229
|
import PIL.Image
|
230
|
+
|
228
231
|
PIL_Image = PIL.Image.Image
|
229
232
|
except ImportError:
|
230
233
|
PIL_Image = None
|
@@ -342,7 +345,7 @@ def handle_null_fields(schema: dict[str, Any]):
|
|
342
345
|
"type": "null"
|
343
346
|
}
|
344
347
|
],
|
345
|
-
"default":
|
348
|
+
"default": None,
|
346
349
|
"title": "Total Area Sq Mi"
|
347
350
|
}
|
348
351
|
}
|
@@ -356,16 +359,12 @@ def handle_null_fields(schema: dict[str, Any]):
|
|
356
359
|
"total_area_sq_mi": {
|
357
360
|
"type": "integer",
|
358
361
|
"nullable": true,
|
359
|
-
"default":
|
362
|
+
"default": None,
|
360
363
|
"title": "Total Area Sq Mi"
|
361
364
|
}
|
362
365
|
}
|
363
366
|
"""
|
364
|
-
if (
|
365
|
-
isinstance(schema, dict)
|
366
|
-
and 'type' in schema
|
367
|
-
and schema['type'] == 'null'
|
368
|
-
):
|
367
|
+
if schema.get('type', None) == 'null':
|
369
368
|
schema['nullable'] = True
|
370
369
|
del schema['type']
|
371
370
|
elif 'anyOf' in schema:
|
@@ -445,6 +444,11 @@ def process_schema(
|
|
445
444
|
if client and not client.vertexai:
|
446
445
|
schema.pop('title', None)
|
447
446
|
|
447
|
+
if schema.get('default') is not None:
|
448
|
+
raise ValueError(
|
449
|
+
'Default value is not supported in the response schema for the Gemmini API.'
|
450
|
+
)
|
451
|
+
|
448
452
|
if defs is None:
|
449
453
|
defs = schema.pop('$defs', {})
|
450
454
|
for _, sub_schema in defs.items():
|
@@ -454,8 +458,19 @@ def process_schema(
|
|
454
458
|
|
455
459
|
any_of = schema.get('anyOf', None)
|
456
460
|
if any_of is not None:
|
461
|
+
if not client.vertexai:
|
462
|
+
raise ValueError(
|
463
|
+
'AnyOf is not supported in the response schema for the Gemini API.'
|
464
|
+
)
|
457
465
|
for sub_schema in any_of:
|
458
|
-
|
466
|
+
# $ref is present in any_of if the schema is a union of Pydantic classes
|
467
|
+
ref_key = sub_schema.get('$ref', None)
|
468
|
+
if ref_key is None:
|
469
|
+
process_schema(sub_schema, client, defs)
|
470
|
+
else:
|
471
|
+
ref = defs[ref_key.split('defs/')[-1]]
|
472
|
+
any_of.append(ref)
|
473
|
+
schema['anyOf'] = [item for item in any_of if '$ref' not in item]
|
459
474
|
return
|
460
475
|
|
461
476
|
schema_type = schema.get('type', None)
|
@@ -526,15 +541,18 @@ def t_schema(
|
|
526
541
|
if (
|
527
542
|
# in Python 3.9 Generic alias list[int] counts as a type,
|
528
543
|
# and breaks issubclass because it's not a class.
|
529
|
-
not isinstance(origin, GenericAlias) and
|
530
|
-
isinstance(origin, type) and
|
544
|
+
not isinstance(origin, GenericAlias) and
|
545
|
+
isinstance(origin, type) and
|
531
546
|
issubclass(origin, pydantic.BaseModel)
|
532
547
|
):
|
533
548
|
schema = origin.model_json_schema()
|
534
549
|
process_schema(schema, client)
|
535
550
|
return types.Schema.model_validate(schema)
|
536
551
|
elif (
|
537
|
-
|
552
|
+
isinstance(origin, GenericAlias)
|
553
|
+
or isinstance(origin, type)
|
554
|
+
or isinstance(origin, VersionedUnionType)
|
555
|
+
or typing.get_origin(origin) in _UNION_TYPES
|
538
556
|
):
|
539
557
|
class Placeholder(pydantic.BaseModel):
|
540
558
|
placeholder: origin
|
google/genai/files.py
CHANGED
@@ -19,7 +19,7 @@ import io
|
|
19
19
|
import mimetypes
|
20
20
|
import os
|
21
21
|
import pathlib
|
22
|
-
from typing import Optional, Union
|
22
|
+
from typing import Any, Optional, Union
|
23
23
|
from urllib.parse import urlencode
|
24
24
|
from . import _api_module
|
25
25
|
from . import _common
|
@@ -351,12 +351,12 @@ def _DeleteFileParameters_to_vertex(
|
|
351
351
|
return to_object
|
352
352
|
|
353
353
|
|
354
|
-
def _FileState_to_vertex_enum_validate(enum_value:
|
354
|
+
def _FileState_to_vertex_enum_validate(enum_value: Any):
|
355
355
|
if enum_value in set(['STATE_UNSPECIFIED', 'PROCESSING', 'ACTIVE', 'FAILED']):
|
356
356
|
raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
|
357
357
|
|
358
358
|
|
359
|
-
def _FileSource_to_vertex_enum_validate(enum_value:
|
359
|
+
def _FileSource_to_vertex_enum_validate(enum_value: Any):
|
360
360
|
if enum_value in set(['SOURCE_UNSPECIFIED', 'UPLOADED', 'GENERATED']):
|
361
361
|
raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
|
362
362
|
|
google/genai/models.py
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
17
17
|
|
18
18
|
import logging
|
19
|
-
from typing import AsyncIterator, Awaitable, Iterator, Optional, Union
|
19
|
+
from typing import Any, AsyncIterator, Awaitable, Iterator, Optional, Union
|
20
20
|
from urllib.parse import urlencode
|
21
21
|
from . import _api_module
|
22
22
|
from . import _common
|
@@ -904,6 +904,9 @@ def _GenerateContentConfig_to_mldev(
|
|
904
904
|
),
|
905
905
|
)
|
906
906
|
|
907
|
+
if getv(from_object, ['labels']) is not None:
|
908
|
+
raise ValueError('labels parameter is not supported in Gemini API.')
|
909
|
+
|
907
910
|
if getv(from_object, ['cached_content']) is not None:
|
908
911
|
setv(
|
909
912
|
parent_object,
|
@@ -1066,6 +1069,9 @@ def _GenerateContentConfig_to_vertex(
|
|
1066
1069
|
),
|
1067
1070
|
)
|
1068
1071
|
|
1072
|
+
if getv(from_object, ['labels']) is not None:
|
1073
|
+
setv(parent_object, ['labels'], getv(from_object, ['labels']))
|
1074
|
+
|
1069
1075
|
if getv(from_object, ['cached_content']) is not None:
|
1070
1076
|
setv(
|
1071
1077
|
parent_object,
|
@@ -2785,7 +2791,7 @@ def _ComputeTokensParameters_to_vertex(
|
|
2785
2791
|
return to_object
|
2786
2792
|
|
2787
2793
|
|
2788
|
-
def _MediaResolution_to_mldev_enum_validate(enum_value:
|
2794
|
+
def _MediaResolution_to_mldev_enum_validate(enum_value: Any):
|
2789
2795
|
if enum_value in set([
|
2790
2796
|
'MEDIA_RESOLUTION_UNSPECIFIED',
|
2791
2797
|
'MEDIA_RESOLUTION_LOW',
|
@@ -2795,17 +2801,17 @@ def _MediaResolution_to_mldev_enum_validate(enum_value: any):
|
|
2795
2801
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2796
2802
|
|
2797
2803
|
|
2798
|
-
def _SafetyFilterLevel_to_mldev_enum_validate(enum_value:
|
2804
|
+
def _SafetyFilterLevel_to_mldev_enum_validate(enum_value: Any):
|
2799
2805
|
if enum_value in set(['BLOCK_NONE']):
|
2800
2806
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2801
2807
|
|
2802
2808
|
|
2803
|
-
def _PersonGeneration_to_mldev_enum_validate(enum_value:
|
2809
|
+
def _PersonGeneration_to_mldev_enum_validate(enum_value: Any):
|
2804
2810
|
if enum_value in set(['ALLOW_ALL']):
|
2805
2811
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2806
2812
|
|
2807
2813
|
|
2808
|
-
def _MaskReferenceMode_to_mldev_enum_validate(enum_value:
|
2814
|
+
def _MaskReferenceMode_to_mldev_enum_validate(enum_value: Any):
|
2809
2815
|
if enum_value in set([
|
2810
2816
|
'MASK_MODE_DEFAULT',
|
2811
2817
|
'MASK_MODE_USER_PROVIDED',
|
@@ -2816,7 +2822,7 @@ def _MaskReferenceMode_to_mldev_enum_validate(enum_value: any):
|
|
2816
2822
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2817
2823
|
|
2818
2824
|
|
2819
|
-
def _ControlReferenceType_to_mldev_enum_validate(enum_value:
|
2825
|
+
def _ControlReferenceType_to_mldev_enum_validate(enum_value: Any):
|
2820
2826
|
if enum_value in set([
|
2821
2827
|
'CONTROL_TYPE_DEFAULT',
|
2822
2828
|
'CONTROL_TYPE_CANNY',
|
@@ -2826,7 +2832,7 @@ def _ControlReferenceType_to_mldev_enum_validate(enum_value: any):
|
|
2826
2832
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2827
2833
|
|
2828
2834
|
|
2829
|
-
def _SubjectReferenceType_to_mldev_enum_validate(enum_value:
|
2835
|
+
def _SubjectReferenceType_to_mldev_enum_validate(enum_value: Any):
|
2830
2836
|
if enum_value in set([
|
2831
2837
|
'SUBJECT_TYPE_DEFAULT',
|
2832
2838
|
'SUBJECT_TYPE_PERSON',
|
@@ -2836,7 +2842,7 @@ def _SubjectReferenceType_to_mldev_enum_validate(enum_value: any):
|
|
2836
2842
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2837
2843
|
|
2838
2844
|
|
2839
|
-
def _EditMode_to_mldev_enum_validate(enum_value:
|
2845
|
+
def _EditMode_to_mldev_enum_validate(enum_value: Any):
|
2840
2846
|
if enum_value in set([
|
2841
2847
|
'EDIT_MODE_DEFAULT',
|
2842
2848
|
'EDIT_MODE_INPAINT_REMOVAL',
|
@@ -4696,15 +4702,18 @@ class Models(_api_module.BaseModule):
|
|
4696
4702
|
)
|
4697
4703
|
if not func_response_parts:
|
4698
4704
|
break
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
role='user',
|
4704
|
-
parts=func_response_parts,
|
4705
|
-
)
|
4705
|
+
func_call_content = response.candidates[0].content
|
4706
|
+
func_response_content = types.Content(
|
4707
|
+
role='user',
|
4708
|
+
parts=func_response_parts,
|
4706
4709
|
)
|
4707
|
-
|
4710
|
+
contents = t.t_contents(self._api_client, contents)
|
4711
|
+
if not automatic_function_calling_history:
|
4712
|
+
automatic_function_calling_history.extend(contents)
|
4713
|
+
contents.append(func_call_content)
|
4714
|
+
contents.append(func_response_content)
|
4715
|
+
automatic_function_calling_history.append(func_call_content)
|
4716
|
+
automatic_function_calling_history.append(func_response_content)
|
4708
4717
|
if _extra_utils.should_append_afc_history(config):
|
4709
4718
|
response.automatic_function_calling_history = (
|
4710
4719
|
automatic_function_calling_history
|
@@ -4774,8 +4783,8 @@ class Models(_api_module.BaseModule):
|
|
4774
4783
|
) -> Pager[types.Model]:
|
4775
4784
|
"""Makes an API request to list the available models.
|
4776
4785
|
|
4777
|
-
If `query_base` is set to True in the config
|
4778
|
-
available base models. If set to False
|
4786
|
+
If `query_base` is set to True in the config or not set (default), the
|
4787
|
+
API will return all available base models. If set to False, it will return
|
4779
4788
|
all tuned models.
|
4780
4789
|
|
4781
4790
|
Args:
|
@@ -4798,6 +4807,8 @@ class Models(_api_module.BaseModule):
|
|
4798
4807
|
types._ListModelsParameters(config=config).config
|
4799
4808
|
or types.ListModelsConfig()
|
4800
4809
|
)
|
4810
|
+
if config.query_base is None:
|
4811
|
+
config.query_base = True
|
4801
4812
|
if self._api_client.vertexai:
|
4802
4813
|
config = config.copy()
|
4803
4814
|
if not config.query_base:
|
@@ -4808,8 +4819,6 @@ class Models(_api_module.BaseModule):
|
|
4808
4819
|
if filter_value
|
4809
4820
|
else 'labels.tune-type:*'
|
4810
4821
|
)
|
4811
|
-
if not config.query_base:
|
4812
|
-
config.query_base = False
|
4813
4822
|
return Pager(
|
4814
4823
|
'models',
|
4815
4824
|
self._list,
|
@@ -5694,15 +5703,18 @@ class AsyncModels(_api_module.BaseModule):
|
|
5694
5703
|
)
|
5695
5704
|
if not func_response_parts:
|
5696
5705
|
break
|
5697
|
-
|
5698
|
-
|
5699
|
-
|
5700
|
-
|
5701
|
-
role='user',
|
5702
|
-
parts=func_response_parts,
|
5703
|
-
)
|
5706
|
+
func_call_content = response.candidates[0].content
|
5707
|
+
func_response_content = types.Content(
|
5708
|
+
role='user',
|
5709
|
+
parts=func_response_parts,
|
5704
5710
|
)
|
5705
|
-
|
5711
|
+
contents = t.t_contents(self._api_client, contents)
|
5712
|
+
if not automatic_function_calling_history:
|
5713
|
+
automatic_function_calling_history.extend(contents)
|
5714
|
+
contents.append(func_call_content)
|
5715
|
+
contents.append(func_response_content)
|
5716
|
+
automatic_function_calling_history.append(func_call_content)
|
5717
|
+
automatic_function_calling_history.append(func_response_content)
|
5706
5718
|
|
5707
5719
|
if _extra_utils.should_append_afc_history(config):
|
5708
5720
|
response.automatic_function_calling_history = (
|
google/genai/types.py
CHANGED
@@ -20,12 +20,22 @@ from enum import Enum, EnumMeta
|
|
20
20
|
import inspect
|
21
21
|
import json
|
22
22
|
import logging
|
23
|
+
import sys
|
23
24
|
import typing
|
24
25
|
from typing import Any, Callable, GenericAlias, Literal, Optional, Type, TypedDict, Union
|
25
26
|
import pydantic
|
26
27
|
from pydantic import Field
|
27
28
|
from . import _common
|
28
29
|
|
30
|
+
if sys.version_info >= (3, 10):
|
31
|
+
# Supports both Union[t1, t2] and t1 | t2
|
32
|
+
VersionedUnionType = Union[typing.types.UnionType, typing._UnionGenericAlias]
|
33
|
+
_UNION_TYPES = (typing.Union, typing.types.UnionType)
|
34
|
+
else:
|
35
|
+
# Supports only Union[t1, t2]
|
36
|
+
VersionedUnionType = typing._UnionGenericAlias
|
37
|
+
_UNION_TYPES = (typing.Union,)
|
38
|
+
|
29
39
|
_is_pillow_image_imported = False
|
30
40
|
if typing.TYPE_CHECKING:
|
31
41
|
import PIL.Image
|
@@ -713,7 +723,7 @@ class HttpOptions(_common.BaseModel):
|
|
713
723
|
timeout: Optional[int] = Field(
|
714
724
|
default=None, description="""Timeout for the request in milliseconds."""
|
715
725
|
)
|
716
|
-
deprecated_response_payload: Optional[dict[str,
|
726
|
+
deprecated_response_payload: Optional[dict[str, Any]] = Field(
|
717
727
|
default=None,
|
718
728
|
description="""This field is deprecated. If set, the response payload will be returned int the supplied dict.""",
|
719
729
|
)
|
@@ -734,7 +744,7 @@ class HttpOptionsDict(TypedDict, total=False):
|
|
734
744
|
timeout: Optional[int]
|
735
745
|
"""Timeout for the request in milliseconds."""
|
736
746
|
|
737
|
-
deprecated_response_payload: Optional[dict[str,
|
747
|
+
deprecated_response_payload: Optional[dict[str, Any]]
|
738
748
|
"""This field is deprecated. If set, the response payload will be returned int the supplied dict."""
|
739
749
|
|
740
750
|
|
@@ -1656,7 +1666,7 @@ ContentUnion = Union[Content, list[PartUnion], PartUnion]
|
|
1656
1666
|
ContentUnionDict = Union[ContentUnion, ContentDict]
|
1657
1667
|
|
1658
1668
|
|
1659
|
-
SchemaUnion = Union[dict, type, Schema, GenericAlias]
|
1669
|
+
SchemaUnion = Union[dict, type, Schema, GenericAlias, VersionedUnionType]
|
1660
1670
|
|
1661
1671
|
|
1662
1672
|
SchemaUnionDict = Union[SchemaUnion, SchemaDict]
|
@@ -1863,6 +1873,10 @@ class GenerateContentConfig(_common.BaseModel):
|
|
1863
1873
|
description="""Associates model output to a specific function call.
|
1864
1874
|
""",
|
1865
1875
|
)
|
1876
|
+
labels: Optional[dict[str, str]] = Field(
|
1877
|
+
default=None,
|
1878
|
+
description="""Labels with user-defined metadata to break down billed charges.""",
|
1879
|
+
)
|
1866
1880
|
cached_content: Optional[str] = Field(
|
1867
1881
|
default=None,
|
1868
1882
|
description="""Resource name of a context cache that can be used in subsequent
|
@@ -2007,6 +2021,9 @@ class GenerateContentConfigDict(TypedDict, total=False):
|
|
2007
2021
|
"""Associates model output to a specific function call.
|
2008
2022
|
"""
|
2009
2023
|
|
2024
|
+
labels: Optional[dict[str, str]]
|
2025
|
+
"""Labels with user-defined metadata to break down billed charges."""
|
2026
|
+
|
2010
2027
|
cached_content: Optional[str]
|
2011
2028
|
"""Resource name of a context cache that can be used in subsequent
|
2012
2029
|
requests.
|
@@ -2902,6 +2919,29 @@ class GenerateContentResponse(_common.BaseModel):
|
|
2902
2919
|
# may not be a valid json per stream response
|
2903
2920
|
except json.decoder.JSONDecodeError:
|
2904
2921
|
pass
|
2922
|
+
elif typing.get_origin(response_schema) in _UNION_TYPES:
|
2923
|
+
# Union schema.
|
2924
|
+
union_types = typing.get_args(response_schema)
|
2925
|
+
for union_type in union_types:
|
2926
|
+
if issubclass(union_type, pydantic.BaseModel):
|
2927
|
+
try:
|
2928
|
+
|
2929
|
+
class Placeholder(pydantic.BaseModel):
|
2930
|
+
placeholder: response_schema
|
2931
|
+
|
2932
|
+
parsed = {'placeholder': json.loads(result.text)}
|
2933
|
+
placeholder = Placeholder.model_validate(parsed)
|
2934
|
+
result.parsed = placeholder.placeholder
|
2935
|
+
except json.decoder.JSONDecodeError:
|
2936
|
+
pass
|
2937
|
+
except pydantic.ValidationError:
|
2938
|
+
pass
|
2939
|
+
else:
|
2940
|
+
try:
|
2941
|
+
result.parsed = json.loads(result.text)
|
2942
|
+
# may not be a valid json per stream response
|
2943
|
+
except json.decoder.JSONDecodeError:
|
2944
|
+
pass
|
2905
2945
|
|
2906
2946
|
return result
|
2907
2947
|
|
google/genai/version.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: google-genai
|
3
|
-
Version: 0.
|
3
|
+
Version: 1.0.0rc0
|
4
4
|
Summary: GenAI Python SDK
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
6
6
|
License: Apache-2.0
|
@@ -144,53 +144,17 @@ response = client.models.generate_content(
|
|
144
144
|
print(response.text)
|
145
145
|
```
|
146
146
|
|
147
|
-
### Thinking
|
148
|
-
|
149
|
-
The Gemini 2.0 Flash Thinking model is an experimental model that could return
|
150
|
-
"thoughts" as part of its response.
|
151
|
-
|
152
|
-
#### Gemini Developer API
|
153
|
-
|
154
|
-
Thinking config is only available in v1alpha for Gemini AI API.
|
155
|
-
|
156
|
-
```python
|
157
|
-
response = client.models.generate_content(
|
158
|
-
model='gemini-2.0-flash-thinking-exp',
|
159
|
-
contents='What is the sum of natural numbers from 1 to 100?',
|
160
|
-
config=types.GenerateContentConfig(
|
161
|
-
thinking_config=types.ThinkingConfig(include_thoughts=True),
|
162
|
-
http_options=types.HttpOptions(api_version='v1alpha'),
|
163
|
-
)
|
164
|
-
)
|
165
|
-
for part in response.candidates[0].content.parts:
|
166
|
-
print(part)
|
167
|
-
```
|
168
|
-
|
169
|
-
#### Vertex AI API
|
170
|
-
|
171
|
-
```python
|
172
|
-
response = client.models.generate_content(
|
173
|
-
model='gemini-2.0-flash-thinking-exp-01-21',
|
174
|
-
contents='What is the sum of natural numbers from 1 to 100?',
|
175
|
-
config=types.GenerateContentConfig(
|
176
|
-
thinking_config=types.ThinkingConfig(include_thoughts=True),
|
177
|
-
)
|
178
|
-
)
|
179
|
-
for part in response.candidates[0].content.parts:
|
180
|
-
print(part)
|
181
|
-
```
|
182
|
-
|
183
147
|
### List Base Models
|
184
148
|
|
185
149
|
To retrieve tuned models, see [list tuned models](#list-tuned-models).
|
186
150
|
|
187
151
|
```python
|
188
|
-
for model in client.models.list(
|
152
|
+
for model in client.models.list():
|
189
153
|
print(model)
|
190
154
|
```
|
191
155
|
|
192
156
|
```python
|
193
|
-
pager = client.models.list(config={"page_size": 10
|
157
|
+
pager = client.models.list(config={"page_size": 10})
|
194
158
|
print(pager.page_size)
|
195
159
|
print(pager[0])
|
196
160
|
pager.next_page()
|
@@ -200,12 +164,12 @@ print(pager[0])
|
|
200
164
|
#### Async
|
201
165
|
|
202
166
|
```python
|
203
|
-
async for job in await client.aio.models.list(
|
167
|
+
async for job in await client.aio.models.list():
|
204
168
|
print(job)
|
205
169
|
```
|
206
170
|
|
207
171
|
```python
|
208
|
-
async_pager = await client.aio.models.list(config={"page_size": 10
|
172
|
+
async_pager = await client.aio.models.list(config={"page_size": 10})
|
209
173
|
print(async_pager.page_size)
|
210
174
|
print(async_pager[0])
|
211
175
|
await async_pager.next_page()
|
@@ -864,12 +828,12 @@ print(tuned_model)
|
|
864
828
|
To retrieve base models, see [list base models](#list-base-models).
|
865
829
|
|
866
830
|
```python
|
867
|
-
for model in client.models.list(config={"page_size": 10}):
|
831
|
+
for model in client.models.list(config={"page_size": 10, "query_base": False}):
|
868
832
|
print(model)
|
869
833
|
```
|
870
834
|
|
871
835
|
```python
|
872
|
-
pager = client.models.list(config={"page_size": 10})
|
836
|
+
pager = client.models.list(config={"page_size": 10, "query_base": False})
|
873
837
|
print(pager.page_size)
|
874
838
|
print(pager[0])
|
875
839
|
pager.next_page()
|
@@ -879,12 +843,12 @@ print(pager[0])
|
|
879
843
|
#### Async
|
880
844
|
|
881
845
|
```python
|
882
|
-
async for job in await client.aio.models.list(config={"page_size": 10}):
|
846
|
+
async for job in await client.aio.models.list(config={"page_size": 10, "query_base": False}):
|
883
847
|
print(job)
|
884
848
|
```
|
885
849
|
|
886
850
|
```python
|
887
|
-
async_pager = await client.aio.models.list(config={"page_size": 10})
|
851
|
+
async_pager = await client.aio.models.list(config={"page_size": 10, "query_base": False})
|
888
852
|
print(async_pager.page_size)
|
889
853
|
print(async_pager[0])
|
890
854
|
await async_pager.next_page()
|
@@ -1,27 +1,27 @@
|
|
1
1
|
google/genai/__init__.py,sha256=IYw-PcsdgjSpS1mU_ZcYkTfPocsJ4aVmrDxP7vX7c6Y,709
|
2
2
|
google/genai/_api_client.py,sha256=ZXiLrTI0wWVZaGEC1BHU9fLVp1MZKpnY8J3wV59VOk4,22806
|
3
3
|
google/genai/_api_module.py,sha256=9bxmtcSTpT8Ht6VwJyw7fQqiR0jJXz7350dWGl-bC5E,780
|
4
|
-
google/genai/_automatic_function_calling_util.py,sha256=
|
4
|
+
google/genai/_automatic_function_calling_util.py,sha256=8KUbDvuon0Pw9HbYGMjavsmZtAf1elKaxkPEPgw27Wk,10696
|
5
5
|
google/genai/_common.py,sha256=Q-3n5U7GCDDfOU_7uBkGYkEcEH2VcMa_NuLcyNzWExM,9017
|
6
6
|
google/genai/_extra_utils.py,sha256=y-6Jr2GN2BKZV67I6fTgDtwfsOTQs7QlLDBQdmW_jKk,11258
|
7
7
|
google/genai/_operations.py,sha256=KaDgwqG5g6Odd1P6ftvIUT9gF3ov08drm01jE1CjB_s,11490
|
8
8
|
google/genai/_replay_api_client.py,sha256=yV2vJJk5Nvdqyi0QmNhupMdm2jrzdYoHVFnVMAx-l0M,14834
|
9
9
|
google/genai/_test_api_client.py,sha256=2PvDcW3h01U4UOSoj7TUo6TwdBHSEN_lO2tXjBoh5Fw,4765
|
10
|
-
google/genai/_transformers.py,sha256=
|
10
|
+
google/genai/_transformers.py,sha256=Jwgbwl7DufqRZGeoPc1GClRQj1X6WM4avZEFfq9WGwA,22690
|
11
11
|
google/genai/batches.py,sha256=jv8pW_g_cZee6ol5ER5bQRUkXsj4IUcZC5cMo-YAnt0,38033
|
12
12
|
google/genai/caches.py,sha256=jsiclHO71kIa2CNrds3O8PL2fCNr_dlhUSPjhiRsjNE,53152
|
13
13
|
google/genai/chats.py,sha256=GyufXQPtyP_v4L3943xaKXMpo1Us9sBTdMSTUV4P6s8,7827
|
14
14
|
google/genai/client.py,sha256=MTZ3DOXk1_xgljaHlvF16jr_SKVPRfU8lZ1eH_dfDeQ,9334
|
15
15
|
google/genai/errors.py,sha256=DtpDZT5UDqumk2cTRUlg3k4ypmO_0tkMNzJgA3qzCmc,3666
|
16
|
-
google/genai/files.py,sha256=
|
16
|
+
google/genai/files.py,sha256=v16OR0IwHVB-BDWsUDYBill0BvOLEd-7eEZBJ-VcY8o,41890
|
17
17
|
google/genai/live.py,sha256=wxz8ebqcPR6JJs39OOVz8zPzfAf31Zol7sGE7byQEyI,23302
|
18
|
-
google/genai/models.py,sha256=
|
18
|
+
google/genai/models.py,sha256=2w8-NAMeJXOrY23kyEi1zyATC1sLpkSlI2Gd0m90Vdk,167626
|
19
19
|
google/genai/pagers.py,sha256=hSHd-gLvEzYWwK85i8EcFNWUMKtszUs7Nw2r3L7d6_U,6686
|
20
20
|
google/genai/tunings.py,sha256=iJJYn1O_wjFKTIL8VS2zpIRqpfCNRrO2REP2ztgFW6M,39144
|
21
|
-
google/genai/types.py,sha256=
|
22
|
-
google/genai/version.py,sha256=
|
23
|
-
google_genai-0.
|
24
|
-
google_genai-0.
|
25
|
-
google_genai-0.
|
26
|
-
google_genai-0.
|
27
|
-
google_genai-0.
|
21
|
+
google/genai/types.py,sha256=J_hZuu2zPPuerqcACNb3pJgQST8Fa2Y4WB-WxYskDa4,279945
|
22
|
+
google/genai/version.py,sha256=Y91_Rt-BIVIiB5ejxu9eKlaoOpM6RxHAVtl2_HhX-Ss,629
|
23
|
+
google_genai-1.0.0rc0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
24
|
+
google_genai-1.0.0rc0.dist-info/METADATA,sha256=MFyH61qAsTbMTgxOdkZIkSR_YMf5EsGvAPy4Zpk-_C8,22948
|
25
|
+
google_genai-1.0.0rc0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
26
|
+
google_genai-1.0.0rc0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
27
|
+
google_genai-1.0.0rc0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|