Skip to content

Transcript Utils

ghost_brain.utils.transcript

Transcript formatting and Google Cloud Storage upload utilities.

format_transcript_markdown(messages: list[dict[str, Any]], session_id: str | None = None, date: datetime | None = None) -> str

Format a list of conversation messages into a Markdown document.

Includes YAML frontmatter with session and temporal metadata.

Parameters:

Name Type Description Default
messages list[dict[str, Any]]

A list of message dictionaries containing 'role' and 'content' keys.

required
session_id str | None

An optional unique identifier for the conversation session.

None
date datetime | None

An optional timestamp for the conversation.

None

Returns:

Name Type Description
str str

The formatted Markdown string containing the transcript.

format_transcript(context: LLMContext) -> str

Extract and format transcript messages from an LLMContext instance.

Parameters:

Name Type Description Default
context LLMContext

The language model context containing the conversation history.

required

Returns:

Name Type Description
str str

The formatted Markdown string of the conversation.

upload_transcript_to_gcs(bucket_name: str, content: str, blob_path: str, content_type: str = 'text/markdown') -> None

Upload a text payload to a specified Google Cloud Storage bucket.

Parameters:

Name Type Description Default
bucket_name str

The destination GCS bucket name.

required
content str

The text content to upload.

required
blob_path str

The destination path and filename within the bucket.

required
content_type str

The MIME type of the uploaded content.

'text/markdown'