fix(archiegateway): curators resolve the default chat model per pass, not at boot (#1818)
This commit is contained in:
2 files changed
+11
-20
No files matched your search
@@ -26,11 +26,6 @@ import (
|
|||||||
|
|
||||||
func (b *server) setupCurators(ctx context.Context) error {
|
func (b *server) setupCurators(ctx context.Context) error {
|
||||||
log := b.log.With("component", "curator")
|
log := b.log.With("component", "curator")
|
||||||
model, err := b.chatModels.ModelFor(ctx)
|
|
||||||
if err != nil {
|
|
||||||
log.WarnContext(ctx, "curators disabled: chat model unavailable; configure a chat model and restart the gateway", "err", err)
|
|
||||||
return fmt.Errorf("curators disabled until the gateway restarts with a chat model: %w", err)
|
|
||||||
}
|
|
||||||
skillsRoot := b.cfg.SkillsDir
|
skillsRoot := b.cfg.SkillsDir
|
||||||
if skillsRoot == "" {
|
if skillsRoot == "" {
|
||||||
skillsRoot = b.cfg.WorkDir
|
skillsRoot = b.cfg.WorkDir
|
||||||
@@ -42,8 +37,7 @@ func (b *server) setupCurators(ctx context.Context) error {
|
|||||||
MemoryEngines: b.memEngines,
|
MemoryEngines: b.memEngines,
|
||||||
Skills: skillcurator.NewStore(skillsRoot),
|
Skills: skillcurator.NewStore(skillsRoot),
|
||||||
Conversations: sessioncurator.NewAdapter(b.chatSessionStore, b.cfg.BotUser),
|
Conversations: sessioncurator.NewAdapter(b.chatSessionStore, b.cfg.BotUser),
|
||||||
LLM: actingPrincipalRunner{inner: curatorLLMRunner{llm: b.chatLLM, outcomes: b.providerOutcomes, usage: b.usage}, resolve: b.actingPrincipal},
|
LLM: actingPrincipalRunner{inner: curatorLLMRunner{llm: b.chatLLM, outcomes: b.providerOutcomes, usage: b.usage, defaultModel: b.chatModels.ModelFor}, resolve: b.actingPrincipal},
|
||||||
Model: model,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := b.curatorRegistry.Register(skillcurator.New(skillcurator.DefaultInterval)); err != nil {
|
if err := b.curatorRegistry.Register(skillcurator.New(skillcurator.DefaultInterval)); err != nil {
|
||||||
@@ -153,6 +147,9 @@ type curatorLLMRunner struct {
|
|||||||
// older chat outcome as current.
|
// older chat outcome as current.
|
||||||
outcomes *providerOutcomeRecorder
|
outcomes *providerOutcomeRecorder
|
||||||
usage *usageSink
|
usage *usageSink
|
||||||
|
// defaultModel resolves the model for a curator whose manifest names none,
|
||||||
|
// at each call, so a chat model configured after boot reaches the next pass.
|
||||||
|
defaultModel func(context.Context) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (curator.ChatResult, error) {
|
func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (curator.ChatResult, error) {
|
||||||
@@ -167,6 +164,13 @@ func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (cu
|
|||||||
if llm == nil {
|
if llm == nil {
|
||||||
return curator.ChatResult{}, fmt.Errorf("curator chat: no model runtime is configured")
|
return curator.ChatResult{}, fmt.Errorf("curator chat: no model runtime is configured")
|
||||||
}
|
}
|
||||||
|
if req.Model == "" {
|
||||||
|
model, err := r.defaultModel(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return curator.ChatResult{}, fmt.Errorf("curator chat: no chat model configured: %w", err)
|
||||||
|
}
|
||||||
|
req.Model = model
|
||||||
|
}
|
||||||
msgs := make([]chat.Message, 0, len(req.Messages))
|
msgs := make([]chat.Message, 0, len(req.Messages))
|
||||||
for _, m := range req.Messages {
|
for _, m := range req.Messages {
|
||||||
msgs = append(msgs, chat.Message{Role: chat.Role(m.Role), Content: m.Content})
|
msgs = append(msgs, chat.Message{Role: chat.Role(m.Role), Content: m.Content})
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package archiegateway
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/slog"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCuratorsWithoutChatModel(t *testing.T) {
|
|
||||||
b := &server{log: slog.New(slog.DiscardHandler), chatModels: newChatModelManager(nil)}
|
|
||||||
if err := b.startCurators(t.Context()); err != nil {
|
|
||||||
t.Fatalf("unconfigured curators must not stop the gateway: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user