google-genai 0.3.0__py3-none-any.whl → 0.4.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/__init__.py +2 -1
- google/genai/_api_client.py +85 -36
- google/genai/_automatic_function_calling_util.py +14 -14
- google/genai/_replay_api_client.py +22 -28
- google/genai/batches.py +16 -16
- google/genai/caches.py +18 -18
- google/genai/chats.py +2 -2
- google/genai/client.py +6 -3
- google/genai/files.py +22 -22
- google/genai/live.py +28 -5
- google/genai/models.py +97 -77
- google/genai/tunings.py +17 -17
- google/genai/types.py +150 -80
- google/genai/version.py +16 -0
- {google_genai-0.3.0.dist-info → google_genai-0.4.0.dist-info}/METADATA +57 -17
- google_genai-0.4.0.dist-info/RECORD +25 -0
- {google_genai-0.3.0.dist-info → google_genai-0.4.0.dist-info}/WHEEL +1 -1
- google_genai-0.3.0.dist-info/RECORD +0 -24
- {google_genai-0.3.0.dist-info → google_genai-0.4.0.dist-info}/LICENSE +0 -0
- {google_genai-0.3.0.dist-info → google_genai-0.4.0.dist-info}/top_level.txt +0 -0
google/genai/chats.py
CHANGED
@@ -109,7 +109,7 @@ class Chat(_BaseChat):
|
|
109
109
|
.. code-block:: python
|
110
110
|
|
111
111
|
chat = client.chats.create(model='gemini-1.5-flash')
|
112
|
-
for chunk in chat.send_message_stream('tell me a story')
|
112
|
+
for chunk in chat.send_message_stream('tell me a story'):
|
113
113
|
print(chunk.text)
|
114
114
|
"""
|
115
115
|
|
@@ -215,7 +215,7 @@ class AsyncChat(_BaseChat):
|
|
215
215
|
|
216
216
|
.. code-block:: python
|
217
217
|
chat = client.aio.chats.create(model='gemini-1.5-flash')
|
218
|
-
async for chunk in chat.send_message_stream('tell me a story')
|
218
|
+
async for chunk in chat.send_message_stream('tell me a story'):
|
219
219
|
print(chunk.text)
|
220
220
|
"""
|
221
221
|
|
google/genai/client.py
CHANGED
@@ -14,12 +14,12 @@
|
|
14
14
|
#
|
15
15
|
|
16
16
|
import os
|
17
|
-
from typing import Optional
|
17
|
+
from typing import Optional, Union
|
18
18
|
|
19
19
|
import google.auth
|
20
20
|
import pydantic
|
21
21
|
|
22
|
-
from ._api_client import ApiClient, HttpOptions
|
22
|
+
from ._api_client import ApiClient, HttpOptions, HttpOptionsDict
|
23
23
|
from ._replay_api_client import ReplayApiClient
|
24
24
|
from .batches import AsyncBatches, Batches
|
25
25
|
from .caches import AsyncCaches, Caches
|
@@ -145,7 +145,7 @@ class Client:
|
|
145
145
|
project: Optional[str] = None,
|
146
146
|
location: Optional[str] = None,
|
147
147
|
debug_config: Optional[DebugConfig] = None,
|
148
|
-
http_options: Optional[HttpOptions] = None,
|
148
|
+
http_options: Optional[Union[HttpOptions, HttpOptionsDict]] = None,
|
149
149
|
):
|
150
150
|
"""Initializes the client.
|
151
151
|
|
@@ -179,6 +179,9 @@ class Client:
|
|
179
179
|
debug_config (DebugConfig):
|
180
180
|
Config settings that control network
|
181
181
|
behavior of the client. This is typically used when running test code.
|
182
|
+
http_options (Union[HttpOptions, HttpOptionsDict]):
|
183
|
+
Http options to use for the client. Response_payload can't be
|
184
|
+
set when passing to the client constructor.
|
182
185
|
"""
|
183
186
|
|
184
187
|
self._debug_config = debug_config or DebugConfig()
|
google/genai/files.py
CHANGED
@@ -98,7 +98,7 @@ def _ListFilesParameters_to_vertex(
|
|
98
98
|
parent_object: dict = None,
|
99
99
|
) -> dict:
|
100
100
|
to_object = {}
|
101
|
-
if getv(from_object, ['config']):
|
101
|
+
if getv(from_object, ['config']) is not None:
|
102
102
|
raise ValueError('config parameter is not supported in Vertex AI.')
|
103
103
|
|
104
104
|
return to_object
|
@@ -128,13 +128,13 @@ def _FileStatus_to_vertex(
|
|
128
128
|
parent_object: dict = None,
|
129
129
|
) -> dict:
|
130
130
|
to_object = {}
|
131
|
-
if getv(from_object, ['details']):
|
131
|
+
if getv(from_object, ['details']) is not None:
|
132
132
|
raise ValueError('details parameter is not supported in Vertex AI.')
|
133
133
|
|
134
|
-
if getv(from_object, ['message']):
|
134
|
+
if getv(from_object, ['message']) is not None:
|
135
135
|
raise ValueError('message parameter is not supported in Vertex AI.')
|
136
136
|
|
137
|
-
if getv(from_object, ['code']):
|
137
|
+
if getv(from_object, ['code']) is not None:
|
138
138
|
raise ValueError('code parameter is not supported in Vertex AI.')
|
139
139
|
|
140
140
|
return to_object
|
@@ -197,40 +197,40 @@ def _File_to_vertex(
|
|
197
197
|
parent_object: dict = None,
|
198
198
|
) -> dict:
|
199
199
|
to_object = {}
|
200
|
-
if getv(from_object, ['name']):
|
200
|
+
if getv(from_object, ['name']) is not None:
|
201
201
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
202
202
|
|
203
|
-
if getv(from_object, ['display_name']):
|
203
|
+
if getv(from_object, ['display_name']) is not None:
|
204
204
|
raise ValueError('display_name parameter is not supported in Vertex AI.')
|
205
205
|
|
206
|
-
if getv(from_object, ['mime_type']):
|
206
|
+
if getv(from_object, ['mime_type']) is not None:
|
207
207
|
raise ValueError('mime_type parameter is not supported in Vertex AI.')
|
208
208
|
|
209
|
-
if getv(from_object, ['size_bytes']):
|
209
|
+
if getv(from_object, ['size_bytes']) is not None:
|
210
210
|
raise ValueError('size_bytes parameter is not supported in Vertex AI.')
|
211
211
|
|
212
|
-
if getv(from_object, ['create_time']):
|
212
|
+
if getv(from_object, ['create_time']) is not None:
|
213
213
|
raise ValueError('create_time parameter is not supported in Vertex AI.')
|
214
214
|
|
215
|
-
if getv(from_object, ['expiration_time']):
|
215
|
+
if getv(from_object, ['expiration_time']) is not None:
|
216
216
|
raise ValueError('expiration_time parameter is not supported in Vertex AI.')
|
217
217
|
|
218
|
-
if getv(from_object, ['update_time']):
|
218
|
+
if getv(from_object, ['update_time']) is not None:
|
219
219
|
raise ValueError('update_time parameter is not supported in Vertex AI.')
|
220
220
|
|
221
|
-
if getv(from_object, ['sha256_hash']):
|
221
|
+
if getv(from_object, ['sha256_hash']) is not None:
|
222
222
|
raise ValueError('sha256_hash parameter is not supported in Vertex AI.')
|
223
223
|
|
224
|
-
if getv(from_object, ['uri']):
|
224
|
+
if getv(from_object, ['uri']) is not None:
|
225
225
|
raise ValueError('uri parameter is not supported in Vertex AI.')
|
226
226
|
|
227
|
-
if getv(from_object, ['state']):
|
227
|
+
if getv(from_object, ['state']) is not None:
|
228
228
|
raise ValueError('state parameter is not supported in Vertex AI.')
|
229
229
|
|
230
|
-
if getv(from_object, ['video_metadata']):
|
230
|
+
if getv(from_object, ['video_metadata']) is not None:
|
231
231
|
raise ValueError('video_metadata parameter is not supported in Vertex AI.')
|
232
232
|
|
233
|
-
if getv(from_object, ['error']):
|
233
|
+
if getv(from_object, ['error']) is not None:
|
234
234
|
raise ValueError('error parameter is not supported in Vertex AI.')
|
235
235
|
|
236
236
|
return to_object
|
@@ -291,10 +291,10 @@ def _CreateFileParameters_to_vertex(
|
|
291
291
|
parent_object: dict = None,
|
292
292
|
) -> dict:
|
293
293
|
to_object = {}
|
294
|
-
if getv(from_object, ['file']):
|
294
|
+
if getv(from_object, ['file']) is not None:
|
295
295
|
raise ValueError('file parameter is not supported in Vertex AI.')
|
296
296
|
|
297
|
-
if getv(from_object, ['config']):
|
297
|
+
if getv(from_object, ['config']) is not None:
|
298
298
|
raise ValueError('config parameter is not supported in Vertex AI.')
|
299
299
|
|
300
300
|
return to_object
|
@@ -355,10 +355,10 @@ def _GetFileParameters_to_vertex(
|
|
355
355
|
parent_object: dict = None,
|
356
356
|
) -> dict:
|
357
357
|
to_object = {}
|
358
|
-
if getv(from_object, ['name']):
|
358
|
+
if getv(from_object, ['name']) is not None:
|
359
359
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
360
360
|
|
361
|
-
if getv(from_object, ['config']):
|
361
|
+
if getv(from_object, ['config']) is not None:
|
362
362
|
raise ValueError('config parameter is not supported in Vertex AI.')
|
363
363
|
|
364
364
|
return to_object
|
@@ -419,10 +419,10 @@ def _DeleteFileParameters_to_vertex(
|
|
419
419
|
parent_object: dict = None,
|
420
420
|
) -> dict:
|
421
421
|
to_object = {}
|
422
|
-
if getv(from_object, ['name']):
|
422
|
+
if getv(from_object, ['name']) is not None:
|
423
423
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
424
424
|
|
425
|
-
if getv(from_object, ['config']):
|
425
|
+
if getv(from_object, ['config']) is not None:
|
426
426
|
raise ValueError('config parameter is not supported in Vertex AI.')
|
427
427
|
|
428
428
|
return to_object
|
google/genai/live.py
CHANGED
@@ -68,6 +68,7 @@ class AsyncSession:
|
|
68
68
|
|
69
69
|
async def send(
|
70
70
|
self,
|
71
|
+
*,
|
71
72
|
input: Union[
|
72
73
|
types.ContentListUnion,
|
73
74
|
types.ContentListUnionDict,
|
@@ -80,6 +81,25 @@ class AsyncSession:
|
|
80
81
|
],
|
81
82
|
end_of_turn: Optional[bool] = False,
|
82
83
|
):
|
84
|
+
"""Send input to the model.
|
85
|
+
|
86
|
+
The method will send the input request to the server.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
input: The input request to the model.
|
90
|
+
end_of_turn: Whether the input is the last message in a turn.
|
91
|
+
|
92
|
+
Example usage:
|
93
|
+
|
94
|
+
.. code-block:: python
|
95
|
+
|
96
|
+
client = genai.Client(api_key=API_KEY)
|
97
|
+
|
98
|
+
async with client.aio.live.connect(model='...') as session:
|
99
|
+
await session.send(input='Hello world!', end_of_turn=True)
|
100
|
+
async for message in session.receive():
|
101
|
+
print(message)
|
102
|
+
"""
|
83
103
|
client_message = self._parse_client_message(input, end_of_turn)
|
84
104
|
await self._ws.send(json.dumps(client_message))
|
85
105
|
|
@@ -113,7 +133,7 @@ class AsyncSession:
|
|
113
133
|
yield result
|
114
134
|
|
115
135
|
async def start_stream(
|
116
|
-
self, stream: AsyncIterator[bytes], mime_type: str
|
136
|
+
self, *, stream: AsyncIterator[bytes], mime_type: str
|
117
137
|
) -> AsyncIterator[types.LiveServerMessage]:
|
118
138
|
"""start a live session from a data stream.
|
119
139
|
|
@@ -199,7 +219,7 @@ class AsyncSession:
|
|
199
219
|
):
|
200
220
|
async for data in data_stream:
|
201
221
|
input = {'data': data, 'mimeType': mime_type}
|
202
|
-
await self.send(input)
|
222
|
+
await self.send(input=input)
|
203
223
|
# Give a chance for the receive loop to process responses.
|
204
224
|
await asyncio.sleep(10**-12)
|
205
225
|
# Give a chance for the receiver to process the last response.
|
@@ -599,7 +619,10 @@ class AsyncLive(_common.BaseModule):
|
|
599
619
|
|
600
620
|
@contextlib.asynccontextmanager
|
601
621
|
async def connect(
|
602
|
-
self,
|
622
|
+
self,
|
623
|
+
*,
|
624
|
+
model: str,
|
625
|
+
config: Optional[types.LiveConnectConfigOrDict] = None,
|
603
626
|
) -> AsyncSession:
|
604
627
|
"""Connect to the live server.
|
605
628
|
|
@@ -609,9 +632,9 @@ class AsyncLive(_common.BaseModule):
|
|
609
632
|
|
610
633
|
client = genai.Client(api_key=API_KEY)
|
611
634
|
config = {}
|
612
|
-
async with client.aio.live.connect(model='
|
635
|
+
async with client.aio.live.connect(model='...', config=config) as session:
|
613
636
|
await session.send(input='Hello world!', end_of_turn=True)
|
614
|
-
async for message in session:
|
637
|
+
async for message in session.receive():
|
615
638
|
print(message)
|
616
639
|
"""
|
617
640
|
base_url = self.api_client._websocket_base_url()
|