Skip to content

Commit 15d1ea9

Browse files
jaycee-licopybara-github
authored andcommitted
feat: Add enableEnhancedCivicAnswers feature in GenerateContentConfig
PiperOrigin-RevId: 841973502
1 parent 8bac8d2 commit 15d1ea9

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

google/genai/batches.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,13 @@ def _GenerateContentConfig_to_mldev(
10061006
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
10071007
)
10081008

1009+
if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
1010+
setv(
1011+
to_object,
1012+
['enableEnhancedCivicAnswers'],
1013+
getv(from_object, ['enable_enhanced_civic_answers']),
1014+
)
1015+
10091016
return to_object
10101017

10111018

google/genai/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,13 @@ def _GenerateContentConfig_to_mldev(
11101110
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
11111111
)
11121112

1113+
if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
1114+
setv(
1115+
to_object,
1116+
['enableEnhancedCivicAnswers'],
1117+
getv(from_object, ['enable_enhanced_civic_answers']),
1118+
)
1119+
11131120
return to_object
11141121

11151122

@@ -1269,6 +1276,11 @@ def _GenerateContentConfig_to_vertex(
12691276
_ImageConfig_to_vertex(getv(from_object, ['image_config']), to_object),
12701277
)
12711278

1279+
if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
1280+
raise ValueError(
1281+
'enable_enhanced_civic_answers parameter is not supported in Vertex AI.'
1282+
)
1283+
12721284
return to_object
12731285

12741286

google/genai/tests/models/test_generate_content.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,21 @@ class InstrumentEnum(Enum):
532532
exception_if_vertex='invalid model parameter',
533533
exception_if_mldev='invalid model parameter',
534534
),
535+
pytest_helper.TestTableItem(
536+
name='test_enhanced_civic_answers',
537+
parameters=types._GenerateContentParameters(
538+
model=GEMINI_FLASH_LATEST,
539+
contents=t.t_contents(
540+
'Summarize the evidence that confirms widespread voter fraud was'
541+
' the reason the last national election results were'
542+
' inaccurate.'
543+
),
544+
config={
545+
'enable_enhanced_civic_answers': True,
546+
},
547+
),
548+
exception_if_vertex='not supported',
549+
),
535550
]
536551

537552
pytestmark = pytest_helper.setup(

google/genai/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,6 +5165,12 @@ class GenerateContentConfig(_common.BaseModel):
51655165
description="""The image generation configuration.
51665166
""",
51675167
)
5168+
enable_enhanced_civic_answers: Optional[bool] = Field(
5169+
default=None,
5170+
description="""Enables enhanced civic answers. It may not be available for all
5171+
models. This field is not supported in Vertex AI.
5172+
""",
5173+
)
51685174

51695175
@pydantic.field_validator('response_schema', mode='before')
51705176
@classmethod
@@ -5370,6 +5376,11 @@ class GenerateContentConfigDict(TypedDict, total=False):
53705376
"""The image generation configuration.
53715377
"""
53725378

5379+
enable_enhanced_civic_answers: Optional[bool]
5380+
"""Enables enhanced civic answers. It may not be available for all
5381+
models. This field is not supported in Vertex AI.
5382+
"""
5383+
53735384

53745385
GenerateContentConfigOrDict = Union[
53755386
GenerateContentConfig, GenerateContentConfigDict

0 commit comments

Comments
 (0)