config

package
v1.48.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL         = "http://localhost:11434/v1"
	DefaultModel           = "qwen3"
	DefaultLLMTimeout      = 5 * time.Second
	DefaultCacheTTL        = 30 * 24 * time.Hour // 30 days
	DefaultMaxExtractPages = 20
	DefaultTextTimeout     = 30 * time.Second
)

Variables

This section is empty.

Functions

func EnvVars added in v1.46.0

func EnvVars() map[string]string

EnvVars returns a mapping from environment variable names to their dot-delimited config keys, derived from the `env` struct tags.

func ExampleTOML

func ExampleTOML() string

ExampleTOML returns a commented config file suitable for writing as a starter config. Not written automatically -- offered to the user on demand.

func Keys added in v1.46.0

func Keys() []string

Keys returns the sorted list of valid dot-delimited config key names by reflecting on the Config struct's TOML tags.

func ParseDuration added in v1.39.0

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string. It extends Go's time.ParseDuration with support for a "d" (day) suffix, and treats bare integers as seconds.

func Path

func Path() string

Path returns the expected config file path (XDG_CONFIG_HOME/micasa/config.toml).

Types

type ByteSize added in v1.39.0

type ByteSize uint64

ByteSize represents a size in bytes, parseable from unitized strings like "50 MiB" or bare integers (interpreted as bytes).

func ParseByteSize added in v1.39.0

func ParseByteSize(s string) (ByteSize, error)

ParseByteSize parses a size string like "50 MiB", "1.5 GiB", or "1024". A bare integer is interpreted as bytes.

func (ByteSize) Bytes added in v1.39.0

func (b ByteSize) Bytes() uint64

Bytes returns the size as uint64.

func (*ByteSize) UnmarshalTOML added in v1.39.0

func (b *ByteSize) UnmarshalTOML(v any) error

UnmarshalTOML implements toml.Unmarshaler for ByteSize, accepting both TOML integers (bytes) and strings ("50 MiB").

type Config

type Config struct {
	LLM        LLM        `toml:"llm"`
	Documents  Documents  `toml:"documents"`
	Extraction Extraction `toml:"extraction"`

	// Warnings collects non-fatal messages (e.g. deprecations) during load.
	// Not serialized; the caller decides how to display them.
	Warnings []string `toml:"-"`
}

Config is the top-level application configuration, loaded from a TOML file.

func Load

func Load() (Config, error)

Load reads the TOML config file from the default path if it exists, falls back to defaults for any unset fields, and applies environment variable overrides last.

func LoadFromPath

func LoadFromPath(path string) (Config, error)

LoadFromPath reads the TOML config file at the given path if it exists, falls back to defaults for any unset fields, and applies environment variable overrides last.

func (Config) Get added in v1.46.0

func (c Config) Get(key string) (string, error)

Get resolves a dot-delimited config key to its string representation. Keys mirror the TOML structure (e.g. "llm.model", "documents.max_file_size").

type Documents added in v1.27.0

type Documents struct {
	// MaxFileSize is the largest file that can be imported as a document
	// attachment. Accepts unitized strings ("50 MiB") or bare integers
	// (bytes). Default: 50 MiB.
	MaxFileSize ByteSize `toml:"max_file_size" env:"MICASA_MAX_DOCUMENT_SIZE"`

	// CacheTTL is the preferred cache lifetime setting. Accepts unitized
	// strings ("30d", "720h") or bare integers (seconds). Default: 30d.
	CacheTTL *Duration `toml:"cache_ttl,omitempty" env:"MICASA_CACHE_TTL"`

	// CacheTTLDays is deprecated; use CacheTTL instead. Kept for backward
	// compatibility. Bare integer interpreted as days.
	CacheTTLDays *int `toml:"cache_ttl_days,omitempty" env:"MICASA_CACHE_TTL_DAYS"`
}

Documents holds settings for document attachments.

func (Documents) CacheTTLDuration added in v1.39.0

func (d Documents) CacheTTLDuration() time.Duration

CacheTTLDuration returns the resolved cache TTL as a time.Duration. CacheTTL takes precedence over CacheTTLDays. Returns 0 to disable.

type Duration added in v1.39.0

type Duration struct{ time.Duration }

