Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Progress Bar

From Leeroopedia
Knowledge Sources
Domains CLI, Progress
Last Updated 2025-02-15 00:00 GMT

Overview

Terminal progress bar implementation with percentage, transfer rate, ETA, and visual block display for tracking byte-based operations like model downloads.

Description

The Bar struct tracks current/max values along with start/stop times and maintains a sliding window of timestamped bucket samples (max 10, throttled to 1 per second) for calculating smooth transfer rates. NewBar initializes a bar with a message, max value, and initial value. The String() method renders the bar to fit the terminal width (via term.GetSize), composing: a message prefix, percentage indicator, a visual block bar using Unicode characters, current/total byte counts (via format.HumanBytes), transfer rate in bytes/s, and estimated time remaining computed from the sliding window rate. The Set method updates the current value and appends rate samples. Rate calculation uses the sliding window during active transfer and overall elapsed time once stopped. formatDuration limits time rendering to 2 units, capping at "99h+".

Usage

Used by the progress package to display download/upload progress for model layers during ollama pull and ollama push operations.

Code Reference

Source Location

  • Repository: Ollama
  • File: progress/bar.go
  • Lines: 1-216

Signature

type Bar struct {
    message      string
    messageWidth int
    maxValue     int64
    initialValue int64
    currentValue int64
    started      time.Time
    stopped      time.Time
    maxBuckets   int
    buckets      []bucket
}

func NewBar(message string, maxValue, initialValue int64) *Bar
func (b *Bar) String() string
func (b *Bar) Set(value int64)

Import

import "github.com/ollama/ollama/progress"

I/O Contract

Inputs

Name Type Required Description
message string Yes Label text displayed before the bar
maxValue int64 Yes Total bytes for the operation
initialValue int64 Yes Starting byte count (for resumed downloads)
value int64 Yes Current byte count (via Set method)

Outputs

Name Type Description
rendered string Terminal-width formatted progress bar string

Usage Examples

import "github.com/ollama/ollama/progress"

// Create a progress bar for a 1GB download
bar := progress.NewBar("pulling model", 1000000000, 0)

// Update as bytes are received
bar.Set(250000000)  // 25%
fmt.Println(bar.String())
// Output: pulling model  25% ▕████                ▏ 250 MB/  1 GB  50 MB/s  15s

bar.Set(1000000000) // 100%
fmt.Println(bar.String())
// Output: pulling model 100% ▕████████████████████▏   1 GB

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment