Class: Ollama::Handlers::Progress

Inherits:
Object
  • Object
show all
Includes:
Concern, Term::ANSIColor
Defined in:
lib/ollama/handlers/progress.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) ⇒ Progress

Returns a new instance of Progress.



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

def initialize(output: $stdout)
  super
  @current     = 0
  @total       = nil
  @last_status = nil
end

Instance Method Details

#call(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ollama/handlers/progress.rb', line 15

def call(response)
  infobar.display.output = @output
  if status = response.status
    infobar.label = status
  end
  if response.total && response.completed
    if !@last_status or @last_status != status
      @last_status and infobar.newline
      @last_status = status
      @current = 0
      @total = response.total
      infobar.counter.reset(total: @total, current: @current)
    end
    infobar.counter.progress(by: response.completed - @current)
    @current = response.completed
    infobar.update(
      message: message(response.completed, response.total),
      force: true
    )
  end
  if error = response.error
    infobar.puts bold { "Error: " } + red { error }
  end
  self
end