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
- #visible(height) ⇒ Array<String>
- #write(chars, attrs = nil, method: :append)
-
#markdown(chars, method: :append)
Appends Markdown to the transcript.
-
#start
Start the transcript.
-
#finish
Finish the transcript.
- #scroll_up(height)
- #scroll_down
- #scroll_to_bottom
- #initialize ⇒ LLM::Repl::Transcript constructor
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
#visible(height) ⇒ Array<String>
87 88 89 90 91 92 |
# File 'lib/llm/repl/transcript.rb', line 87 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)
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 |
#markdown(chars, method: :append)
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 |
#start
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 |
#finish
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 |
#scroll_up(height)
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 |
#scroll_down
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_to_bottom
This method returns an undefined value.
80 81 82 |
# File 'lib/llm/repl/transcript.rb', line 80 def scroll_to_bottom @offset = 0 end |