Skip to content

Commit a57d2f9

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add translation_config SDK support for GEAP.
PiperOrigin-RevId: 971644297
1 parent 2cc99a9 commit a57d2f9

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

google/genai/_live_converters.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,10 @@ def _LiveConnectConfig_to_vertex(
11541154
)
11551155

11561156
if getv(from_object, ['translation_config']) is not None:
1157-
raise ValueError(
1158-
'translation_config parameter is only supported in Gemini Developer API'
1159-
' mode, not in Gemini Enterprise Agent Platform mode.'
1157+
setv(
1158+
parent_object,
1159+
['setup', 'generationConfig', 'translationConfig'],
1160+
getv(from_object, ['translation_config']),
11601161
)
11611162

11621163
return to_object

google/genai/tests/live/test_live.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,12 +1624,26 @@ async def test_bidi_setup_to_api_with_translation_config(vertexai):
16241624
},
16251625
}
16261626

1627-
with pytest_helper.exception_if_vertex(api_client, ValueError):
1628-
result = await get_connect_message(
1629-
api_client=api_client, model='test_model', config=config_dict
1630-
)
1627+
result = await get_connect_message(
1628+
api_client=api_client, model='test_model', config=config_dict
1629+
)
16311630

1632-
if not vertexai:
1631+
if vertexai:
1632+
expected_result = {
1633+
'setup': {
1634+
'model': (
1635+
'projects/test_project/locations/us-central1/publishers/google/models/test_model'
1636+
),
1637+
'generationConfig': {
1638+
'responseModalities': ['AUDIO'],
1639+
'translationConfig': {
1640+
'echoTargetLanguage': True,
1641+
'targetLanguageCode': 'es',
1642+
},
1643+
},
1644+
}
1645+
}
1646+
else:
16331647
expected_result = {
16341648
'setup': {
16351649
'model': 'models/test_model',
@@ -1641,7 +1655,7 @@ async def test_bidi_setup_to_api_with_translation_config(vertexai):
16411655
},
16421656
}
16431657
}
1644-
assert result == expected_result
1658+
assert result == expected_result
16451659

16461660
# Test 2: Config defined using types.LiveConnectConfig.
16471661
config = types.LiveConnectConfig(
@@ -1651,13 +1665,11 @@ async def test_bidi_setup_to_api_with_translation_config(vertexai):
16511665
)
16521666
)
16531667

1654-
with pytest_helper.exception_if_vertex(api_client, ValueError):
1655-
result = await get_connect_message(
1656-
api_client=api_client, model='test_model', config=config
1657-
)
1668+
result = await get_connect_message(
1669+
api_client=api_client, model='test_model', config=config
1670+
)
16581671

1659-
if not vertexai:
1660-
assert result == expected_result
1672+
assert result == expected_result
16611673

16621674

16631675
@pytest.mark.parametrize('vertexai', [True, False])
@@ -2303,4 +2315,3 @@ async def test_bidi_setup_replicated_voice_config_with_consent(vertexai):
23032315
replicated_sig['voice_consent_signature'].get('signature')
23042316
== 'test_sig_abc123'
23052317
)
2306-

google/genai/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11395,22 +11395,22 @@ class TranslationConfig(_common.BaseModel):
1139511395

1139611396
echo_target_language: Optional[bool] = Field(
1139711397
default=None,
11398-
description="""Optional. If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language.""",
11398+
description="""If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language.""",
1139911399
)
1140011400
target_language_code: Optional[str] = Field(
1140111401
default=None,
11402-
description="""Required. The target language for translation. Supported values are BCP-47 language codes (e.g. "en", "es", "fr").""",
11402+
description="""The target language for translation. Supported values are BCP-47 language codes (e.g. "en", "es", "fr").""",
1140311403
)
1140411404

1140511405

1140611406
class TranslationConfigDict(TypedDict, total=False):
1140711407
"""Config for stream translation."""
1140811408

1140911409
echo_target_language: Optional[bool]
11410-
"""Optional. If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language."""
11410+
"""If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language."""
1141111411

1141211412
target_language_code: Optional[str]
11413-
"""Required. The target language for translation. Supported values are BCP-47 language codes (e.g. "en", "es", "fr")."""
11413+
"""The target language for translation. Supported values are BCP-47 language codes (e.g. "en", "es", "fr")."""
1141411414

1141511415

1141611416
TranslationConfigOrDict = Union[TranslationConfig, TranslationConfigDict]

0 commit comments

Comments
 (0)