Skip to content

Commit e5dd7ed

Browse files
feat: [google-ai-generativelanguage] Add video metadata to files API (#12704)
BEGIN_COMMIT_OVERRIDE feat(v1beta): Add video metadata to files API feat(v1beta): Update timeouts for generate content docs(v1beta): Minor updates feat(v1): Add usage metadata to GenerateContentResponse feat(v1): Add generate_content_request to CountTokensRequest feat(v1): Update timeouts docs(v1): Minor updates END_COMMIT_OVERRIDE - [ ] Regenerate this pull request now. PiperOrigin-RevId: 634425922 Source-Link: googleapis/googleapis@298a53b Source-Link: googleapis/googleapis-gen@e549e3f Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiZTU0OWUzZmY0ZmJmZGMzNTc5ZjJlZWY1OWVhMDhjNzA3MDZkNDZmMiJ9 BEGIN_NESTED_COMMIT feat: [google-ai-generativelanguage] Add usage metadata to GenerateContentResponse feat: Add generate_content_request to CountTokensRequest feat: Update timeouts docs: Minor updates PiperOrigin-RevId: 634424772 Source-Link: googleapis/googleapis@b546bed Source-Link: googleapis/googleapis-gen@c09c0f6 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiYzA5YzBmNjI5MjIwMDVmNjczZTczZDAzNGI2MTI2NTc2MzE4ZGY3NCJ9 END_NESTED_COMMIT --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 6ccf5dc commit e5dd7ed

23 files changed

Lines changed: 163 additions & 49 deletions

File tree

packages/google-ai-generativelanguage/google/ai/generativelanguage/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
Message,
9090
MessagePrompt,
9191
)
92-
from google.ai.generativelanguage_v1beta.types.file import File
92+
from google.ai.generativelanguage_v1beta.types.file import File, VideoMetadata
9393
from google.ai.generativelanguage_v1beta.types.file_service import (
9494
CreateFileRequest,
9595
CreateFileResponse,
@@ -251,6 +251,7 @@
251251
"Message",
252252
"MessagePrompt",
253253
"File",
254+
"VideoMetadata",
254255
"CreateFileRequest",
255256
"CreateFileResponse",
256257
"DeleteFileRequest",

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/async_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ async def generate_content(
283283
r"""Generates a response from the model given an input
284284
``GenerateContentRequest``.
285285
286+
Input capabilities differ between models, including tuned
287+
models. See the `model
288+
guide <https://ai.google.dev/models/gemini>`__ and `tuning
289+
guide <https://ai.google.dev/docs/model_tuning_guidance>`__ for
290+
details.
291+
286292
.. code-block:: python
287293
288294
# This snippet has been automatically generated and should be regarded as a
@@ -847,8 +853,9 @@ async def sample_count_tokens():
847853
on the ``request`` instance; if ``request`` is provided, this
848854
should not be set.
849855
contents (:class:`MutableSequence[google.ai.generativelanguage_v1.types.Content]`):
850-
Required. The input given to the
851-
model as a prompt.
856+
Optional. The input given to the model as a prompt. This
857+
field is ignored when ``generate_content_request`` is
858+
set.
852859
853860
This corresponds to the ``contents`` field
854861
on the ``request`` instance; if ``request`` is provided, this

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,12 @@ def generate_content(
696696
r"""Generates a response from the model given an input
697697
``GenerateContentRequest``.
698698
699+
Input capabilities differ between models, including tuned
700+
models. See the `model
701+
guide <https://ai.google.dev/models/gemini>`__ and `tuning
702+
guide <https://ai.google.dev/docs/model_tuning_guidance>`__ for
703+
details.
704+
699705
.. code-block:: python
700706
701707
# This snippet has been automatically generated and should be regarded as a
@@ -1248,8 +1254,9 @@ def sample_count_tokens():
12481254
on the ``request`` instance; if ``request`` is provided, this
12491255
should not be set.
12501256
contents (MutableSequence[google.ai.generativelanguage_v1.types.Content]):
1251-
Required. The input given to the
1252-
model as a prompt.
1257+
Optional. The input given to the model as a prompt. This
1258+
field is ignored when ``generate_content_request`` is
1259+
set.
12531260
12541261
This corresponds to the ``contents`` field
12551262
on the ``request`` instance; if ``request`` is provided, this

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ def _prep_wrapped_messages(self, client_info):
136136
predicate=retries.if_exception_type(
137137
core_exceptions.ServiceUnavailable,
138138
),
139-
deadline=60.0,
139+
deadline=600.0,
140140
),
141-
default_timeout=60.0,
141+
default_timeout=600.0,
142142
client_info=client_info,
143143
),
144144
self.stream_generate_content: gapic_v1.method.wrap_method(
@@ -150,9 +150,9 @@ def _prep_wrapped_messages(self, client_info):
150150
predicate=retries.if_exception_type(
151151
core_exceptions.ServiceUnavailable,
152152
),
153-
deadline=60.0,
153+
deadline=600.0,
154154
),
155-
default_timeout=60.0,
155+
default_timeout=600.0,
156156
client_info=client_info,
157157
),
158158
self.embed_content: gapic_v1.method.wrap_method(

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ def generate_content(
247247
Generates a response from the model given an input
248248
``GenerateContentRequest``.
249249
250+
Input capabilities differ between models, including tuned
251+
models. See the `model
252+
guide <https://ai.google.dev/models/gemini>`__ and `tuning
253+
guide <https://ai.google.dev/docs/model_tuning_guidance>`__ for
254+
details.
255+
250256
Returns:
251257
Callable[[~.GenerateContentRequest],
252258
~.GenerateContentResponse]:

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc_asyncio.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ def generate_content(
251251
Generates a response from the model given an input
252252
``GenerateContentRequest``.
253253
254+
Input capabilities differ between models, including tuned
255+
models. See the `model
256+
guide <https://ai.google.dev/models/gemini>`__ and `tuning
257+
guide <https://ai.google.dev/docs/model_tuning_guidance>`__ for
258+
details.
259+
254260
Returns:
255261
Callable[[~.GenerateContentRequest],
256262
Awaitable[~.GenerateContentResponse]]:
@@ -401,9 +407,9 @@ def _prep_wrapped_messages(self, client_info):
401407
predicate=retries.if_exception_type(
402408
core_exceptions.ServiceUnavailable,
403409
),
404-
deadline=60.0,
410+
deadline=600.0,
405411
),
406-
default_timeout=60.0,
412+
default_timeout=600.0,
407413
client_info=client_info,
408414
),
409415
self.stream_generate_content: gapic_v1.method_async.wrap_method(
@@ -415,9 +421,9 @@ def _prep_wrapped_messages(self, client_info):
415421
predicate=retries.if_exception_type(
416422
core_exceptions.ServiceUnavailable,
417423
),
418-
deadline=60.0,
424+
deadline=600.0,
419425
),
420-
default_timeout=60.0,
426+
default_timeout=600.0,
421427
client_info=client_info,
422428
),
423429
self.embed_content: gapic_v1.method_async.wrap_method(

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/types/content.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ class Blob(proto.Message):
109109
110110
Attributes:
111111
mime_type (str):
112-
The IANA standard MIME type of the source
113-
data. Accepted types include: "image/png",
114-
"image/jpeg", "image/heic", "image/heif",
115-
"image/webp".
112+
The IANA standard MIME type of the source data. Examples:
113+
114+
- image/png
115+
- image/jpeg If an unsupported MIME type is provided, an
116+
error will be returned. For a complete list of supported
117+
types, see `Supported file
118+
formats <https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats>`__.
116119
data (bytes):
117120
Raw bytes for media formats.
118121
"""

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/types/generative_service.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class GenerateContentResponse(proto.Message):
273273
prompt_feedback (google.ai.generativelanguage_v1.types.GenerateContentResponse.PromptFeedback):
274274
Returns the prompt's feedback related to the
275275
content filters.
276+
usage_metadata (google.ai.generativelanguage_v1.types.GenerateContentResponse.UsageMetadata):
277+
Output only. Metadata on the generation
278+
requests' token usage.
276279
"""
277280

278281
class PromptFeedback(proto.Message):
@@ -319,6 +322,33 @@ class BlockReason(proto.Enum):
319322
message=safety.SafetyRating,
320323
)
321324

