Very thorough search — I need to find all "inference switch", "generator switcher", "external generate", "GeneratorSwitcher", "ExternalGenerateFn", "Gorgonite", "internal transformer" related code in the KNIRVSERVER backend and KNIRVHASHER packages.
Search in both:
packages/KNIRVSERVER/backend/ — especially internal/services/inferencer/ and internal/services/cognitiveengine/
packages/KNIRVHASHER/ — especially pkg/hashing/transformer/ and cmd/heart/
For each match found:
Return the full file path and line numbers
Show the surrounding context (10-20 lines)
Identify the struct/interface and its methods
Specifically I need to understand:
What is the current GeneratorSwitcher / ExternalGenerateFn mechanism?
How does the inferencer package decide between external LLM vs internal?
What's the Gorgonite / internal transformer model?
How is it currently configured and wired?
Where is the Neural Desktop Chat implemented?
Be very thorough — search for patterns like: GeneratorSwitcher, ExternalGenerateFn, external_generator, internal_generator, Gorgonite, gorgonite, transformer, inference_switch, model_switch, NewGPT, GenerateText, GenerateTextWithContext
Assistant
Now let me read the core files in detail:
Assistant
Now let me look at the generate_badge_config_handlers.go (the /api/v1/generate-badge-config endpoint that HEART calls), and check for the ExternalGeneratorURL wiring in the backend server's main:
Assistant
Here is the comprehensive report of all findings:
1. The GeneratorSwitcher / ExternalGenerateFn Mechanism
1. If force == Internal or External -> return forced mode
2. If no external generator configured -> Internal
3. If training provider says IsReady() -> Internal
4. Otherwise -> External (bootstrap mode)
Two implementations of WASMSourceGenerator:
InternalGPTGenerator (lines 96-125 of generator.go) — wraps the Gorgonite 4-stage pipeline
ExternalLLMGenerator (lines 22-106 of external_generator.go) — uses a callback function or HTTP endpoint
NewExternalLLMGenerator(fn ExternalGenerateFn) (line 30) — for in-process injection
NewExternalLLMGeneratorWithURL(url string) (line 37) — for HTTP-based LLM
GenerateSource() builds a structured prompt via BuildWASMGenerationPrompt() (line 110), then either calls the function or POSTs to the URL. The HTTP endpoint receives WASMGenerationRequest and returns WASMGenerationResponse.
2. How the Inferencer Decides External LLM vs Internal
GenerateTextWithContext() (line 361) delegates to DelegatorService.GenerateSimple() (line 380), which tries primary attempts first, then falls through to fallbacks on 429/quota/transient errors.
The /api/v1/generate-badge-config endpoint (line 1981 of backend_server/main.go) is the bridge: the HEART service's ExternalGeneratorURL points at this KNIRVSERVER endpoint when the GeneratorSwitcher is in external mode.
type GorgoniteConfig struct {
VocabSize int // 100277
EmbedDim int // 768
NumHeads int // 12
NumLayers int // 12
ContextLen int // 2048
DropoutRate float64 // 0.1
FFNHiddenDim int // 3072
}
type HasherTransformerConfig struct {
VocabSize int
EmbedDim int
NumLayers int
NumHeads int
ContextLen int
DropoutRate float32
FFNHiddenDim int
Activation string // "hash", "tanh", "sigmoid"
}
Each weight is a [32]byte seed operated on by core.HashMethod (SHA-256 via ASIC), making it hardware-accelerated. Forward() runs tokens through embedding, multi-head attention (seed-based QKV), FFN (seed-based), and average pooling. GenerateToken() produces next-token predictions with temperature sampling.
Per the transformer_audit.md (line 12): "The HasherTransformer (hash-seed, hardware-accelerated) lives in gpt.go:935+ and is the default path via hasher-host, not the Gorgonite GPT."
// Register WASM generation endpoint (bootstrap LLM generator for HEART).
// The HEART service calls this endpoint when its GeneratorSwitcher is
// in external mode (i.e. while the internal Gorgonite model is training).
// Chat routes — public so the Neural Desktop can chat without auth in testnet mode
cognitiveRouter.HandleFunc("/chat", h.HandleChat).Methods("POST", "OPTIONS")
cognitiveRouter.HandleFunc("/chat/clear", h.HandleClearChatSession).Methods("POST", "OPTIONS")
HandleChat() (line 342):
Standard quality: calls h.inferenceService.Chat()
Deep quality: calls h.inferenceService.GenerateTextWithMOA() directly
GeneratorSwitcher is ONLY in KNIRVHASHER/pkg/hashing/transformer/generator.go. It switches WASM generation between the internal Gorgonite GPT (Gorgonia-based 4-stage pipeline) and an external LLM, based on the GPT's training state (IsReady()).
ExternalGenerateFn is ONLY in KNIRVHASHER/pkg/hashing/transformer/external_generator.go. It is a callback type func(ctx context.Context, prompt string) (string, error) injected in HEARTConfig.ExternalGenerateFn (JSON/YAML-ignored), with an HTTP URL fallback ExternalGeneratorURL.
The Gorgonite model (GPT struct in gpt.go:364) is a full 12-layer, 12-head, 768-dim transformer built with Gorgonia, using sinusoidal positional encoding, multi-head self-attention, causal masking, and FeedForward blocks. Its weights are trained via the TrainModel() pipeline.
The HasherTransformer (gpt.go:984) is a separate hardware-accelerated transformer where every weight is a [32]byte seed operated on by core.HashMethod (SHA-256 via ASIC). It is the default path via hasher-host (cmd/driver/hasher-host/main.go), NOT used by HEARTService.
The KNIRVSERVER InferenceService does NOT use GeneratorSwitcher. It uses a DelegatorService with a Gemini→Deepseek→Cerebras→OpenAI→Anthropic fallback chain. The /api/v1/generate-badge-config endpoint serves as the HEART service's external LLM during bootstrap.