c0c11cd36d
- Add llmphraser: LFM-based phraser implementing Phraser interface with PhraseChat, PhraseNudge, PhraseReactive, and PhraseReminder methods. - Add shared internal/llm/client: llama-server completion client used by both the phraser (talking back) and router (routing), sharing one model. - Add LLMReplier in mavend: replaces StubReplier for chat/nudge/reactive replies, falls back to stub on model errors. - Update Phraser interface: add PhraseChat method, update stub to match. - Wire LLM phaser into mavend voice init, plumb LLM config from JSON.
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/kami/maven/internal/llm"
|
|
"github.com/kami/maven/internal/router"
|
|
"github.com/kami/maven/internal/voice"
|
|
)
|
|
|
|
type mockCompleter struct{ out string; err error }
|
|
|
|
func (m mockCompleter) Complete(_ context.Context, _ llm.Req) (string, error) { return m.out, m.err }
|
|
|
|
func TestLLMReplierReturnsLLMReply(t *testing.T) {
|
|
r := newLLMReplier(mockCompleter{out: "записала, кофе закончился"})
|
|
got := r.Reply(router.Decision{Intent: router.IntentNote, Slots: router.Slots{Text: "кофе закончился"}})
|
|
if got != "записала, кофе закончился" {
|
|
t.Errorf("got %q, want %q", got, "записала, кофе закончился")
|
|
}
|
|
}
|
|
|
|
func TestLLMReplierFallsBackToStubOnError(t *testing.T) {
|
|
r := newLLMReplier(mockCompleter{err: errTestLLMDown})
|
|
noteDec := router.Decision{Intent: router.IntentNote}
|
|
got := r.Reply(noteDec)
|
|
want := voice.NewStubReplier().Reply(noteDec)
|
|
if got != want {
|
|
t.Errorf("on llm error: got %q, want stub %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLLMReplierFallsBackToStubOnEmpty(t *testing.T) {
|
|
r := newLLMReplier(mockCompleter{out: ""})
|
|
noteDec := router.Decision{Intent: router.IntentNote}
|
|
got := r.Reply(noteDec)
|
|
want := voice.NewStubReplier().Reply(noteDec)
|
|
if got != want {
|
|
t.Errorf("on empty llm: got %q, want stub %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLLMReplierClarifyUsesStub(t *testing.T) {
|
|
r := newLLMReplier(mockCompleter{out: "я всё поняла"})
|
|
clarifyDec := router.Decision{Clarify: true}
|
|
got := r.Reply(clarifyDec)
|
|
want := voice.NewStubReplier().Reply(clarifyDec)
|
|
if got != want {
|
|
t.Errorf("on clarify: got %q, want stub %q", got, want)
|
|
}
|
|
}
|
|
|
|
var errTestLLMDown = errTest("llm down")
|
|
|
|
type errTest string
|
|
|
|
func (e errTest) Error() string { return string(e) }
|