CodeVetter · Repo Unpack · Extension points
ollama/ollama
Deliberate plug-in surfaces: per-model-family Parser and Renderer registries (name-keyed constructors with a switch fallback), embedded named chat templates, the llm.LlamaServer runner interface, cobra command table, launch.Default* UI hooks, middleware translators for new API dialects, envconfig's AsMap registry, and the create/ import pipeline stages.
- New output parsers plug in via parsers.Register(name, constructor) or a case in ParserForName's switch; Parser interface = Init/Add/PreservedTokens/HasToolSupport/HasThinkingSupport
- New prompt renderers plug in via renderers.Register or rendererForName switch; Renderer interface = Thinking/Render/LeadingBOS; RenderImgTags global toggles [img] tag emission
- Named Go templates are added as .gotmpl+.json pairs embedded via go:embed and indexed in template/index.json; template.Named resolves by GGUF chat_template name for autodetection
- New inference backends implement llm.LlamaServer (Completion/Chat/Embedding/Tokenize/WaitUntilRunning/Close/...) and get wired through Scheduler.newServerFn or the IsMLX branch (mlxrunner.Client)
- New API dialects slot into GenerateRoutes as gin middleware translators in middleware/ (ChatMiddleware, CompletionsMiddleware, ResponsesMiddleware, AnthropicMessagesMiddleware, TranscriptionMiddleware) wrapping the core handlers
- New CLI commands register in NewCLI's command table; hidden/internal commands (runner, gpu-discover) show the pattern for plumbing sub-binaries through the same binary
- Interactive UI is swappable via launch.Default* function hooks (SingleSelector, MultiSelector, SignIn, Upgrade, ConfirmPrompt, Spinner) — cmd/cmd.go's init() replaces them with Bubbletea TUI implementations
- New environment settings register in envconfig: typed accessors (Bool/Uint/String/BoolWithDefault) plus an entry in AsMap() so `ollama serve` logs and help list them
- GPU backends are build-time extensions: OLLAMA_LLAMA_BACKENDS selects cuda_v12/cuda_v13/rocm_v7_1/rocm_v7_2/vulkan/jetpack variants; runtime discovery globs lib/ollama/*/ggml-* dirs
- Safetensors import is a staged pipeline in create/ (classify -> transform -> prequant -> quantize -> writer -> manifest) with per-architecture files (gemma4.go, qwen35.go, cohere2moe.go, glimmer.go, nemotron_h.go, laguna.go) — new architectures add a file + classification entry
- Model capabilities are declared via model.Capability flags (completion, tools, insert, vision, audio, embedding, thinking, image) checked through Model.CheckCapabilities, gating handler behavior per request