Class: Ollama::Handlers::Markdown

Inherits:
Object
  • Object
show all
Includes:
Concern, Term::ANSIColor
Defined in:
lib/ollama/handlers/markdown.rb

Instance Attribute Summary

Attributes included from Concern

#output, #result

Instance Method Summary collapse

Methods included from Concern

#to_proc

Constructor Details

#initialize(output: $stdout, stream: true) ⇒ Markdown

Returns a new instance of Markdown.



8
9
10
11
12
13
# File 'lib/ollama/handlers/markdown.rb', line 8

def initialize(output: $stdout, stream: true)
  super(output:)
  @stream      = stream
  @output.sync = @stream
  @content     = ''
end

Instance Method Details

#call(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ollama/handlers/markdown.rb', line 15

def call(response)
  if content = response.response || response.message&.content
    if @stream
      @content << content
      markdown_content = Kramdown::ANSI.parse(@content)
      @output.print clear_screen, move_home, markdown_content
    else
      markdown_content = Kramdown::ANSI.parse(content)
      @output.print markdown_content
    end
  end
  self
end