ollama

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "http://localhost:11434"

DefaultBaseURL is the default ollama API endpoint.

View Source
const HuggingFaceAPIURL = "https://huggingface.co/api/models"

HuggingFaceAPIURL is the default HuggingFace Hub API base URL.

View Source
const SWEBenchCacheTTL = 6 * time.Hour

FetchSWEBenchScores fetches the SWE-bench Verified leaderboard and returns the best score per model. Keys include lowercased model tags, HuggingFace repo paths extracted from URL tags, and model name parts.

All entries are included (not filtered by os_model) so that HF repo ID matching can find scores for any model. SWEBenchCacheTTL is the on-disk cache lifetime for SWE-bench leaderboard data.

View Source
const SWEBenchURL = "https://raw.githubusercontent.com/SWE-bench/swe-bench.github.io/master/data/leaderboards.json"

SWEBenchURL is the default URL for SWE-bench leaderboard data.

Variables

This section is empty.

Functions

func CheckHardware

func CheckHardware(parameterSize string, systemRAMGB float64) (bool, float64)

CheckHardware checks if a model with given parameter size fits in available RAM. Returns (ok, neededGB). If parameter size is unknown, returns (true, 0).

func CheckHardwareSafe added in v0.5.0

func CheckHardwareSafe(parameterSize string, systemRAMGB float64) (bool, float64)

CheckHardwareSafe checks if a model fits within 75% of available RAM. Uses a conservative threshold: a 48 GB model won't run on 48 GB RAM. Returns (ok, neededGB). If parameter size is unknown, returns (true, 0).

func ComputeRecommendedScore added in v0.5.0

func ComputeRecommendedScore(swe, speedTPM, ramFit float64) float64

ComputeRecommendedScore computes the composite ranking score. swe: SWE-bench %, speedTPM: tokens/min, ramFit: graduated multiplier (0–1).

SWE quality dominates (90% weight). Speed contributes a small bonus (up to 5 points) so that among models with equal SWE scores, faster wins — but a model with 8% lower SWE cannot overcome a 3-point speed bonus.

func Detect

func Detect(ctx context.Context, baseURL string) bool

Detect checks if ollama is reachable at the given base URL.

func DetectAppleSiliconBandwidthGBs added in v0.5.0

func DetectAppleSiliconBandwidthGBs() float64

DetectAppleSiliconBandwidthGBs returns 0 on Linux (not Apple Silicon).

func EstimateCloudSpeedTPM added in v0.5.0

func EstimateCloudSpeedTPM(pricePerToken float64) float64

EstimateCloudSpeedTPM estimates cloud model speed (tokens/min) from completion price per token (USD). Cheaper models are typically faster.

func EstimateLocalSpeedTPM added in v0.5.0

func EstimateLocalSpeedTPM(paramsB, bandwidthGBs float64) float64

EstimateLocalSpeedTPM estimates local model speed (tokens/min).

When bandwidthGBs > 0 (Apple Silicon detected), uses the physics formula:

speed = bandwidth / model_weight_bytes_per_token

Q4_K_M quantization ≈ 0.5625 bytes/param (4.5 bits/param). Capped at 9000 T/min (150 tok/s) — the compute-bound ceiling for tiny models.

When bandwidthGBs == 0, falls back to generic tier estimates for average consumer GPU hardware.

func EstimateRAMGB

func EstimateRAMGB(paramsB float64) float64

EstimateRAMGB estimates RAM needed (GB) for a Q4_K_M quantized model. Formula: params_in_billions * 0.55 + 2 GB overhead. Returns 0 if paramsB is 0.

func FetchSWEBenchScores

func FetchSWEBenchScores(ctx context.Context, url string) (map[string]float64, error)

func FindSWEScore

func FindSWEScore(scores map[string]float64, hfRepoID string) (float64, bool)

FindSWEScore finds the best SWE-bench score for a HuggingFace repo ID. It checks the scores map using the full repo ID, the model name part, and case-insensitive variants.

func FormatActiveTOMLSnippet added in v0.3.0

