Skip to content

Commit a80babd

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: add live history_config with initial_history_in_client_content
PiperOrigin-RevId: 882741677
1 parent 41b348e commit a80babd

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

google/genai/_live_converters.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,9 @@ def _LiveClientSetup_to_mldev(
584584
if getv(from_object, ['proactivity']) is not None:
585585
setv(to_object, ['proactivity'], getv(from_object, ['proactivity']))
586586

587+
if getv(from_object, ['history_config']) is not None:
588+
setv(to_object, ['historyConfig'], getv(from_object, ['history_config']))
589+
587590
if getv(from_object, ['explicit_vad_signal']) is not None:
588591
raise ValueError(
589592
'explicit_vad_signal parameter is not supported in Gemini API.'
@@ -658,6 +661,9 @@ def _LiveClientSetup_to_vertex(
658661
if getv(from_object, ['proactivity']) is not None:
659662
setv(to_object, ['proactivity'], getv(from_object, ['proactivity']))
660663

664+
if getv(from_object, ['history_config']) is not None:
665+
raise ValueError('history_config parameter is not supported in Vertex AI.')
666+
661667
if getv(from_object, ['explicit_vad_signal']) is not None:
662668
setv(
663669
to_object,
@@ -819,6 +825,13 @@ def _LiveConnectConfig_to_mldev(
819825
getv(from_object, ['proactivity']),
820826
)
821827

828+
if getv(from_object, ['history_config']) is not None:
829+
setv(
830+
parent_object,
831+
['setup', 'historyConfig'],
832+
getv(from_object, ['history_config']),
833+
)
834+
822835
if getv(from_object, ['explicit_vad_signal']) is not None:
823836
raise ValueError(
824837
'explicit_vad_signal parameter is not supported in Gemini API.'
@@ -972,6 +985,9 @@ def _LiveConnectConfig_to_vertex(
972985
getv(from_object, ['proactivity']),
973986
)
974987

988+
if getv(from_object, ['history_config']) is not None:
989+
raise ValueError('history_config parameter is not supported in Vertex AI.')
990+
975991
if getv(from_object, ['explicit_vad_signal']) is not None:
976992
setv(
977993
parent_object,

google/genai/_tokens_converters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ def _LiveConnectConfig_to_mldev(
411411
getv(from_object, ['proactivity']),
412412
)
413413

414+
if getv(from_object, ['history_config']) is not None:
415+
setv(
416+
parent_object,
417+
['setup', 'historyConfig'],
418+
getv(from_object, ['history_config']),
419+
)
420+
414421
if getv(from_object, ['explicit_vad_signal']) is not None:
415422
raise ValueError(
416423
'explicit_vad_signal parameter is not supported in Gemini API.'

google/genai/tests/live/test_live.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,19 @@ async def test_explicit_vad_config(vertexai):
873873
assert result['setup']['explicitVadSignal'] == True
874874

875875

876+
@pytest.mark.asyncio
877+
async def test_history_config():
878+
config_dict = {
879+
'history_config': {'initial_history_in_client_content': True},
880+
}
881+
result = await get_connect_message(
882+
mock_api_client(vertexai=False), model='test_model', config=config_dict
883+
)
884+
assert result['setup']['historyConfig'] == {
885+
'initial_history_in_client_content': True,
886+
}
887+
888+
876889
@pytest.mark.parametrize('vertexai', [True, False])
877890
@pytest.mark.asyncio
878891
async def test_bidi_setup_to_api_with_system_instruction_as_content_type(

google/genai/types.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18037,6 +18037,33 @@ class ProactivityConfigDict(TypedDict, total=False):
1803718037
ProactivityConfigOrDict = Union[ProactivityConfig, ProactivityConfigDict]
1803818038

1803918039

18040+
class HistoryConfig(_common.BaseModel):
18041+
"""Configuration for history exchange between client and server."""
18042+
18043+
initial_history_in_client_content: Optional[bool] = Field(
18044+
default=None,
18045+
description="""If true, after sending `setup_complete`, the server will wait
18046+
and at first process `client_content` messages until `turn_complete` is
18047+
`true`. This initial history will not trigger a model call and
18048+
may end with model content. After `turn_complete` is `true`, the client
18049+
can start the realtime conversation via `realtime_input`.""",
18050+
)
18051+
18052+
18053+
class HistoryConfigDict(TypedDict, total=False):
18054+
"""Configuration for history exchange between client and server."""
18055+
18056+
initial_history_in_client_content: Optional[bool]
18057+
"""If true, after sending `setup_complete`, the server will wait
18058+
and at first process `client_content` messages until `turn_complete` is
18059+
`true`. This initial history will not trigger a model call and
18060+
may end with model content. After `turn_complete` is `true`, the client
18061+
can start the realtime conversation via `realtime_input`."""
18062+
18063+
18064+
HistoryConfigOrDict = Union[HistoryConfig, HistoryConfigDict]
18065+
18066+
1804018067
class AutomaticActivityDetection(_common.BaseModel):
1804118068
"""Configures automatic detection of activity."""
1804218069

@@ -18184,6 +18211,10 @@ class LiveClientSetup(_common.BaseModel):
1818418211
description="""Configures the proactivity of the model. This allows the model to respond proactively to
1818518212
the input and to ignore irrelevant input.""",
1818618213
)
18214+
history_config: Optional[HistoryConfig] = Field(
18215+
default=None,
18216+
description="""Configures the exchange of history between the client and the server.""",
18217+
)
1818718218
explicit_vad_signal: Optional[bool] = Field(
1818818219
default=None,
1818918220
description="""Configures the explicit VAD signal. If enabled, the client will send
@@ -18241,6 +18272,9 @@ class LiveClientSetupDict(TypedDict, total=False):
1824118272
"""Configures the proactivity of the model. This allows the model to respond proactively to
1824218273
the input and to ignore irrelevant input."""
1824318274

18275+
history_config: Optional[HistoryConfigDict]
18276+
"""Configures the exchange of history between the client and the server."""
18277+
1824418278
explicit_vad_signal: Optional[bool]
1824518279
"""Configures the explicit VAD signal. If enabled, the client will send
1824618280
vad_signal to indicate the start and end of speech. This allows the server
@@ -18730,6 +18764,10 @@ class LiveConnectConfig(_common.BaseModel):
1873018764
description="""Configures the proactivity of the model. This allows the model to respond proactively to
1873118765
the input and to ignore irrelevant input.""",
1873218766
)
18767+
history_config: Optional[HistoryConfig] = Field(
18768+
default=None,
18769+
description="""Configures the exchange of history between the client and the server.""",
18770+
)
1873318771
explicit_vad_signal: Optional[bool] = Field(
1873418772
default=None,
1873518773
description="""Configures the explicit VAD signal. If enabled, the client will send
@@ -18838,6 +18876,9 @@ class LiveConnectConfigDict(TypedDict, total=False):
1883818876
"""Configures the proactivity of the model. This allows the model to respond proactively to
1883918877
the input and to ignore irrelevant input."""
1884018878

18879+
history_config: Optional[HistoryConfigDict]
18880+
"""Configures the exchange of history between the client and the server."""
18881+
1884118882
explicit_vad_signal: Optional[bool]
1884218883
"""Configures the explicit VAD signal. If enabled, the client will send
1884318884
vad_signal to indicate the start and end of speech. This allows the server

0 commit comments

Comments
 (0)