ollama

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 12 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 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 Detect

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

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

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)

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.

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 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 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
}

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)
}

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) []RankedModel

RankModels sorts models by SWE-bench 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. Hardcoded fallback ratings

ScoreSource is set to "SWE" for live matches, "est" for fallback, "" for no score.

Jump to

Keyboard shortcuts

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