Transcript
A linear history of entries that reflect an interaction with a session.
Declaration
struct TranscriptMentioned in
Overview
Use a Transcript to visualize previous instructions, prompts and model responses. If you use tool calling, a Transcript includes a history of tool calls and their results.
struct HistoryView: View {
let session: LanguageModelSession
var body: some View {
ScrollView {
ForEach(session.transcript) { entry in
switch entry {
case let .instructions(instructions):
MyInstructionsView(instructions)
case let .prompt(prompt)
MyPromptView(prompt)
case let .toolCalls(toolCalls):
MyToolCallsView(toolCalls)
case let .toolOutput(toolOutput):
MyToolOutputView(toolOutput)
case let .response(response):
MyResponseView(response)
}
}
}
}
}When you create a new LanguageModelSession it doesn’t contain the state of a previous session. You can initialize a new session with a list of entries you get from a session transcript:
// Create a new session with the first and last entries from a previous session.
func newContextualSession(with originalSession: LanguageModelSession) -> LanguageModelSession {
let allEntries = originalSession.transcript
// Collect the entries to keep from the original session.
let entries = [allEntries.first, allEntries.last].compactMap { $0 }
let transcript = Transcript(entries: entries)
// Create a new session with the result and preload the session resources.
var session = LanguageModelSession(transcript: transcript)
session.prewarm()
return session
}