325+
class UsageMetadata(proto.Message):
326+
r"""Metadata on the generation request's token usage.
327+
328+
Attributes:
329+
prompt_token_count (int):
330+
Number of tokens in the prompt.
331+
candidates_token_count (int):
332+
Total number of tokens across the generated
333+
candidates.
334+
total_token_count (int):
335+
Total token count for the generation request
336+
(prompt + candidates).
337+
"""
338+
339+
prompt_token_count: int = proto.Field(
340+
proto.INT32,
341+
number=1,
342+
)
343+
candidates_token_count: int = proto.Field(
344+
proto.INT32,
345+
number=2,
346+
)
347+
total_token_count: int = proto.Field(
348+
proto.INT32,
349+
number=3,
350+
)
351+
322352
candidates: MutableSequence["Candidate"] = proto.RepeatedField(
323353
proto.MESSAGE,
324354
number=1,
@@ -329,6 +359,11 @@ class BlockReason(proto.Enum):
329359
number=2,
330360
message=PromptFeedback,
331361
)
362+
usage_metadata: UsageMetadata = proto.Field(
363+
proto.MESSAGE,
364+
number=3,
365+
message=UsageMetadata,
366+
)
332367

333368

334369
class Candidate(proto.Message):
@@ -458,8 +493,9 @@ class EmbedContentRequest(proto.Message):
458493
output_dimensionality (int):
459494
Optional. Optional reduced dimension for the output
460495
embedding. If set, excessive values in the output embedding
461-
are truncated from the end. Supported by
462-
``models/text-embedding-latest``.
496+
are truncated from the end. Supported by newer models since
497+
2024, and the earlier model (``models/embedding-001``)
498+
cannot specify this value.
463499
464500
This field is a member of `oneof`_ ``_output_dimensionality``.
465501
"""
@@ -584,8 +620,12 @@ class CountTokensRequest(proto.Message):
584620
585621
Format: ``models/{model}``
586622
contents (MutableSequence[google.ai.generativelanguage_v1.types.Content]):
587-
Required. The input given to the model as a
588-
prompt.
623+
Optional. The input given to the model as a prompt. This
624+
field is ignored when ``generate_content_request`` is set.
625+
generate_content_request (google.ai.generativelanguage_v1.types.GenerateContentRequest):
626+
Optional. The overall input given to the
627+
model. CountTokens will count prompt, function
628+
calling, etc.
589629
"""
590630

591631
model: str = proto.Field(
@@ -597,6 +637,11 @@ class CountTokensRequest(proto.Message):
597637
number=2,
598638
message=gag_content.Content,
599639
)
640+
generate_content_request: "GenerateContentRequest" = proto.Field(
641+
proto.MESSAGE,
642+
number=3,
643+
message="GenerateContentRequest",
644+
)
600645

601646

602647
class CountTokensResponse(proto.Message):

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/types/safety.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class SafetySetting(proto.Message):
144144
r"""Safety setting, affecting the safety-blocking behavior.
145145
146146
Passing a safety setting for a category changes the allowed
147-
proability that content is blocked.
147+
probability that content is blocked.
148148
149149
Attributes:
150150
category (google.ai.generativelanguage_v1.types.HarmCategory):

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Message,
6161
MessagePrompt,
6262
)
63-
from .types.file import File
63+
from .types.file import File, VideoMetadata
6464
from .types.file_service import (
6565
CreateFileRequest,
6666
CreateFileResponse,
@@ -325,4 +325,5 @@
325325
"UpdateDocumentRequest",
326326
"UpdatePermissionRequest",
327327
"UpdateTunedModelRequest",
328+
"VideoMetadata",
328329
)

0 commit comments

Comments
 (0)