titlemodel

package
v1.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package titlemodel names sessions with a tiny language model that runs on the user's own machine.

A session needs a short title, and asking the chat provider for it costs a request, needs the network and shows the first message to the provider again. A 0.5-billion-parameter instruct model answers in about a second on a CPU, offline and for free. The package downloads two things on request, checks both against sums fixed in this file, and runs them: the llama.cpp server (llama-server) and a small GGUF model. Nothing is downloaded or started unless the user installed the model (`seshat title-model install`), and when it is missing or fails, the engine falls back to the provider as before.

Index

Constants

View Source
const DefaultModelID = "qwen2.5-0.5b"

DefaultModelID is the model installed when none is chosen.

View Source
const HFBaseURL = "https://huggingface.co"

HFBaseURL is where the model files are published.

View Source
const LlamaBaseURL = "https://github.com/ggml-org/llama.cpp/releases/download/" + LlamaTag

LlamaBaseURL is where the archives are published.

View Source
const LlamaTag = "b11342"

LlamaTag is the llama.cpp release the server comes from. Raising it means checking the new archives and updating every sum below.

Variables

View Source
var Models = []Model{
	{
		ID: "qwen2.5-0.5b", Label: "Qwen2.5 0.5B Instruct", Repo: "Qwen/Qwen2.5-0.5B-Instruct-GGUF",
		File: "qwen2.5-0.5b-instruct-q4_k_m.gguf", SHA256: "74a4da8c9fdbcd15bd1f6d01d621410d31c6fc00986f5eb687824e7b93d7a9db",
		Size: 491400032, Description: "Default. Small, multilingual, Apache-2.0.",
	},
	{
		ID: "gemma-3-270m", Label: "Gemma 3 270M Instruct", Repo: "unsloth/gemma-3-270m-it-GGUF",
		File: "gemma-3-270m-it-Q4_K_M.gguf", SHA256: "b1baabd6b729e4041822220d3e648e00d99cac5df86b10dffb77bcccf0688e39",
		Size: 253115424, Description: "Smallest option. Faster, rougher titles. Gemma terms of use apply.",
	},
}

Models is the catalog, the same models the desktop offers.

Functions

func CleanTitle

func CleanTitle(raw string) string

CleanTitle keeps the first line of a model's answer, without quotes, a "Title:" label or closing punctuation, and at most 8 words.

func CleanupOrphan

func CleanupOrphan(root string) bool

CleanupOrphan stops a title server that an earlier run of seshat left behind, and reports whether it did.

A process id alone is not proof of anything (the system reuses them), so the process is stopped only if the port of the record still answers as a llama-server that has loaded this very model file.

func CloseShared

func CloseShared()

CloseShared stops the shared server, if any.

func LogFile

func LogFile(root string) (*os.File, error)

LogFile opens the file the server output goes to, next to the installation.

func Remove

func Remove(root string) error

Remove deletes everything an installation put on disk.

func SaveState

func SaveState(root string, st State) error

SaveState records an installation.

func StatePath

func StatePath(root string) string

StatePath is where the installation is recorded.

Types

type Archive

type Archive struct {
	Name   string
	SHA256 string
	Size   int64
}

Archive is a llama.cpp CPU build for one platform.

func ArchiveFor

func ArchiveFor(goos, goarch string) (Archive, bool)

ArchiveFor returns the llama.cpp build for a platform.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator names sessions with the local model. It satisfies the engine's TitleGenerator. The server starts at the first title, is shared by every session of the process, and stops when idle or on Close.

func NewGenerator

func NewGenerator(root string, st State) *Generator

NewGenerator returns a generator for an installation.

func Shared

func Shared(root string) *Generator

Shared returns the generator of the process for a runtime root, or nil when the model is not installed or is turned off. Several clients are built in one run (changing the model builds a new one) and they must share one server.

func (*Generator) Close

func (g *Generator) Close()

Close stops the server and refuses further titles.

func (*Generator) GenerateTitle

func (g *Generator) GenerateTitle(ctx context.Context, firstUserMsg string) (string, error)

GenerateTitle returns a short title for the first message of a session.

type Installer

type Installer struct {
	// Root is the runtime root; everything lives in Root/title-model.
	Root string
	// LlamaBase and HFBase are the download locations (tests point them at a local server).
	LlamaBase string
	HFBase    string
	HTTP      *http.Client
	// Archives and Models override the catalog (tests).
	Archives map[string]Archive
	Models   []Model
	// GOOS and GOARCH override the platform (tests).
	GOOS, GOARCH string
	Progress     Progress
}

Installer downloads, checks and records the server and the model.

func NewInstaller

func NewInstaller(root string) *Installer

NewInstaller returns an installer for the official locations and the real platform.

func (*Installer) Install

func (in *Installer) Install(ctx context.Context, modelID string) (State, error)

Install downloads the llama.cpp server and the model (what is already there and intact is not downloaded again), then records the installation and turns it on.

type Model

type Model struct {
	ID          string
	Label       string
	Repo        string
	File        string
	SHA256      string
	Size        int64
	Description string
}

Model is a GGUF instruct model small enough to name a session in about a second on a CPU. Only models that answer directly belong here: a reasoning model spends its output budget thinking and never returns a title.

func FindModel

func FindModel(id string) (Model, error)

FindModel returns the catalog entry with the given id.

type Progress

type Progress func(what string, done, total int64)

Progress is called while a file downloads.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a running llama-server bound to the loopback address.

func StartServer

func StartServer(ctx context.Context, serverPath, modelPath string, log io.Writer) (*Server, error)

StartServer launches llama-server on a free loopback port and returns once the model is loaded and the server answers. log, when not nil, receives what the server prints.

func (*Server) Alive

func (s *Server) Alive() bool

Alive reports whether the process is still running.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL is the address of the server's HTTP API.

func (*Server) PID

func (s *Server) PID() int

PID is the process id of the server, 0 when there is no process.

func (*Server) Port

func (s *Server) Port() int

Port is the loopback port the server listens on.

func (*Server) Stop

func (s *Server) Stop()

Stop ends the server. It is safe to call more than once.

type State

type State struct {
	// Enabled says whether sessions are named with the local model. Installing turns it on; `disable` turns it off
	// without deleting anything.
	Enabled    bool   `json:"enabled"`
	ModelID    string `json:"model_id"`
	ModelPath  string `json:"model_path"`
	ServerPath string `json:"server_path"`
	LlamaTag   string `json:"llama_tag"`
}

State is what is recorded of an installation, in <runtime root>/title-model/state.json.

func LoadState

func LoadState(root string) State

LoadState reads the recorded installation; a missing or damaged file is an empty state.

func (State) Ready

func (s State) Ready() bool

Ready reports whether both files an installation records are still on disk.

Jump to

Keyboard shortcuts

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