Sha256: af0ee7f695971840445ad540f9d30bf89af3c15edfd0c3cc4e3a9d162d144c1d

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

require 'infobar'
require 'tins/unit'

class Ollama::Handlers::Progress
  include Ollama::Handlers::Concern
  include Term::ANSIColor

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

  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

  private

  def message(current, total)
    progress = '%s/%s' % [ current, total ].map {
      Tins::Unit.format(_1, format: '%.2f %U')
    }
    '%l ' + progress + ' in %te, ETA %e @%E'
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ollama-ruby-0.12.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.11.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.10.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.9.3 lib/ollama/handlers/progress.rb
ollama-ruby-0.9.2 lib/ollama/handlers/progress.rb
ollama-ruby-0.9.1 lib/ollama/handlers/progress.rb
ollama-ruby-0.9.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.8.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.7.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.6.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.5.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.4.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.3.2 lib/ollama/handlers/progress.rb
ollama-ruby-0.3.1 lib/ollama/handlers/progress.rb
ollama-ruby-0.3.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.2.0 lib/ollama/handlers/progress.rb
ollama-ruby-0.1.0 lib/ollama/handlers/progress.rb