Class: LLM::Repl::Transcript
- Inherits:
-
Object
- Object
- LLM::Repl::Transcript
- Defined in:
- lib/llm/repl/transcript.rb
Overview
This class maintains conversation state that includes the conversation itself, and metadata associated with the conversation.
Internally it maintains an array where each element represents a row, and each element in a row is a Hash that describes a piece of text and any styles that might be applied to it by the UI thread.
It also maintains a cursor that tracks the active row by its index number. The streaming path reuses a single row by overwriting its contents repeatedly.
Constant Summary collapse
- WIDTH =
80
Instance Method Summary collapse
-
#finish ⇒ void
Finish the transcript.
- #initialize ⇒ LLM::Repl::Transcript constructor
-
#markdown(chars, method: :append) ⇒ void
Appends Markdown to the transcript.
- #scroll_down ⇒ void
- #scroll_up(height) ⇒ void
-
#start ⇒ void
Start the transcript.
- #visible(height) ⇒ Array<String>
- #write(chars, attrs = nil, method: :append) ⇒ void
Constructor Details
#initialize ⇒ LLM::Repl::Transcript
22 23 24 25 26 27 |
# File 'lib/llm/repl/transcript.rb', line 22 def initialize @rows = [[]] @cursor = nil @snapshot = nil @offset = 0 end |
Instance Method Details
#finish ⇒ void
This method returns an undefined value.
Finish the transcript.
60 61 62 63 |
# File 'lib/llm/repl/transcript.rb', line 60 def finish @cursor = nil @snapshot = nil end |
#markdown(chars, method: :append) ⇒ void
This method returns an undefined value.
Appends Markdown to the transcript.
44 45 46 47 |
# File 'lib/llm/repl/transcript.rb', line 44 def markdown(chars, method: :append) chunks = LLM::Repl::Markdown.new(chars).ast self.method(method).call(chunks) end |
#scroll_down ⇒ void
This method returns an undefined value.
74 75 76 |
# File 'lib/llm/repl/transcript.rb', line 74 def scroll_down @offset = [@offset - 1, 0].max end |
#scroll_up(height) ⇒ void
This method returns an undefined value.
67 68 69 70 |
# File 'lib/llm/repl/transcript.rb', line 67 def scroll_up(height) max = [rows.size - height, 0].max @offset = [@offset + 1, max].min end |
#start ⇒ void
This method returns an undefined value.
Start the transcript.
52 53 54 55 |
# File 'lib/llm/repl/transcript.rb', line 52 def start @cursor = @rows.size - 1 @snapshot = @rows.map(&:dup) end |
#visible(height) ⇒ Array<String>
81 82 83 84 85 86 |
# File 'lib/llm/repl/transcript.rb', line 81 def visible(height) all = rows last = all.size - 1 - @offset first = [last - height + 1, 0].max all[first..last] || [] end |
#write(chars, attrs = nil, method: :append) ⇒ void
This method returns an undefined value.
34 35 36 37 |
# File 'lib/llm/repl/transcript.rb', line 34 def write(chars, attrs = nil, method: :append) chunks = [{text: chars.to_s, attrs:}.compact] self.method(method).call(chunks) end |