google-genai 1.5.0__tar.gz → 1.7.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.5.0 → google_genai-1.7.0}/PKG-INFO +201 -31
- google_genai-1.5.0/google_genai.egg-info/PKG-INFO → google_genai-1.7.0/README.md +193 -53
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_api_client.py +196 -141
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_automatic_function_calling_util.py +4 -14
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_common.py +7 -5
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_replay_api_client.py +6 -3
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_transformers.py +61 -37
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/batches.py +4 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/caches.py +20 -26
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/chats.py +137 -46
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/client.py +3 -2
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/errors.py +11 -19
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/files.py +9 -9
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/live.py +276 -93
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/models.py +245 -68
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/operations.py +30 -2
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/pagers.py +3 -5
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/tunings.py +31 -21
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/types.py +88 -33
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/version.py +1 -1
- google_genai-1.5.0/README.md → google_genai-1.7.0/google_genai.egg-info/PKG-INFO +223 -23
- google_genai-1.7.0/google_genai.egg-info/requires.txt +7 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/pyproject.toml +8 -8
- google_genai-1.5.0/google_genai.egg-info/requires.txt +0 -7
- {google_genai-1.5.0 → google_genai-1.7.0}/LICENSE +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/MANIFEST.in +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/__init__.py +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_extra_utils.py +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google_genai.egg-info/SOURCES.txt +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.5.0 → google_genai-1.7.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: google-genai
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.7.0
|
4
4
|
Summary: GenAI Python SDK
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
6
6
|
License: Apache-2.0
|
@@ -20,13 +20,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
20
|
Requires-Python: >=3.9
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
License-File: LICENSE
|
23
|
-
Requires-Dist: anyio<5.0.
|
24
|
-
Requires-Dist: google-auth<3.0.
|
25
|
-
Requires-Dist: httpx<1.0.
|
26
|
-
Requires-Dist: pydantic<3.0.
|
27
|
-
Requires-Dist: requests<3.0.
|
28
|
-
Requires-Dist: websockets<15.
|
29
|
-
Requires-Dist: typing-extensions<5.0.
|
23
|
+
Requires-Dist: anyio<5.0.0,>=4.8.0
|
24
|
+
Requires-Dist: google-auth<3.0.0,>=2.14.1
|
25
|
+
Requires-Dist: httpx<1.0.0,>=0.28.1
|
26
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
27
|
+
Requires-Dist: requests<3.0.0,>=2.28.1
|
28
|
+
Requires-Dist: websockets<15.1.0,>=13.0.0
|
29
|
+
Requires-Dist: typing-extensions<5.0.0,>=4.11.0
|
30
30
|
|
31
31
|
# Google Gen AI SDK
|
32
32
|
|
@@ -41,7 +41,7 @@ Google Gen AI Python SDK provides an interface for developers to integrate Googl
|
|
41
41
|
|
42
42
|
## Installation
|
43
43
|
|
44
|
-
```
|
44
|
+
```sh
|
45
45
|
pip install google-genai
|
46
46
|
```
|
47
47
|
|
@@ -72,16 +72,16 @@ client = genai.Client(
|
|
72
72
|
**(Optional) Using environment variables:**
|
73
73
|
|
74
74
|
You can create a client by configuring the necessary environment variables.
|
75
|
-
Configuration setup instructions depends on whether you're using the Gemini
|
76
|
-
|
75
|
+
Configuration setup instructions depends on whether you're using the Gemini
|
76
|
+
Developer API or the Gemini API in Vertex AI.
|
77
77
|
|
78
|
-
**
|
78
|
+
**Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
|
79
79
|
|
80
80
|
```bash
|
81
81
|
export GOOGLE_API_KEY='your-api-key'
|
82
82
|
```
|
83
83
|
|
84
|
-
**Vertex AI
|
84
|
+
**Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_CLOUD_PROJECT`
|
85
85
|
and `GOOGLE_CLOUD_LOCATION`, as shown below:
|
86
86
|
|
87
87
|
```bash
|
@@ -142,7 +142,7 @@ response = client.models.generate_content(
|
|
142
142
|
print(response.text)
|
143
143
|
```
|
144
144
|
|
145
|
-
#### with uploaded file (Gemini API only)
|
145
|
+
#### with uploaded file (Gemini Developer API only)
|
146
146
|
download the file in console.
|
147
147
|
|
148
148
|
```sh
|
@@ -160,37 +160,203 @@ response = client.models.generate_content(
|
|
160
160
|
print(response.text)
|
161
161
|
```
|
162
162
|
|
163
|
-
#### How to structure `contents`
|
164
|
-
|
163
|
+
#### How to structure `contents` argument for `generate_content`
|
164
|
+
The SDK always converts the inputs to the `contents` argument into
|
165
|
+
`list[types.Content]`.
|
166
|
+
The following shows some common ways to provide your inputs.
|
167
|
+
|
168
|
+
##### Provide a `list[types.Content]`
|
169
|
+
This is the canonical way to provide contents, SDK will not do any conversion.
|
170
|
+
|
171
|
+
##### Provide a `types.Content` instance
|
172
|
+
|
173
|
+
```python
|
174
|
+
contents = types.Content(
|
175
|
+
role='user',
|
176
|
+
parts=[types.Part.from_text(text='Why is the sky blue?')]
|
177
|
+
)
|
178
|
+
```
|
179
|
+
|
180
|
+
SDK converts this to
|
181
|
+
|
182
|
+
```python
|
183
|
+
[
|
184
|
+
types.Content(
|
185
|
+
role='user',
|
186
|
+
parts=[types.Part.from_text(text='Why is the sky blue?')]
|
187
|
+
)
|
188
|
+
]
|
189
|
+
```
|
190
|
+
|
191
|
+
##### Provide a string
|
192
|
+
|
193
|
+
```python
|
194
|
+
contents='Why is the sky blue?'
|
195
|
+
```
|
196
|
+
|
197
|
+
The SDK will assume this is a text part, and it converts this into the following:
|
165
198
|
|
166
|
-
|
199
|
+
```python
|
200
|
+
[
|
201
|
+
types.UserContent(
|
202
|
+
parts=[
|
203
|
+
types.Part.from_text(text='Why is the sky blue?')
|
204
|
+
]
|
205
|
+
)
|
206
|
+
]
|
207
|
+
```
|
208
|
+
|
209
|
+
Where a `types.UserContent` is a subclass of `types.Content`, it sets the
|
210
|
+
`role` field to be `user`.
|
211
|
+
|
212
|
+
##### Provide a list of string
|
167
213
|
|
168
214
|
```python
|
169
|
-
contents='
|
215
|
+
contents=['Why is the sky blue?', 'Why is the cloud white?']
|
170
216
|
```
|
171
217
|
|
172
|
-
|
218
|
+
The SDK assumes these are 2 text parts, it converts this into a single content,
|
219
|
+
like the following:
|
173
220
|
|
174
221
|
```python
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
222
|
+
[
|
223
|
+
types.UserContent(
|
224
|
+
parts=[
|
225
|
+
types.Part.from_text(text='Why is the sky blue?'),
|
226
|
+
types.Part.from_text(text='Why is the cloud white?'),
|
227
|
+
]
|
228
|
+
)
|
229
|
+
]
|
179
230
|
```
|
180
231
|
|
181
|
-
|
182
|
-
|
232
|
+
Where a `types.UserContent` is a subclass of `types.Content`, the
|
233
|
+
`role` field in `types.UserContent` is fixed to be `user`.
|
234
|
+
|
235
|
+
##### Provide a function call part
|
183
236
|
|
184
237
|
```python
|
185
|
-
contents=
|
186
|
-
|
238
|
+
contents = types.Part.from_function_call(
|
239
|
+
name='get_weather_by_location',
|
240
|
+
args={'location': 'Boston'}
|
241
|
+
)
|
242
|
+
```
|
243
|
+
|
244
|
+
The SDK converts a function call part to a content with a `model` role:
|
245
|
+
|
246
|
+
```python
|
247
|
+
[
|
248
|
+
types.ModelContent(
|
249
|
+
parts=[
|
250
|
+
types.Part.from_function_call(
|
251
|
+
name='get_weather_by_location',
|
252
|
+
args={'location': 'Boston'}
|
253
|
+
)
|
254
|
+
]
|
255
|
+
)
|
256
|
+
]
|
257
|
+
```
|
258
|
+
|
259
|
+
Where a `types.ModelContent` is a subclass of `types.Content`, the
|
260
|
+
`role` field in `types.ModelContent` is fixed to be `model`.
|
261
|
+
|
262
|
+
##### Provide a list of function call parts
|
263
|
+
|
264
|
+
```python
|
265
|
+
contents = [
|
266
|
+
types.Part.from_function_call(
|
267
|
+
name='get_weather_by_location',
|
268
|
+
args={'location': 'Boston'}
|
269
|
+
),
|
270
|
+
types.Part.from_function_call(
|
271
|
+
name='get_weather_by_location',
|
272
|
+
args={'location': 'New York'}
|
273
|
+
),
|
274
|
+
]
|
275
|
+
```
|
276
|
+
|
277
|
+
The SDK converts a list of function call parts to the a content with a `model` role:
|
278
|
+
|
279
|
+
```python
|
280
|
+
[
|
281
|
+
types.ModelContent(
|
282
|
+
parts=[
|
283
|
+
types.Part.from_function_call(
|
284
|
+
name='get_weather_by_location',
|
285
|
+
args={'location': 'Boston'}
|
286
|
+
),
|
287
|
+
types.Part.from_function_call(
|
288
|
+
name='get_weather_by_location',
|
289
|
+
args={'location': 'New York'}
|
290
|
+
)
|
291
|
+
]
|
292
|
+
)
|
293
|
+
]
|
294
|
+
```
|
295
|
+
|
296
|
+
Where a `types.ModelContent` is a subclass of `types.Content`, the
|
297
|
+
`role` field in `types.ModelContent` is fixed to be `model`.
|
298
|
+
|
299
|
+
##### Provide a non function call part
|
300
|
+
|
301
|
+
```python
|
302
|
+
contents = types.Part.from_uri(
|
303
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
304
|
+
mime_type: 'image/jpeg',
|
305
|
+
)
|
306
|
+
```
|
307
|
+
|
308
|
+
The SDK converts all non function call parts into a content with a `user` role.
|
309
|
+
|
310
|
+
```python
|
311
|
+
[
|
312
|
+
types.UserContent(parts=[
|
187
313
|
types.Part.from_uri(
|
188
|
-
|
189
|
-
|
190
|
-
)
|
191
|
-
]
|
314
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
315
|
+
mime_type: 'image/jpeg',
|
316
|
+
)
|
317
|
+
])
|
318
|
+
]
|
319
|
+
```
|
320
|
+
|
321
|
+
##### Provide a list of non function call parts
|
322
|
+
|
323
|
+
```python
|
324
|
+
contents = [
|
325
|
+
types.Part.from_text('What is this image about?'),
|
326
|
+
types.Part.from_uri(
|
327
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
328
|
+
mime_type: 'image/jpeg',
|
329
|
+
)
|
330
|
+
]
|
331
|
+
```
|
332
|
+
|
333
|
+
The SDK will convert the list of parts into a content with a `user` role
|
334
|
+
|
335
|
+
```python
|
336
|
+
[
|
337
|
+
types.UserContent(
|
338
|
+
parts=[
|
339
|
+
types.Part.from_text('What is this image about?'),
|
340
|
+
types.Part.from_uri(
|
341
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
342
|
+
mime_type: 'image/jpeg',
|
343
|
+
)
|
344
|
+
]
|
345
|
+
)
|
346
|
+
]
|
192
347
|
```
|
193
348
|
|
349
|
+
##### Mix types in contents
|
350
|
+
|
351
|
+
You can also provide a list of `types.ContentUnion`. The SDK leaves items of
|
352
|
+
`types.Content` as is, it groups consecutive non function call parts into a
|
353
|
+
single `types.UserContent`, and it groups consecutive function call parts into
|
354
|
+
a single `types.ModelContent`.
|
355
|
+
|
356
|
+
If you put a list within a list, the inner list can only contain
|
357
|
+
`types.PartUnion` items. The SDK will convert the inner list into a single
|
358
|
+
`types.UserContent`.
|
359
|
+
|
194
360
|
### System Instructions and Other Configs
|
195
361
|
|
196
362
|
The output of the model can be influenced by several optional settings
|
@@ -481,6 +647,10 @@ response = client.models.generate_content(
|
|
481
647
|
```
|
482
648
|
### JSON Response Schema
|
483
649
|
|
650
|
+
However you define your schema, don't duplicate it in your input prompt,
|
651
|
+
including by giving examples of expected JSON output. If you do, the generated
|
652
|
+
output might be lower in quality.
|
653
|
+
|
484
654
|
#### Pydantic Model Schema support
|
485
655
|
|
486
656
|
Schemas can be provided as Pydantic Models.
|
@@ -1,33 +1,3 @@
|
|
1
|
-
Metadata-Version: 2.2
|
2
|
-
Name: google-genai
|
3
|
-
Version: 1.5.0
|
4
|
-
Summary: GenAI Python SDK
|
5
|
-
Author-email: Google LLC <googleapis-packages@google.com>
|
6
|
-
License: Apache-2.0
|
7
|
-
Project-URL: Homepage, https://github.com/googleapis/python-genai
|
8
|
-
Classifier: Intended Audience :: Developers
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Classifier: Programming Language :: Python
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
17
|
-
Classifier: Programming Language :: Python :: 3.13
|
18
|
-
Classifier: Topic :: Internet
|
19
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
20
|
-
Requires-Python: >=3.9
|
21
|
-
Description-Content-Type: text/markdown
|
22
|
-
License-File: LICENSE
|
23
|
-
Requires-Dist: anyio<5.0.0dev,>=4.8.0
|
24
|
-
Requires-Dist: google-auth<3.0.0dev,>=2.14.1
|
25
|
-
Requires-Dist: httpx<1.0.0dev,>=0.28.1
|
26
|
-
Requires-Dist: pydantic<3.0.0dev,>=2.0.0
|
27
|
-
Requires-Dist: requests<3.0.0dev,>=2.28.1
|
28
|
-
Requires-Dist: websockets<15.0dev,>=13.0
|
29
|
-
Requires-Dist: typing-extensions<5.0.0dev,>=4.11.0
|
30
|
-
|
31
1
|
# Google Gen AI SDK
|
32
2
|
|
33
3
|
[](https://pypi.org/project/google-genai/)
|
@@ -41,7 +11,7 @@ Google Gen AI Python SDK provides an interface for developers to integrate Googl
|
|
41
11
|
|
42
12
|
## Installation
|
43
13
|
|
44
|
-
```
|
14
|
+
```sh
|
45
15
|
pip install google-genai
|
46
16
|
```
|
47
17
|
|
@@ -72,16 +42,16 @@ client = genai.Client(
|
|
72
42
|
**(Optional) Using environment variables:**
|
73
43
|
|
74
44
|
You can create a client by configuring the necessary environment variables.
|
75
|
-
Configuration setup instructions depends on whether you're using the Gemini
|
76
|
-
|
45
|
+
Configuration setup instructions depends on whether you're using the Gemini
|
46
|
+
Developer API or the Gemini API in Vertex AI.
|
77
47
|
|
78
|
-
**
|
48
|
+
**Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
|
79
49
|
|
80
50
|
```bash
|
81
51
|
export GOOGLE_API_KEY='your-api-key'
|
82
52
|
```
|
83
53
|
|
84
|
-
**Vertex AI
|
54
|
+
**Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_CLOUD_PROJECT`
|
85
55
|
and `GOOGLE_CLOUD_LOCATION`, as shown below:
|
86
56
|
|
87
57
|
```bash
|
@@ -142,7 +112,7 @@ response = client.models.generate_content(
|
|
142
112
|
print(response.text)
|
143
113
|
```
|
144
114
|
|
145
|
-
#### with uploaded file (Gemini API only)
|
115
|
+
#### with uploaded file (Gemini Developer API only)
|
146
116
|
download the file in console.
|
147
117
|
|
148
118
|
```sh
|
@@ -160,37 +130,203 @@ response = client.models.generate_content(
|
|
160
130
|
print(response.text)
|
161
131
|
```
|
162
132
|
|
163
|
-
#### How to structure `contents`
|
164
|
-
|
133
|
+
#### How to structure `contents` argument for `generate_content`
|
134
|
+
The SDK always converts the inputs to the `contents` argument into
|
135
|
+
`list[types.Content]`.
|
136
|
+
The following shows some common ways to provide your inputs.
|
137
|
+
|
138
|
+
##### Provide a `list[types.Content]`
|
139
|
+
This is the canonical way to provide contents, SDK will not do any conversion.
|
140
|
+
|
141
|
+
##### Provide a `types.Content` instance
|
142
|
+
|
143
|
+
```python
|
144
|
+
contents = types.Content(
|
145
|
+
role='user',
|
146
|
+
parts=[types.Part.from_text(text='Why is the sky blue?')]
|
147
|
+
)
|
148
|
+
```
|
149
|
+
|
150
|
+
SDK converts this to
|
151
|
+
|
152
|
+
```python
|
153
|
+
[
|
154
|
+
types.Content(
|
155
|
+
role='user',
|
156
|
+
parts=[types.Part.from_text(text='Why is the sky blue?')]
|
157
|
+
)
|
158
|
+
]
|
159
|
+
```
|
160
|
+
|
161
|
+
##### Provide a string
|
162
|
+
|
163
|
+
```python
|
164
|
+
contents='Why is the sky blue?'
|
165
|
+
```
|
166
|
+
|
167
|
+
The SDK will assume this is a text part, and it converts this into the following:
|
168
|
+
|
169
|
+
```python
|
170
|
+
[
|
171
|
+
types.UserContent(
|
172
|
+
parts=[
|
173
|
+
types.Part.from_text(text='Why is the sky blue?')
|
174
|
+
]
|
175
|
+
)
|
176
|
+
]
|
177
|
+
```
|
178
|
+
|
179
|
+
Where a `types.UserContent` is a subclass of `types.Content`, it sets the
|
180
|
+
`role` field to be `user`.
|
181
|
+
|
182
|
+
##### Provide a list of string
|
183
|
+
|
184
|
+
```python
|
185
|
+
contents=['Why is the sky blue?', 'Why is the cloud white?']
|
186
|
+
```
|
187
|
+
|
188
|
+
The SDK assumes these are 2 text parts, it converts this into a single content,
|
189
|
+
like the following:
|
190
|
+
|
191
|
+
```python
|
192
|
+
[
|
193
|
+
types.UserContent(
|
194
|
+
parts=[
|
195
|
+
types.Part.from_text(text='Why is the sky blue?'),
|
196
|
+
types.Part.from_text(text='Why is the cloud white?'),
|
197
|
+
]
|
198
|
+
)
|
199
|
+
]
|
200
|
+
```
|
201
|
+
|
202
|
+
Where a `types.UserContent` is a subclass of `types.Content`, the
|
203
|
+
`role` field in `types.UserContent` is fixed to be `user`.
|
204
|
+
|
205
|
+
##### Provide a function call part
|
206
|
+
|
207
|
+
```python
|
208
|
+
contents = types.Part.from_function_call(
|
209
|
+
name='get_weather_by_location',
|
210
|
+
args={'location': 'Boston'}
|
211
|
+
)
|
212
|
+
```
|
213
|
+
|
214
|
+
The SDK converts a function call part to a content with a `model` role:
|
215
|
+
|
216
|
+
```python
|
217
|
+
[
|
218
|
+
types.ModelContent(
|
219
|
+
parts=[
|
220
|
+
types.Part.from_function_call(
|
221
|
+
name='get_weather_by_location',
|
222
|
+
args={'location': 'Boston'}
|
223
|
+
)
|
224
|
+
]
|
225
|
+
)
|
226
|
+
]
|
227
|
+
```
|
165
228
|
|
166
|
-
|
229
|
+
Where a `types.ModelContent` is a subclass of `types.Content`, the
|
230
|
+
`role` field in `types.ModelContent` is fixed to be `model`.
|
231
|
+
|
232
|
+
##### Provide a list of function call parts
|
167
233
|
|
168
234
|
```python
|
169
|
-
contents=
|
235
|
+
contents = [
|
236
|
+
types.Part.from_function_call(
|
237
|
+
name='get_weather_by_location',
|
238
|
+
args={'location': 'Boston'}
|
239
|
+
),
|
240
|
+
types.Part.from_function_call(
|
241
|
+
name='get_weather_by_location',
|
242
|
+
args={'location': 'New York'}
|
243
|
+
),
|
244
|
+
]
|
245
|
+
```
|
246
|
+
|
247
|
+
The SDK converts a list of function call parts to the a content with a `model` role:
|
248
|
+
|
249
|
+
```python
|
250
|
+
[
|
251
|
+
types.ModelContent(
|
252
|
+
parts=[
|
253
|
+
types.Part.from_function_call(
|
254
|
+
name='get_weather_by_location',
|
255
|
+
args={'location': 'Boston'}
|
256
|
+
),
|
257
|
+
types.Part.from_function_call(
|
258
|
+
name='get_weather_by_location',
|
259
|
+
args={'location': 'New York'}
|
260
|
+
)
|
261
|
+
]
|
262
|
+
)
|
263
|
+
]
|
170
264
|
```
|
171
265
|
|
172
|
-
|
266
|
+
Where a `types.ModelContent` is a subclass of `types.Content`, the
|
267
|
+
`role` field in `types.ModelContent` is fixed to be `model`.
|
268
|
+
|
269
|
+
##### Provide a non function call part
|
173
270
|
|
174
271
|
```python
|
175
|
-
contents=types.
|
176
|
-
|
177
|
-
|
178
|
-
|
272
|
+
contents = types.Part.from_uri(
|
273
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
274
|
+
mime_type: 'image/jpeg',
|
275
|
+
)
|
179
276
|
```
|
180
277
|
|
181
|
-
|
182
|
-
instances:
|
278
|
+
The SDK converts all non function call parts into a content with a `user` role.
|
183
279
|
|
184
280
|
```python
|
185
|
-
|
186
|
-
|
281
|
+
[
|
282
|
+
types.UserContent(parts=[
|
187
283
|
types.Part.from_uri(
|
188
|
-
|
189
|
-
|
190
|
-
)
|
191
|
-
]
|
284
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
285
|
+
mime_type: 'image/jpeg',
|
286
|
+
)
|
287
|
+
])
|
288
|
+
]
|
289
|
+
```
|
290
|
+
|
291
|
+
##### Provide a list of non function call parts
|
292
|
+
|
293
|
+
```python
|
294
|
+
contents = [
|
295
|
+
types.Part.from_text('What is this image about?'),
|
296
|
+
types.Part.from_uri(
|
297
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
298
|
+
mime_type: 'image/jpeg',
|
299
|
+
)
|
300
|
+
]
|
192
301
|
```
|
193
302
|
|
303
|
+
The SDK will convert the list of parts into a content with a `user` role
|
304
|
+
|
305
|
+
```python
|
306
|
+
[
|
307
|
+
types.UserContent(
|
308
|
+
parts=[
|
309
|
+
types.Part.from_text('What is this image about?'),
|
310
|
+
types.Part.from_uri(
|
311
|
+
file_uri: 'gs://generativeai-downloads/images/scones.jpg',
|
312
|
+
mime_type: 'image/jpeg',
|
313
|
+
)
|
314
|
+
]
|
315
|
+
)
|
316
|
+
]
|
317
|
+
```
|
318
|
+
|
319
|
+
##### Mix types in contents
|
320
|
+
|
321
|
+
You can also provide a list of `types.ContentUnion`. The SDK leaves items of
|
322
|
+
`types.Content` as is, it groups consecutive non function call parts into a
|
323
|
+
single `types.UserContent`, and it groups consecutive function call parts into
|
324
|
+
a single `types.ModelContent`.
|
325
|
+
|
326
|
+
If you put a list within a list, the inner list can only contain
|
327
|
+
`types.PartUnion` items. The SDK will convert the inner list into a single
|
328
|
+
`types.UserContent`.
|
329
|
+
|
194
330
|
### System Instructions and Other Configs
|
195
331
|
|
196
332
|
The output of the model can be influenced by several optional settings
|
@@ -481,6 +617,10 @@ response = client.models.generate_content(
|
|
481
617
|
```
|
482
618
|
### JSON Response Schema
|
483
619
|
|
620
|
+
However you define your schema, don't duplicate it in your input prompt,
|
621
|
+
including by giving examples of expected JSON output. If you do, the generated
|
622
|
+
output might be lower in quality.
|
623
|
+
|
484
624
|
#### Pydantic Model Schema support
|
485
625
|
|
486
626
|
Schemas can be provided as Pydantic Models.
|