Skip to content

Commit 7dcc969

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: Support Gemini batch inline request's metadata and add test coverage to safety setting
PiperOrigin-RevId: 817811792
1 parent 3871aac commit 7dcc969

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

google/genai/batches.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ def _InlinedRequest_to_mldev(
10711071
],
10721072
)
10731073

1074+
if getv(from_object, ['metadata']) is not None:
1075+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
1076+
10741077
if getv(from_object, ['config']) is not None:
10751078
setv(
10761079
to_object,

google/genai/tests/batches/test_create_with_inlined_requests.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,35 @@
2626
from ... import types
2727
from .. import pytest_helper
2828

29-
_GEMINI_MODEL = 'gemini-1.5-flash-002'
29+
_GEMINI_MODEL = 'gemini-2.5-flash-lite'
3030
_DISPLAY_NAME = 'test_batch'
3131

32-
_MLDEV_GEMINI_MODEL = 'gemini-2.0-flash'
32+
_MLDEV_GEMINI_MODEL = 'gemini-2.5-flash'
33+
34+
_SAFETY_SETTINGS = [
35+
{
36+
'category': 'HARM_CATEGORY_HATE_SPEECH',
37+
'threshold': 'BLOCK_ONLY_HIGH',
38+
},
39+
{
40+
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
41+
'threshold': 'BLOCK_LOW_AND_ABOVE',
42+
},
43+
]
44+
3345
_INLINED_REQUEST = {
3446
'contents': [{
3547
'parts': [{
3648
'text': 'Hello!',
3749
}],
3850
'role': 'user',
3951
}],
52+
'metadata': {
53+
'key': 'request-1',
54+
},
55+
'config': {
56+
'safety_settings': _SAFETY_SETTINGS,
57+
},
4058
}
4159
_INLINED_TEXT_REQUEST_UNION = {
4260
'contents': [{

google/genai/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11766,6 +11766,10 @@ class InlinedRequest(_common.BaseModel):
1176611766
description="""Content of the request.
1176711767
""",
1176811768
)
11769+
metadata: Optional[dict[str, str]] = Field(
11770+
default=None,
11771+
description="""The metadata to be associated with the request.""",
11772+
)
1176911773
config: Optional[GenerateContentConfig] = Field(
1177011774
default=None,
1177111775
description="""Configuration that contains optional model parameters.
@@ -11784,6 +11788,9 @@ class InlinedRequestDict(TypedDict, total=False):
1178411788
"""Content of the request.
1178511789
"""
1178611790

11791+
metadata: Optional[dict[str, str]]
11792+
"""The metadata to be associated with the request."""
11793+
1178711794
config: Optional[GenerateContentConfigDict]
1178811795
"""Configuration that contains optional model parameters.
1178911796
"""

0 commit comments

Comments
 (0)