Skip to content

Commit 3ad30a5

Browse files
hangfeicopybara-github
authored andcommitted
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
1 parent 0ac35b2 commit 3ad30a5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/google/adk/sessions/database_session_service.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ class StorageEvent(Base):
271271
)
272272
error_message: Mapped[str] = mapped_column(String(1024), nullable=True)
273273
interrupted: Mapped[bool] = mapped_column(Boolean, nullable=True)
274+
input_transcription: Mapped[dict[str, Any]] = mapped_column(
275+
DynamicJSON, nullable=True
276+
)
277+
output_transcription: Mapped[dict[str, Any]] = mapped_column(
278+
DynamicJSON, nullable=True
279+
)
274280

275281
storage_session: Mapped[StorageSession] = relationship(
276282
"StorageSession",
@@ -337,6 +343,14 @@ def from_event(cls, session: Session, event: Event) -> StorageEvent:
337343
storage_event.citation_metadata = event.citation_metadata.model_dump(
338344
exclude_none=True, mode="json"
339345
)
346+
if event.input_transcription:
347+
storage_event.input_transcription = event.input_transcription.model_dump(
348+
exclude_none=True, mode="json"
349+
)
350+
if event.output_transcription:
351+
storage_event.output_transcription = (
352+
event.output_transcription.model_dump(exclude_none=True, mode="json")
353+
)
340354
return storage_event
341355

342356
def to_event(self) -> Event:
@@ -366,6 +380,12 @@ def to_event(self) -> Event:
366380
citation_metadata=_session_util.decode_model(
367381
self.citation_metadata, types.CitationMetadata
368382
),
383+
input_transcription=_session_util.decode_model(
384+
self.input_transcription, types.Transcription
385+
),
386+
output_transcription=_session_util.decode_model(
387+
self.output_transcription, types.Transcription
388+
),
369389
)
370390

371391

tests/unittests/sessions/test_session_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,14 @@ async def test_append_event_complete(service_type, tmp_path):
512512
),
513513
citation_metadata=types.CitationMetadata(),
514514
custom_metadata={'custom_key': 'custom_value'},
515+
input_transcription=types.Transcription(
516+
text='input transcription',
517+
finished=True,
518+
),
519+
output_transcription=types.Transcription(
520+
text='output transcription',
521+
finished=True,
522+
),
515523
)
516524
await session_service.append_event(session=session, event=event)
517525

0 commit comments

Comments
 (0)