Duration wraps time.Duration with parsing support for day-suffixed strings ("30d") and bare integers (interpreted as seconds).

func (*Duration) UnmarshalTOML added in v1.39.0

func (d *Duration) UnmarshalTOML(v any) error

UnmarshalTOML implements toml.Unmarshaler for Duration, accepting TOML integers (seconds) and strings ("30d", "720h").

type Extraction added in v1.45.0

type Extraction struct {
	// Model overrides llm.model for extraction. Extraction wants a small,
	// fast model optimized for structured JSON output. Defaults to the
	// chat model if empty.
	Model string `toml:"model" env:"MICASA_EXTRACTION_MODEL"`

	// MaxExtractPages is the maximum number of pages for async extraction of scanned
	// documents. Front-loaded info (specs, warranty) is typically in the
	// first pages. Default: 20.
	MaxExtractPages int `toml:"max_extract_pages" env:"MICASA_MAX_EXTRACT_PAGES"`

	// Enabled controls whether LLM-powered extraction runs when a document
	// is uploaded. Text and image extraction are independent and always
	// available. Default: true.
	Enabled *bool `toml:"enabled,omitempty" env:"MICASA_EXTRACTION_ENABLED"`

	// TextTimeout is the maximum time to wait for pdftotext. Go duration
	// string, e.g. "30s", "1m". Default: "30s".
	TextTimeout string `toml:"text_timeout" env:"MICASA_TEXT_TIMEOUT"`

	// Thinking enables the model's internal reasoning mode (e.g. qwen3
	// <think> blocks). Disable for faster responses when structured output
	// is all you need. Default: false.
	Thinking *bool `toml:"thinking,omitempty" env:"MICASA_EXTRACTION_THINKING"`
}

Extraction holds settings for the document extraction pipeline (LLM-powered structured pre-fill).

func (Extraction) IsEnabled added in v1.45.0

func (e Extraction) IsEnabled() bool

IsEnabled returns whether LLM extraction is enabled. Defaults to true when the field is unset.

func (Extraction) ResolvedModel added in v1.45.0

func (e Extraction) ResolvedModel(chatModel string) string

ResolvedModel returns the extraction model, falling back to the given chat model if no extraction-specific model is configured.

func (Extraction) TextTimeoutDuration added in v1.45.0

func (e Extraction) TextTimeoutDuration() time.Duration

TextTimeoutDuration returns the parsed text extraction timeout, falling back to DefaultTextTimeout if the value is empty or unparseable.

func (Extraction) ThinkingEnabled added in v1.45.0

func (e Extraction) ThinkingEnabled() bool

ThinkingEnabled returns whether model thinking mode is enabled. Defaults to false (faster, no <think> blocks).

type LLM

type LLM struct {
	// BaseURL is the root of an OpenAI-compatible API.
	// The client appends /chat/completions, /models, etc.
	// Default: http://localhost:11434/v1 (Ollama)
	BaseURL string `toml:"base_url" env:"OLLAMA_HOST"`

	// Model is the model identifier passed in chat requests.
	// Default: qwen3
	Model string `toml:"model" env:"MICASA_LLM_MODEL"`

	// ExtraContext is custom text appended to all system prompts.
	// Useful for domain-specific details: house style, currency, location, etc.
	// Optional; defaults to empty.
	ExtraContext string `toml:"extra_context"`

	// Timeout is the maximum time to wait for quick LLM server operations
	// (ping, model listing, auto-detect). Go duration string, e.g. "5s",
	// "10s", "500ms". Default: "5s".
	Timeout string `toml:"timeout" env:"MICASA_LLM_TIMEOUT"`

	// Thinking enables the model's internal reasoning mode for chat
	// (e.g. qwen3 <think> blocks). Default: unset (not sent to server).
	Thinking *bool `toml:"thinking,omitempty" env:"MICASA_LLM_THINKING"`
}

LLM holds settings for the local LLM inference backend.

func (LLM) TimeoutDuration added in v1.32.0

func (l LLM) TimeoutDuration() time.Duration

TimeoutDuration returns the parsed LLM timeout, falling back to DefaultLLMTimeout if the value is empty or unparseable.

Jump to

Keyboard shortcuts

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