func FormatActiveTOMLSnippet(ranked []RankedModel) string

FormatActiveTOMLSnippet generates an active (uncommented) TOML snippet for devcell.toml from ranked models. The #1 ranked model becomes the default.

func FormatTOMLSnippet

func FormatTOMLSnippet(ranked []RankedModel) string

FormatTOMLSnippet generates a commented-out TOML snippet for devcell.toml from ranked models.

func GetSystemRAMGB

func GetSystemRAMGB() float64

GetSystemRAMGB returns total system RAM in GB (Linux).

func InferTaskLabel

func InferTaskLabel(info HFModelInfo, ollamaName string) string

InferTaskLabel returns a short human-readable label for what a model is good at, based on HuggingFace tags and model name.

func MatchModelScore

func MatchModelScore(ollamaName string, scores map[string]float64) (float64, bool)

MatchModelScore finds the SWE-bench score for an ollama model name. It strips the :size suffix and does case-insensitive matching.

func ModelFamily

func ModelFamily(name string) string

ModelFamily strips the :tag suffix from an ollama model name (exported). "deepseek-r1:32b" → "deepseek-r1", "codellama:latest" → "codellama".

func NormalizeCloudID added in v0.5.0

func NormalizeCloudID(id string) string

NormalizeCloudID converts an OpenRouter model ID to a SWE-bench-comparable key. Strips provider prefix, converts dots to dashes, strips :variant suffixes. "anthropic/claude-opus-4.6" → "claude-opus-4-6"

func ParseAppleSiliconBandwidth added in v0.5.0

func ParseAppleSiliconBandwidth(brandString string) float64

ParseAppleSiliconBandwidth parses a CPU brand string like "Apple M4 Pro" and returns the corresponding memory bandwidth in GB/s, or 0 if unrecognised.

func ParseParamSize

func ParseParamSize(s string) float64

ParseParamSize parses a parameter size string like "32B" or "671M" into billions of parameters. Returns 0 if unparseable.

Types

type HFModelInfo

type HFModelInfo struct {
	ModelID     string   `json:"modelId"`
	PipelineTag string   `json:"pipeline_tag"`
	Tags        []string `json:"tags"`
}

HFModelInfo holds model metadata from HuggingFace.

func FetchHFModelInfo

func FetchHFModelInfo(ctx context.Context, baseURL string, modelFamily string) (HFModelInfo, error)

FetchHFModelInfo searches the HuggingFace Hub API for a model by name and returns its metadata. The baseURL parameter allows test injection.

type Model

type Model struct {
	Name                    string
	Size                    int64
	ParameterSize           string
	Family                  string
	Provider                string  // "" or "ollama" = local; otherwise cloud provider (e.g. "anthropic")
	CompletionPricePerToken float64 // USD per token; 0 for local models
}

Model represents a locally available ollama model.

func FetchModels

func FetchModels(ctx context.Context, baseURL string) ([]Model, error)

FetchModels retrieves the list of locally available models from ollama using the official Go SDK.

type RankedModel

type RankedModel struct {
	Model
	SWEScore         float64
	Rank             int
	ScoreSource      string  // "SWE", "est", or "" (no score)
	SpeedTPM         float64 // estimated tokens per minute
	RecommendedScore float64 // composite score for default ranking
}

RankedModel is a Model with its SWE-bench score and rank position.

func RankModels

func RankModels(models []Model, limit int, sweScores map[string]float64, hfInfoMap map[string]HFModelInfo, systemRAMGB float64, sortBy string) []RankedModel

RankModels sorts models by composite score (descending) and limits to top N. It tries multiple matching strategies in order:

  1. Direct family match against sweScores (MatchModelScore)
  2. HF repo ID match against sweScores (FindSWEScore via hfInfoMap)
  3. Cloud model NormalizeCloudID match against sweScores
  4. Hardcoded fallback ratings

ScoreSource is set to "SWE" for live matches, "est" for fallback, "" for no score. sortBy can be "swe", "speed", "size", or "" / "recommended".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL