Constructs a formatted transcript string from user and assistant messages.
(chat_events: list[ReturnChatEvent])
| 21 | |
| 22 | |
| 23 | def construct_transcript(chat_events: list[ReturnChatEvent]) -> str: |
| 24 | """Constructs a formatted transcript string from user and assistant messages.""" |
| 25 | relevant_events = [e for e in chat_events if e.type in ("USER_MESSAGE", "AGENT_MESSAGE")] |
| 26 | |
| 27 | lines: list[str] = [] |
| 28 | for event in relevant_events: |
| 29 | role = "User" if event.role == "USER" else "Assistant" |
| 30 | timestamp = event.timestamp |
| 31 | dt = datetime.fromtimestamp(timestamp / 1000.0) |
| 32 | readable_time = dt.strftime("%Y-%m-%d %H:%M:%S") |
| 33 | lines.append(f"[{readable_time}] {role}: {event.message_text}") |
| 34 | |
| 35 | return "\n".join(lines) |
| 36 | |
| 37 | |
| 38 | def save_transcript_to_file(transcript: str, chat_id: str) -> None: |
no outgoing calls
no test coverage detected