Class: Ollama::Handlers::Progress
- Inherits:
- 
      Object
      
        - Object
- Ollama::Handlers::Progress
 
- Includes:
- Concern, Term::ANSIColor
- Defined in:
- lib/ollama/handlers/progress.rb
Overview
A handler that displays progress information for streaming operations.
This class is designed to provide visual feedback during long-running operations such as model creation, pulling, or pushing. It uses a progress bar to show the current status and estimated time remaining, making it easier to monitor the progress of these operations in terminal environments.
Instance Attribute Summary
Attributes included from Concern
Instance Method Summary collapse
- 
  
    
      #call(response)  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    The call method processes a response by updating progress information and displaying status updates. 
- 
  
    
      #initialize(output: $stdout)  ⇒ Progress 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    The initialize method sets up a new handler instance with the specified output destination and initializes internal state for progress tracking. 
- 
  
    
      #message(current, total)  ⇒ String 
    
    
  
  
  
  
  private
  
  
  
  
    The message method formats progress information into a descriptive string. 
Methods included from Concern
Constructor Details
#initialize(output: $stdout) ⇒ Progress
The initialize method sets up a new handler instance with the specified output destination and initializes internal state for progress tracking.
| 21 22 23 24 25 26 | # File 'lib/ollama/handlers/progress.rb', line 21 def initialize(output: $stdout) super @current = 0 @total = nil @last_status = nil end | 
Instance Method Details
#call(response) ⇒ self
The call method processes a response by updating progress information and displaying status updates.
This method handles the display of progress information for streaming operations by updating the progress bar with current completion status, handling status changes, and displaying any error messages that occur during the operation. It manages internal state to track progress and ensures proper formatting of output.
progress information
response
| 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # File 'lib/ollama/handlers/progress.rb', line 42 def call(response) .display.output = @output if status = response.status .label = status end if response.total && response.completed if !@last_status or @last_status != status @last_status and .newline @last_status = status @current = 0 @total = response.total .counter.reset(total: @total, current: @current) end .counter.progress(by: response.completed - @current) @current = response.completed .update( message: (response.completed, response.total), force: true ) end if error = response.error .puts bold { "Error: " } + red { error } end self end | 
#message(current, total) ⇒ String (private)
The message method formats progress information into a descriptive string.
This method takes current and total values and creates a formatted progress message that includes the current value, total value, time elapsed, estimated time remaining, and the current rate of progress.
| 81 82 83 84 85 86 | # File 'lib/ollama/handlers/progress.rb', line 81 def (current, total) progress = '%s/%s' % [ current, total ].map { Tins::Unit.format(_1, format: '%.2f %U') } '%l ' + progress + ' in %te, ETA %e @%E' end |