package main import ( "log" "github.com/kami/maven/internal/config" "github.com/kami/maven/internal/kiwix" "github.com/kami/maven/internal/llm" ) // kiwixWiring — the offline encyclopedia, assembled. nil ⇒ off, which is the // default: the query chain simply has no ZIM source. // // The rewriter is separately optional. Searching without one is legal and // mostly useless against English ZIMs, but it is the honest degraded mode when // there is no llama-server to rewrite with, and it is what `rewrite: false` // asks for. type kiwixWiring struct { client *kiwix.Client rewriter *kiwix.Rewriter // nil ⇒ the question is searched verbatim book string // bookRU — searched instead of book when the question is Cyrillic, and // searched verbatim because it is in his language already (V-508). Empty ⇒ // every question goes to book. bookRU string max int runes int } // wireKiwix builds the ZIM reader from the `kiwix` block, or returns nil when // there is none. config.Normalise has already dropped a block with no URL and // filled the two size defaults, so this does no validation of its own. // // The llm client is the phraser's swap-aware one (llmClientFor), so a model // swap re-points the rewriter with everything else. A nil client means there is // no resident model at all; that degrades the rewriter, not the source. func wireKiwix(cfg *config.Config, c *llm.Client) *kiwixWiring { if cfg.Kiwix == nil { return nil } kc := cfg.Kiwix w := &kiwixWiring{ client: kiwix.New(kc.URL), book: kc.Book, bookRU: kc.BookRU, max: kc.MaxResults, runes: kc.SnippetRunes, } if kc.BookRU != "" { log.Printf("voice: kiwix: russian questions read %q verbatim", kc.BookRU) } switch { case !kc.RewriteEnabled(): log.Printf("voice: kiwix at %s (book %q, query rewriting off by config)", kc.URL, kc.Book) case c == nil: log.Printf("voice: kiwix at %s (book %q, no llama-server: searching questions verbatim)", kc.URL, kc.Book) default: w.rewriter = kiwix.NewRewriter(c) log.Printf("voice: kiwix at %s (book %q)", kc.URL, kc.Book) } return w }