Adds two new LLM-backed MCP tools to the ingestion service: - brain_answer(query): BM25 retrieval + LLM synthesis → answer + sources - brain_classify(text): classifies doc into type/title/tags via LLM Adds llm.Router for primary→fallback routing (berget.ai → iguana). Wired via BRAIN_LLM_PRIMARY_URL/BRAIN_LLM_FALLBACK_URL env vars; no-op when unset so existing deployments are unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
747 B
Go
30 lines
747 B
Go
package llm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// Router calls Primary first; on any error falls back to Fallback.
|
|
// Fallback may be nil, in which case primary errors are returned directly.
|
|
type Router struct {
|
|
Primary *Client
|
|
Fallback *Client
|
|
}
|
|
|
|
// Complete implements pipeline.CompleteFunc, routing through Primary then Fallback.
|
|
func (r *Router) Complete(ctx context.Context, system, user string) (string, error) {
|
|
out, err := r.Primary.Complete(ctx, system, user)
|
|
if err == nil {
|
|
return out, nil
|
|
}
|
|
if r.Fallback == nil {
|
|
return "", fmt.Errorf("primary llm: %w", err)
|
|
}
|
|
out, err2 := r.Fallback.Complete(ctx, system, user)
|
|
if err2 != nil {
|
|
return "", fmt.Errorf("primary llm: %w; fallback llm: %v", err, err2)
|
|
}
|
|
return out, nil
|
|
}
|