File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -795,8 +795,8 @@ def _is_request_input_event(event: Event) -> bool:
795795 return _is_function_call_event (event , REQUEST_INPUT_FUNCTION_CALL_NAME )
796796
797797
798- def _is_live_model_audio_event_with_inline_data (event : Event ) -> bool :
799- """Check if the event is a live/bidi audio event with inline data.
798+ def _is_live_model_media_event_with_inline_data (event : Event ) -> bool :
799+ """Check if the event is a live/bidi media event (audio, video, image) with inline data.
800800
801801 There are two possible cases and we only care about the second case:
802802 content=Content(
@@ -826,12 +826,14 @@ def _is_live_model_audio_event_with_inline_data(event: Event) -> bool:
826826 if not event .content or not event .content .parts :
827827 return False
828828 for part in event .content .parts :
829- if (
830- part .inline_data
831- and part .inline_data .mime_type
832- and part .inline_data .mime_type .startswith ('audio/' )
833- ):
834- return True
829+ if part .inline_data and part .inline_data .mime_type :
830+ mime = part .inline_data .mime_type .lower ()
831+ if (
832+ mime .startswith ('audio/' )
833+ or mime .startswith ('video/' )
834+ or mime .startswith ('image/' )
835+ ):
836+ return True
835837 return False
836838
837839
Original file line number Diff line number Diff line change @@ -786,17 +786,17 @@ async def _compute_artifact_delta_for_rewind(
786786
787787 def _should_append_event (self , event : Event , is_live_call : bool ) -> bool :
788788 """Checks if an event should be appended to the session."""
789- # Don't append audio response from model in live mode to session.
789+ # Don't append media ( audio/video/image) response from model in live mode to session.
790790 # The data is appended to artifacts with a reference in file_data in the
791- # event.
791+ # event if save_live_blob is True .
792792 # We should append non-partial events only.For example, non-finished(partial)
793793 # transcription events should not be appended.
794794 # Function call and function response events should be appended.
795795 # Other control events should be appended.
796- if is_live_call and contents ._is_live_model_audio_event_with_inline_data (
796+ if is_live_call and contents ._is_live_model_media_event_with_inline_data (
797797 event
798798 ):
799- # We don't append live model audio events with inline data to avoid
799+ # We don't append live model media events with inline data to avoid
800800 # storing large blobs in the session. However, events with file_data
801801 # (references to artifacts) should be appended.
802802 return False
Original file line number Diff line number Diff line change @@ -1188,6 +1188,35 @@ def test_should_append_event_other_event(self):
11881188 )
11891189 assert self .runner ._should_append_event (event , is_live_call = True ) is True
11901190
1191+ def test_should_not_append_event_live_model_video (self ):
1192+ event = Event (
1193+ invocation_id = "inv1" ,
1194+ author = "model" ,
1195+ content = types .Content (
1196+ parts = [
1197+ types .Part (
1198+ inline_data = types .Blob (data = b"123" , mime_type = "video/mp4" )
1199+ )
1200+ ]
1201+ ),
1202+ )
1203+ assert self .runner ._should_append_event (event , is_live_call = True ) is False
1204+
1205+ def test_should_append_event_non_live_model_video (self ):
1206+ event = Event (
1207+ invocation_id = "inv1" ,
1208+ author = "model" ,
1209+ content = types .Content (
1210+ parts = [
1211+ types .Part (
1212+ inline_data = types .Blob (data = b"123" , mime_type = "video/mp4" )
1213+ )
1214+ ]
1215+ ),
1216+ )
1217+ assert self .runner ._should_append_event (event , is_live_call = False ) is True
1218+
1219+
11911220
11921221@pytest .fixture
11931222def user_agent_module (tmp_path , monkeypatch ):
You can’t perform that action at this time.
0 commit comments