fix: Add transcription fields to session events

This change introduces `input_transcription` and `output_transcription` fields to session events, enabling the storage and retrieval of transcription data in both the database and Vertex AI session services.

Closes #3172

Co-authored-by: Hangfei Lin <hangfei@google.com>
PiperOrigin-RevId: 834366848
This commit is contained in:
Hangfei Lin
2025-11-19 11:08:38 -08:00
committed by Copybara-Service
parent 0ac35b23dc
commit 3ad30a58f9
2 changed files with 28 additions and 0 deletions
@@ -271,6 +271,12 @@ class StorageEvent(Base):
)
error_message: Mapped[str] = mapped_column(String(1024), nullable=True)
interrupted: Mapped[bool] = mapped_column(Boolean, nullable=True)
input_transcription: Mapped[dict[str, Any]] = mapped_column(
DynamicJSON, nullable=True
)
output_transcription: Mapped[dict[str, Any]] = mapped_column(
DynamicJSON, nullable=True
)
storage_session: Mapped[StorageSession] = relationship(
"StorageSession",
@@ -337,6 +343,14 @@ class StorageEvent(Base):
storage_event.citation_metadata = event.citation_metadata.model_dump(
exclude_none=True, mode="json"
)
if event.input_transcription:
storage_event.input_transcription = event.input_transcription.model_dump(
exclude_none=True, mode="json"
)
if event.output_transcription:
storage_event.output_transcription = (
event.output_transcription.model_dump(exclude_none=True, mode="json")
)
return storage_event
def to_event(self) -> Event:
@@ -366,6 +380,12 @@ class StorageEvent(Base):
citation_metadata=_session_util.decode_model(
self.citation_metadata, types.CitationMetadata
),
input_transcription=_session_util.decode_model(
self.input_transcription, types.Transcription
),
output_transcription=_session_util.decode_model(
self.output_transcription, types.Transcription
),
)
@@ -512,6 +512,14 @@ async def test_append_event_complete(service_type, tmp_path):
),
citation_metadata=types.CitationMetadata(),
custom_metadata={'custom_key': 'custom_value'},
input_transcription=types.Transcription(
text='input transcription',
finished=True,
),
output_transcription=types.Transcription(
text='output transcription',
finished=True,
),
)
await session_service.append_event(session=session, event=event)