google-genai 1.1.0__py3-none-any.whl → 1.3.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 +152 -48
- google/genai/_api_module.py +5 -0
- google/genai/_common.py +12 -0
- google/genai/_extra_utils.py +7 -2
- google/genai/_replay_api_client.py +32 -1
- google/genai/_transformers.py +40 -10
- google/genai/batches.py +6 -3
- google/genai/caches.py +13 -10
- google/genai/client.py +22 -11
- google/genai/errors.py +18 -3
- google/genai/files.py +8 -5
- google/genai/live.py +64 -41
- google/genai/models.py +661 -87
- google/genai/{_operations.py → operations.py} +260 -20
- google/genai/tunings.py +3 -0
- google/genai/types.py +439 -7
- google/genai/version.py +1 -1
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/METADATA +126 -15
- google_genai-1.3.0.dist-info/RECORD +27 -0
- google_genai-1.1.0.dist-info/RECORD +0 -27
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/LICENSE +0 -0
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/WHEEL +0 -0
- {google_genai-1.1.0.dist-info → google_genai-1.3.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: google-genai
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.3.0
|
4
4
|
Summary: GenAI Python SDK
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
6
6
|
License: Apache-2.0
|
@@ -21,9 +21,11 @@ Requires-Python: >=3.9
|
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
License-File: LICENSE
|
23
23
|
Requires-Dist: google-auth<3.0.0dev,>=2.14.1
|
24
|
+
Requires-Dist: httpx<1.0.0dev,>=0.28.1
|
24
25
|
Requires-Dist: pydantic<3.0.0dev,>=2.0.0
|
25
26
|
Requires-Dist: requests<3.0.0dev,>=2.28.1
|
26
27
|
Requires-Dist: websockets<15.0dev,>=13.0
|
28
|
+
Requires-Dist: typing-extensions<5.0.0dev,>=4.11.0
|
27
29
|
|
28
30
|
# Google Gen AI SDK
|
29
31
|
|
@@ -66,21 +68,56 @@ client = genai.Client(
|
|
66
68
|
)
|
67
69
|
```
|
68
70
|
|
71
|
+
**(Optional) Using environment variables:**
|
72
|
+
|
73
|
+
You can create a client by configuring the necessary environment variables.
|
74
|
+
Configuration setup instructions depends on whether you're using the Gemini API
|
75
|
+
on Vertex AI or the ML Dev Gemini API.
|
76
|
+
|
77
|
+
**ML Dev Gemini API:** Set `GOOGLE_API_KEY` as shown below:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
export GOOGLE_API_KEY='your-api-key'
|
81
|
+
```
|
82
|
+
|
83
|
+
**Vertex AI API:** Set `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_CLOUD_PROJECT`
|
84
|
+
and `GOOGLE_CLOUD_LOCATION`, as shown below:
|
85
|
+
|
86
|
+
```bash
|
87
|
+
export GOOGLE_GENAI_USE_VERTEXAI=true
|
88
|
+
export GOOGLE_CLOUD_PROJECT='your-project-id'
|
89
|
+
export GOOGLE_CLOUD_LOCATION='us-central1'
|
90
|
+
```
|
91
|
+
|
92
|
+
```python
|
93
|
+
client = genai.Client()
|
94
|
+
```
|
95
|
+
|
96
|
+
### API Selection
|
97
|
+
|
98
|
+
By default, the SDK uses the beta API endpoints provided by Google to support
|
99
|
+
preview features in the APIs. The stable API endpoints can be selected by
|
100
|
+
setting the API version to `v1`.
|
101
|
+
|
69
102
|
To set the API version use `http_options`. For example, to set the API version
|
70
103
|
to `v1` for Vertex AI:
|
71
104
|
|
72
105
|
```python
|
73
106
|
client = genai.Client(
|
74
|
-
vertexai=True,
|
75
|
-
|
107
|
+
vertexai=True,
|
108
|
+
project='your-project-id',
|
109
|
+
location='us-central1',
|
110
|
+
http_options=types.HttpOptions(api_version='v1')
|
76
111
|
)
|
77
112
|
```
|
78
113
|
|
79
|
-
To set the API version to `v1alpha` for the Gemini API:
|
114
|
+
To set the API version to `v1alpha` for the Gemini Developer API:
|
80
115
|
|
81
116
|
```python
|
82
|
-
client = genai.Client(
|
83
|
-
|
117
|
+
client = genai.Client(
|
118
|
+
api_key='GEMINI_API_KEY',
|
119
|
+
http_options=types.HttpOptions(api_version='v1alpha')
|
120
|
+
)
|
84
121
|
```
|
85
122
|
|
86
123
|
## Types
|
@@ -99,7 +136,7 @@ The `client.models` modules exposes model inferencing and model getters.
|
|
99
136
|
|
100
137
|
```python
|
101
138
|
response = client.models.generate_content(
|
102
|
-
model='gemini-2.0-flash-001', contents='
|
139
|
+
model='gemini-2.0-flash-001', contents='Why is the sky blue?'
|
103
140
|
)
|
104
141
|
print(response.text)
|
105
142
|
```
|
@@ -107,14 +144,14 @@ print(response.text)
|
|
107
144
|
#### with uploaded file (Gemini API only)
|
108
145
|
download the file in console.
|
109
146
|
|
110
|
-
```
|
147
|
+
```sh
|
111
148
|
!wget -q https://storage.googleapis.com/generativeai-downloads/data/a11.txt
|
112
149
|
```
|
113
150
|
|
114
151
|
python code.
|
115
152
|
|
116
153
|
```python
|
117
|
-
file = client.files.upload(
|
154
|
+
file = client.files.upload(file='a11.txt')
|
118
155
|
response = client.models.generate_content(
|
119
156
|
model='gemini-2.0-flash-001',
|
120
157
|
contents=['Could you summarize this file?', file]
|
@@ -247,7 +284,7 @@ print(response.text)
|
|
247
284
|
#### Automatic Python function Support
|
248
285
|
|
249
286
|
You can pass a Python function directly and it will be automatically
|
250
|
-
called and responded.
|
287
|
+
called and responded by default.
|
251
288
|
|
252
289
|
```python
|
253
290
|
def get_current_weather(location: str) -> str:
|
@@ -267,6 +304,30 @@ response = client.models.generate_content(
|
|
267
304
|
|
268
305
|
print(response.text)
|
269
306
|
```
|
307
|
+
#### Disabling automatic function calling
|
308
|
+
If you pass in a python function as a tool directly, and do not want
|
309
|
+
automatic function calling, you can disable automatic function calling
|
310
|
+
as follows:
|
311
|
+
|
312
|
+
```python
|
313
|
+
response = client.models.generate_content(
|
314
|
+
model='gemini-2.0-flash-001',
|
315
|
+
contents='What is the weather like in Boston?',
|
316
|
+
config=types.GenerateContentConfig(
|
317
|
+
tools=[get_current_weather],
|
318
|
+
automatic_function_calling=types.AutomaticFunctionCallingConfig(
|
319
|
+
disable=True
|
320
|
+
),
|
321
|
+
),
|
322
|
+
)
|
323
|
+
```
|
324
|
+
|
325
|
+
With automatic function calling disabled, you will get a list of function call
|
326
|
+
parts in the response:
|
327
|
+
|
328
|
+
```python
|
329
|
+
function_calls: Optional[List[types.FunctionCall]] = response.function_calls
|
330
|
+
```
|
270
331
|
|
271
332
|
#### Manually declare and invoke a function for function calling
|
272
333
|
|
@@ -664,7 +725,6 @@ response1 = client.models.generate_images(
|
|
664
725
|
model='imagen-3.0-generate-002',
|
665
726
|
prompt='An umbrella in the foreground, and a rainy night sky in the background',
|
666
727
|
config=types.GenerateImagesConfig(
|
667
|
-
negative_prompt='human',
|
668
728
|
number_of_images=1,
|
669
729
|
include_rai_reason=True,
|
670
730
|
output_mime_type='image/jpeg',
|
@@ -722,7 +782,6 @@ response3 = client.models.edit_image(
|
|
722
782
|
config=types.EditImageConfig(
|
723
783
|
edit_mode='EDIT_MODE_INPAINT_INSERTION',
|
724
784
|
number_of_images=1,
|
725
|
-
negative_prompt='human',
|
726
785
|
include_rai_reason=True,
|
727
786
|
output_mime_type='image/jpeg',
|
728
787
|
),
|
@@ -730,6 +789,34 @@ response3 = client.models.edit_image(
|
|
730
789
|
response3.generated_images[0].image.show()
|
731
790
|
```
|
732
791
|
|
792
|
+
### Veo
|
793
|
+
|
794
|
+
#### Generate Videos
|
795
|
+
|
796
|
+
Support for generate videos in Vertex and Gemini Developer API is behind an allowlist
|
797
|
+
|
798
|
+
```python
|
799
|
+
# Create operation
|
800
|
+
operation = client.models.generate_videos(
|
801
|
+
model='veo-2.0-generate-001',
|
802
|
+
prompt='A neon hologram of a cat driving at top speed',
|
803
|
+
config=types.GenerateVideosConfig(
|
804
|
+
number_of_videos=1,
|
805
|
+
fps=24,
|
806
|
+
duration_seconds=5,
|
807
|
+
enhance_prompt=True,
|
808
|
+
),
|
809
|
+
)
|
810
|
+
|
811
|
+
# Poll operation
|
812
|
+
while not operation.done:
|
813
|
+
time.sleep(20)
|
814
|
+
operation = client.operations.get(operation)
|
815
|
+
|
816
|
+
video = operation.result.generated_videos[0].video
|
817
|
+
video.show()
|
818
|
+
```
|
819
|
+
|
733
820
|
## Chats
|
734
821
|
|
735
822
|
Create a chat session to start a multi-turn conversations with the model.
|
@@ -778,17 +865,24 @@ Files are only supported in Gemini Developer API.
|
|
778
865
|
### Upload
|
779
866
|
|
780
867
|
```python
|
781
|
-
file1 = client.files.upload(
|
782
|
-
file2 = client.files.upload(
|
868
|
+
file1 = client.files.upload(file='2312.11805v3.pdf')
|
869
|
+
file2 = client.files.upload(file='2403.05530.pdf')
|
783
870
|
|
784
871
|
print(file1)
|
785
872
|
print(file2)
|
786
873
|
```
|
787
874
|
|
875
|
+
### Get
|
876
|
+
|
877
|
+
```python
|
878
|
+
file1 = client.files.upload(file='2312.11805v3.pdf')
|
879
|
+
file_info = client.files.get(name=file1.name)
|
880
|
+
```
|
881
|
+
|
788
882
|
### Delete
|
789
883
|
|
790
884
|
```python
|
791
|
-
file3 = client.files.upload(
|
885
|
+
file3 = client.files.upload(file='2312.11805v3.pdf')
|
792
886
|
|
793
887
|
client.files.delete(name=file3.name)
|
794
888
|
```
|
@@ -1093,3 +1187,20 @@ delete_job = client.batches.delete(name=job.name)
|
|
1093
1187
|
|
1094
1188
|
delete_job
|
1095
1189
|
```
|
1190
|
+
|
1191
|
+
## Error Handling
|
1192
|
+
|
1193
|
+
To handle errors raised by the model service, the SDK provides this [APIError](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.
|
1194
|
+
|
1195
|
+
```python
|
1196
|
+
from google.genai import errors
|
1197
|
+
|
1198
|
+
try:
|
1199
|
+
client.models.generate_content(
|
1200
|
+
model="invalid-model-name",
|
1201
|
+
contents="What is your name?",
|
1202
|
+
)
|
1203
|
+
except errors.APIError as e:
|
1204
|
+
print(e.code) # 404
|
1205
|
+
print(e.message)
|
1206
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
google/genai/__init__.py,sha256=IYw-PcsdgjSpS1mU_ZcYkTfPocsJ4aVmrDxP7vX7c6Y,709
|
2
|
+
google/genai/_api_client.py,sha256=Y8Mv9QYdHnvzCy4DsPB6aQNKCfOIuwJ67gaew3zS2BA,26759
|
3
|
+
google/genai/_api_module.py,sha256=ySPNIb2OC2vhDpU7VOYvP2-Av3ZlmwgEpIaqF4fIWWc,898
|
4
|
+
google/genai/_automatic_function_calling_util.py,sha256=Hs7vvLRCRxL-YbNRnwx_qulY9sspwE6xP7A3-cjoIB8,10834
|
5
|
+
google/genai/_common.py,sha256=GUaoMzkTPw7oS18gkDArOTPb5EKwt8JpND5-THIZ_-I,9961
|
6
|
+
google/genai/_extra_utils.py,sha256=Ia3jUDwKLhgVXawBBA3l5Y0R12c4oWr69D0b6tfLTww,11729
|
7
|
+
google/genai/_replay_api_client.py,sha256=pbpeeWL4hHAE_8S0YbrCfgGeQxCioBFhcUDTJtH4rjs,16152
|
8
|
+
google/genai/_test_api_client.py,sha256=2PvDcW3h01U4UOSoj7TUo6TwdBHSEN_lO2tXjBoh5Fw,4765
|
9
|
+
google/genai/_transformers.py,sha256=jBmQS1_KPndBR1mc41t3vKUKCM42duvnniQjLAKGVfQ,24612
|
10
|
+
google/genai/batches.py,sha256=_ktwVQvHHUz7JkyXSUXpW_isyBIK_8BQkPD4OUjdJzg,38130
|
11
|
+
google/genai/caches.py,sha256=IiNVYtCyadYBYIGV3aszdrw_HB0sOH5ps1bnEfnc7n0,53167
|
12
|
+
google/genai/chats.py,sha256=6gKf81vtLqUAR2TeaI0kZfxrEPEHbfwxHB5hI9zSz9A,8552
|
13
|
+
google/genai/client.py,sha256=vPVU_Edh1IMFoq9pVpq4bZOVo71FaKzSVpdUn2y4HPM,9773
|
14
|
+
google/genai/errors.py,sha256=gALDvxSVHX163dtH_Uf0zsWcHy-p4U4zf7CTRigXjLE,4205
|
15
|
+
google/genai/files.py,sha256=VfB02YaVAl5MWxqD5Zg5PYXtv4_VtfNMjxk5HbcCaI8,42169
|
16
|
+
google/genai/live.py,sha256=DGNbhkOx5Dj_6uIOc1UsgRodv3NX3ztYbfS6VUjXJgc,24276
|
17
|
+
google/genai/models.py,sha256=b2iymH-aaldS72xbbQiUFUWkpATCrVSh0Kxs6S1ngiw,194655
|
18
|
+
google/genai/operations.py,sha256=C96700qYD9hlTahjlP0VPEcTsio-sXtfB7ml16G-IZQ,17954
|
19
|
+
google/genai/pagers.py,sha256=hSHd-gLvEzYWwK85i8EcFNWUMKtszUs7Nw2r3L7d6_U,6686
|
20
|
+
google/genai/tunings.py,sha256=5qtJO3atPxhHyReYoU3yavQ3cEoc5h7mZpSzxsE1Jmg,44745
|
21
|
+
google/genai/types.py,sha256=qGZQ_IBCNKUPK_Ft5A4qbG1V3xbhisOQNvv2EZ8s4Lg,295881
|
22
|
+
google/genai/version.py,sha256=6XlttB_dEVuHt3Ks7rw29lt6WqnD9MqEtyZ3jfjI3XQ,626
|
23
|
+
google_genai-1.3.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
24
|
+
google_genai-1.3.0.dist-info/METADATA,sha256=TBFoFOTwCodhcG4v7sWYbSccYfh2UXZdyC5A2iS7rK8,28874
|
25
|
+
google_genai-1.3.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
26
|
+
google_genai-1.3.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
27
|
+
google_genai-1.3.0.dist-info/RECORD,,
|
@@ -1,27 +0,0 @@
|
|
1
|
-
google/genai/__init__.py,sha256=IYw-PcsdgjSpS1mU_ZcYkTfPocsJ4aVmrDxP7vX7c6Y,709
|
2
|
-
google/genai/_api_client.py,sha256=wLDcPY7qZi3caUlN-uIzbir6gzKQZg-zP8cxBp9Yq5g,22534
|
3
|
-
google/genai/_api_module.py,sha256=9bxmtcSTpT8Ht6VwJyw7fQqiR0jJXz7350dWGl-bC5E,780
|
4
|
-
google/genai/_automatic_function_calling_util.py,sha256=Hs7vvLRCRxL-YbNRnwx_qulY9sspwE6xP7A3-cjoIB8,10834
|
5
|
-
google/genai/_common.py,sha256=HrGkshBrfkt5bARjtJ8-dSLJSKEptM1JnqDG5AGm2Rw,9565
|
6
|
-
google/genai/_extra_utils.py,sha256=vpZs7mrAwZ1mJrbsmSdqrDepLe4hyPgjNYENV56lv2Y,11508
|
7
|
-
google/genai/_operations.py,sha256=KaDgwqG5g6Odd1P6ftvIUT9gF3ov08drm01jE1CjB_s,11490
|
8
|
-
google/genai/_replay_api_client.py,sha256=f_znGdDKXUOEN8lkRBzVZ6LDSGwrWHzy9N-Sk6pUU4E,14963
|
9
|
-
google/genai/_test_api_client.py,sha256=2PvDcW3h01U4UOSoj7TUo6TwdBHSEN_lO2tXjBoh5Fw,4765
|
10
|
-
google/genai/_transformers.py,sha256=BfKU8xla1OmE5MmTxhYIMhBjZE3LJ2Rag1Fd6ojXX18,23891
|
11
|
-
google/genai/batches.py,sha256=jv8pW_g_cZee6ol5ER5bQRUkXsj4IUcZC5cMo-YAnt0,38033
|
12
|
-
google/genai/caches.py,sha256=jsiclHO71kIa2CNrds3O8PL2fCNr_dlhUSPjhiRsjNE,53152
|
13
|
-
google/genai/chats.py,sha256=6gKf81vtLqUAR2TeaI0kZfxrEPEHbfwxHB5hI9zSz9A,8552
|
14
|
-
google/genai/client.py,sha256=MTZ3DOXk1_xgljaHlvF16jr_SKVPRfU8lZ1eH_dfDeQ,9334
|
15
|
-
google/genai/errors.py,sha256=dea3cQecyGFMoV5oIvUfKeMY904HzlcT4oiPWQzDCZo,3746
|
16
|
-
google/genai/files.py,sha256=U3qaa31AX7dKcZh6RkZSAkrDO7FVitukMW67wxL70kQ,42074
|
17
|
-
google/genai/live.py,sha256=xDu1wV8iQ5lI2i4_AmtOQOuiiPXBt6WykV_rXfjb0Sc,23467
|
18
|
-
google/genai/models.py,sha256=GEmUx8hLdfEenZNeUDjbKkpHHXsFiaxmAI5JN9OQHXA,178456
|
19
|
-
google/genai/pagers.py,sha256=hSHd-gLvEzYWwK85i8EcFNWUMKtszUs7Nw2r3L7d6_U,6686
|
20
|
-
google/genai/tunings.py,sha256=sZYVy8gJmvMLxYGLVDhASVPNP58ngNVIQb3CWJVTs48,44678
|
21
|
-
google/genai/types.py,sha256=2Ysd4tt4a2_FK8L-idyH6a9UvoXKOr0eg_xluGl_34M,281256
|
22
|
-
google/genai/version.py,sha256=xY649pcj-oW-ztwg6bMebnF3eIBvVGp4g6eFatbMDGQ,626
|
23
|
-
google_genai-1.1.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
24
|
-
google_genai-1.1.0.dist-info/METADATA,sha256=xywOX430bytBvC7mthMlXcpVJPUF7ugZocPm2UvG9wY,26094
|
25
|
-
google_genai-1.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
26
|
-
google_genai-1.1.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
27
|
-
google_genai-1.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|