attachments

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blocked

type Blocked struct {
	Path   string
	Reason string
}

type Extractor

type Extractor func(path string) (string, error)

type Kind

type Kind int
const (
	KindImage Kind = iota
	KindAudio
	KindVideo
	KindDocument
	KindText
	KindUnknown
)

func Sniff

func Sniff(path string) Kind

Sniff classifies a file by extension. Documents/text delegate to the extraction package's predicates so the two stay in sync.

type ModelCapabilities

type ModelCapabilities struct {
	InputModalities []string // "text","image","audio","video"
}

func FetchCapabilities

func FetchCapabilities(ctx context.Context, baseURL, apiKey, model string) ModelCapabilities

FetchCapabilities asks LocalAI's /models/capabilities endpoint for the given model's input modalities. Any failure (network, decode, unknown model) is treated as text-only so we never hand media to a model that can't take it.

func (ModelCapabilities) Accepts

func (m ModelCapabilities) Accepts(mod string) bool

type Override

type Override int
const (
	OverrideNone Override = iota
	OverrideTranscribe
)

type Part

type Part struct {
	Kind    Kind
	DataURI string
	// Format is the container/codec derived from the file extension (e.g. "wav",
	// "mp3", "m4a"). Only populated for natively-sent audio (SendAsAudio), where
	// it feeds cogito's input_audio.format wire field; empty for image/video.
	Format string
}

type Result

type Result struct {
	Parts        []Part
	TextPreamble string
	Blocked      []Blocked
}

func Apply

func Apply(ctx context.Context, files []string, caps ModelCapabilities, overrides map[string]Override,
	extract Extractor, transcribe Transcriber) (Result, error)

Apply resolves each file to its treatment and executes it, producing the native parts + text preamble SendMessage needs, plus any blocked files for the caller to surface. overrides maps a file path to an audio override (may be nil).

Apply is all-or-nothing on hard failures: the first extractor, transcriber, or DataURI error aborts the whole batch and is returned as-is (the caller is expected to resolve or remove the offending file and retry). Only capability Block outcomes are non-fatal — they are collected into Result.Blocked rather than erroring, so a batch containing a lone unsupported file still returns a nil error with that file recorded in Blocked.

type Transcriber

type Transcriber func(ctx context.Context, path string) (string, error)

type Treatment

type Treatment int
const (
	SendAsImage Treatment = iota
	SendAsAudio
	SendAsVideo
	Transcribe
	ConvertToText
	Block
)

func Route

func Route(kind Kind, caps ModelCapabilities, override Override) Treatment

Route is pure: it maps a file kind + the active model's capabilities + an optional (audio-only) override to a treatment. See the spec's decision table.

Jump to

Keyboard shortcuts

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