Add per-chat thinking levels for Codex, Claude Code and OpenCode
Codex: model/list supportedReasoningEfforts per model, turn/start effort, thread reasoningEffort as the current level. Claude Code: initialize supportedEffortLevels, apply_flag_settings effortLevel at the next turn start. OpenCode v2: model variants via the session model endpoint. chat_effort sets a level; rows and chat_models carry the levels; Codex and Claude levels persist in operator_sessions.chat_effort and are re-applied before every turn.
This commit is contained in:
@@ -249,6 +249,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatModeSelect:
|
||||
handleChatModeSwitch(ctx, request, broker, write)
|
||||
return true
|
||||
case protocol.ChatEffortSelect:
|
||||
handleChatEffort(ctx, request, broker, write)
|
||||
return true
|
||||
case protocol.ChatShells:
|
||||
handleChatShells(ctx, request, broker, registry, write)
|
||||
return true
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// chatEfforter is the optional thinking-level surface of a chat harness.
|
||||
type chatEfforter interface {
|
||||
// Efforts reports the levels the row's model accepts (session.Model is
|
||||
// already the saved next-turn model) and the harness default, from what
|
||||
// the adapter knows without starting a process. None: no control.
|
||||
Efforts(ctx context.Context, session protocol.ChatSession) ([]protocol.ChatEffort, string, error)
|
||||
// SetEffort hands a level to the harness for the next turn; "" restores
|
||||
// its default. A running turn keeps the level it started with.
|
||||
SetEffort(ctx context.Context, sessionID, effort string) error
|
||||
}
|
||||
|
||||
// chatEffortRegistry stores each Codex or Claude chat's level. OpenCode keeps
|
||||
// the level natively as the session model's variant.
|
||||
type chatEffortRegistry interface {
|
||||
SetChatEffort(ctx context.Context, id, effort string) error
|
||||
ChatEffort(ctx context.Context, id string) (string, error)
|
||||
}
|
||||
|
||||
var (
|
||||
errChatEffortsUnsupported = errors.New("this chat harness does not support thinking levels")
|
||||
errChatEffortsNone = errors.New("this chat's model has no thinking levels")
|
||||
)
|
||||
|
||||
// storedEffort is a model backend's saved level, "" when none.
|
||||
func (m *chatManager) storedEffort(ctx context.Context, id string) string {
|
||||
registry, ok := m.registry.(chatEffortRegistry)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
effort, err := registry.ChatEffort(ctx, id)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return effort
|
||||
}
|
||||
|
||||
// withEffort adds the row model's levels and the current level. A level the
|
||||
// model does not accept is reported as the default rather than as chosen.
|
||||
func (m *chatManager) withEffort(ctx context.Context, session protocol.ChatSession) protocol.ChatSession {
|
||||
efforter, ok := m.adapter(session.Backend).(chatEfforter)
|
||||
if !ok {
|
||||
session.Effort, session.Efforts, session.DefaultEffort = "", nil, ""
|
||||
return session
|
||||
}
|
||||
efforts, fallback, err := efforter.Efforts(ctx, session)
|
||||
if err != nil || len(efforts) == 0 {
|
||||
session.Effort, session.Efforts, session.DefaultEffort = "", nil, ""
|
||||
return session
|
||||
}
|
||||
// A stored choice wins; otherwise the harness's own reported level (a
|
||||
// Codex thread's reasoningEffort, an OpenCode variant) is current.
|
||||
if isModelBackend(session.Backend) {
|
||||
if stored := m.storedEffort(ctx, session.ID); stored != "" {
|
||||
session.Effort = stored
|
||||
}
|
||||
}
|
||||
if !protocol.HasChatEffort(efforts, session.Effort) {
|
||||
session.Effort = ""
|
||||
}
|
||||
if !protocol.HasChatEffort(efforts, fallback) {
|
||||
fallback = ""
|
||||
}
|
||||
session.Efforts, session.DefaultEffort = efforts, fallback
|
||||
return session
|
||||
}
|
||||
|
||||
// EffortState is the chat's current level with its model's levels.
|
||||
func (m *chatManager) EffortState(ctx context.Context, sessionID string) (protocol.ChatEffortRequest, error) {
|
||||
session, found, err := m.Session(ctx, sessionID)
|
||||
if err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
if !found {
|
||||
return protocol.ChatEffortRequest{}, errors.New("unknown chat session " + sessionID)
|
||||
}
|
||||
return effortState(session), nil
|
||||
}
|
||||
|
||||
func effortState(session protocol.ChatSession) protocol.ChatEffortRequest {
|
||||
return protocol.ChatEffortRequest{SessionID: session.ID, Effort: session.Effort, Efforts: session.Efforts, DefaultEffort: session.DefaultEffort}
|
||||
}
|
||||
|
||||
// SetEffort validates a level against the chat's current model, hands it to
|
||||
// the harness and, for Codex and Claude, stores it so it survives a restart
|
||||
// and is re-applied before every later turn.
|
||||
func (m *chatManager) SetEffort(ctx context.Context, sessionID, effort string) (protocol.ChatEffortRequest, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
efforter, ok := adapter.(chatEfforter)
|
||||
if !ok {
|
||||
return protocol.ChatEffortRequest{}, errChatEffortsUnsupported
|
||||
}
|
||||
state, err := m.EffortState(ctx, sessionID)
|
||||
if err == nil && len(state.Efforts) == 0 {
|
||||
// A harness whose catalog arrives with its process (Claude Code)
|
||||
// loads it on an explicit choice, never just to list a row.
|
||||
if modeler, ok := adapter.(chatModeler); ok {
|
||||
if _, err := modeler.Models(ctx, sessionID); err == nil {
|
||||
state, err = m.EffortState(ctx, sessionID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
if len(state.Efforts) == 0 {
|
||||
return protocol.ChatEffortRequest{}, errChatEffortsNone
|
||||
}
|
||||
if effort != "" && !protocol.HasChatEffort(state.Efforts, effort) {
|
||||
return protocol.ChatEffortRequest{}, errors.New("thinking level " + effort + " is not offered by this chat's model")
|
||||
}
|
||||
if isModelBackend(m.backendFor(ctx, sessionID)) {
|
||||
registry, ok := m.registry.(chatEffortRegistry)
|
||||
if !ok {
|
||||
return protocol.ChatEffortRequest{}, errors.New("durable chat thinking levels are not configured")
|
||||
}
|
||||
if err := efforter.SetEffort(ctx, sessionID, effort); err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
if err := registry.SetChatEffort(ctx, sessionID, effort); err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
} else if err := efforter.SetEffort(ctx, sessionID, effort); err != nil {
|
||||
return protocol.ChatEffortRequest{}, err
|
||||
}
|
||||
state.Effort = effort
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// applyStoredEffort hands a Codex or Claude chat's stored level to the harness
|
||||
// before a turn; it covers a restart that lost the adapter's in-memory level.
|
||||
func (m *chatManager) applyStoredEffort(ctx context.Context, adapter chatBroker, sessionID string) error {
|
||||
efforter, ok := adapter.(chatEfforter)
|
||||
if !ok || !isModelBackend(m.backendFor(ctx, sessionID)) {
|
||||
return nil
|
||||
}
|
||||
effort := m.storedEffort(ctx, sessionID)
|
||||
if effort == "" {
|
||||
return nil
|
||||
}
|
||||
return efforter.SetEffort(ctx, sessionID, effort)
|
||||
}
|
||||
|
||||
// reconcileEffort runs after a saved model switch: a stored level the new
|
||||
// model does not accept becomes that model's default (or the harness's own),
|
||||
// so the next turn never sends a level the model refuses.
|
||||
func (m *chatManager) reconcileEffort(ctx context.Context, sessionID string) error {
|
||||
stored := m.storedEffort(ctx, sessionID)
|
||||
if stored == "" {
|
||||
return nil
|
||||
}
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
efforter, ok := adapter.(chatEfforter)
|
||||
registry, stores := m.registry.(chatEffortRegistry)
|
||||
if !ok || !stores {
|
||||
return nil
|
||||
}
|
||||
session, found, err := m.Session(ctx, sessionID)
|
||||
if err != nil || !found || protocol.HasChatEffort(session.Efforts, stored) {
|
||||
return err
|
||||
}
|
||||
next := session.DefaultEffort
|
||||
if err := efforter.SetEffort(ctx, sessionID, next); err != nil {
|
||||
return err
|
||||
}
|
||||
return registry.SetChatEffort(ctx, sessionID, next)
|
||||
}
|
||||
|
||||
// handleChatEffort sets one chat's thinking level and echoes the stored level
|
||||
// with the model's levels.
|
||||
func handleChatEffort(ctx context.Context, request protocol.Message, broker chatBroker, write func(protocol.Message) error) {
|
||||
body := request.EffortRequest
|
||||
if body == nil || !validChatSessionID(body.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid chat session id is required"})
|
||||
return
|
||||
}
|
||||
setter, ok := broker.(interface {
|
||||
SetEffort(context.Context, string, string) (protocol.ChatEffortRequest, error)
|
||||
})
|
||||
if !ok {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: errChatEffortsUnsupported.Error()})
|
||||
return
|
||||
}
|
||||
reply, err := setter.SetEffort(ctx, body.SessionID, strings.TrimSpace(body.Effort))
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
_ = write(protocol.Message{Type: protocol.ChatEffortSelect, ID: request.ID, EffortRequest: &reply})
|
||||
}
|
||||
|
||||
// chatModelsEffort is the chat's current level for a chat_models reply, nil
|
||||
// when the broker cannot report one.
|
||||
func chatModelsEffort(ctx context.Context, broker chatBroker, sessionID string) *protocol.ChatEffortRequest {
|
||||
reporter, ok := broker.(interface {
|
||||
EffortState(context.Context, string) (protocol.ChatEffortRequest, error)
|
||||
})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
state, err := reporter.EffortState(ctx, sessionID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &state
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// effortedChat reports levels per model and records the levels handed to it.
|
||||
type effortedChat struct {
|
||||
*selectedModelChat
|
||||
levels map[string][]protocol.ChatEffort
|
||||
defaults map[string]string
|
||||
applied []string
|
||||
}
|
||||
|
||||
func (c *effortedChat) Efforts(_ context.Context, session protocol.ChatSession) ([]protocol.ChatEffort, string, error) {
|
||||
return c.levels[session.Model], c.defaults[session.Model], nil
|
||||
}
|
||||
|
||||
func (c *effortedChat) SetEffort(_ context.Context, _, effort string) error {
|
||||
if effort == "refused" {
|
||||
return errors.New("harness refused")
|
||||
}
|
||||
c.applied = append(c.applied, effort)
|
||||
return nil
|
||||
}
|
||||
|
||||
func effortFixture(t *testing.T, path, backend string) (*pipeline.Store, *effortedChat, string) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
store, err := pipeline.Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id := "01900000-0000-7000-8000-000000000003"
|
||||
if err := store.RecordOperatorSession(ctx, id, "/fixture", "chat", protocol.ChatSessionTagOperator); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SetOperatorSessionBackend(ctx, id, backend); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fake := &effortedChat{selectedModelChat: &selectedModelChat{fakeChat: scriptedChat()},
|
||||
levels: map[string][]protocol.ChatEffort{"thinker": {{ID: "low", Name: "Low"}, {ID: "high", Name: "High"}}, "other": {{ID: "high", Name: "High"}, {ID: "max", Name: "Max"}}},
|
||||
defaults: map[string]string{"thinker": "high", "other": "max"},
|
||||
}
|
||||
fake.models = []protocol.ChatModel{{ID: "thinker", Provider: "prov"}, {ID: "other", Provider: "prov"}, {ID: "plain", Provider: "prov"}}
|
||||
fake.sessionRecord = protocol.ChatSession{ID: id, Backend: backend, Model: "thinker", ModelProvider: "prov"}
|
||||
fake.sessionFound = true
|
||||
fake.sessions = []protocol.ChatSession{fake.sessionRecord}
|
||||
return store, fake, id
|
||||
}
|
||||
|
||||
func TestChatEffortIsValidatedStoredAndReappliedAfterRestart(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
path := filepath.Join(t.TempDir(), "chat.db")
|
||||
store, fake, id := effortFixture(t, path, "codex")
|
||||
manager := &chatManager{codex: fake, registry: store, cache: map[string]string{}}
|
||||
var reply protocol.Message
|
||||
capture := func(msg protocol.Message) error { reply = msg; return nil }
|
||||
|
||||
session, _, err := manager.Session(ctx, id)
|
||||
if err != nil || session.Effort != "" || session.DefaultEffort != "high" || len(session.Efforts) != 2 {
|
||||
t.Fatalf("fresh row = %+v, %v", session, err)
|
||||
}
|
||||
for _, bad := range []string{"max", "refused"} {
|
||||
handleChatEffort(ctx, protocol.Message{ID: "bad", EffortRequest: &protocol.ChatEffortRequest{SessionID: id, Effort: bad}}, manager, capture)
|
||||
if reply.Type != protocol.Error {
|
||||
t.Fatalf("level %q accepted: %+v", bad, reply)
|
||||
}
|
||||
}
|
||||
handleChatEffort(ctx, protocol.Message{ID: "set", EffortRequest: &protocol.ChatEffortRequest{SessionID: id, Effort: "low"}}, manager, capture)
|
||||
if reply.Type != protocol.ChatEffortSelect || reply.ID != "set" || reply.EffortRequest.Effort != "low" || len(reply.EffortRequest.Efforts) != 2 || reply.EffortRequest.DefaultEffort != "high" {
|
||||
t.Fatalf("set reply = %+v", reply)
|
||||
}
|
||||
if len(fake.applied) != 1 || fake.applied[0] != "low" || fake.overrides != 0 {
|
||||
t.Fatalf("applied %v, turns %d", fake.applied, fake.overrides)
|
||||
}
|
||||
handleChatModels(ctx, protocol.Message{ID: "models", ChatQuery: &protocol.ChatQuery{SessionID: id}}, manager, capture)
|
||||
if reply.Type != protocol.ChatModels || reply.EffortRequest == nil || reply.EffortRequest.Effort != "low" {
|
||||
t.Fatalf("models reply = %+v", reply)
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// A restarted server lists the stored level and re-applies it before turns.
|
||||
store, err = pipeline.Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
fake.applied = nil
|
||||
manager = &chatManager{codex: fake, registry: store, cache: map[string]string{}}
|
||||
list, err := manager.Sessions(ctx)
|
||||
if err != nil || len(list) != 1 || list[0].Effort != "low" || len(list[0].Efforts) != 2 {
|
||||
t.Fatalf("restarted list = %+v, %v", list, err)
|
||||
}
|
||||
if err := manager.Prompt(ctx, id, "hello"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := manager.PromptWithMessageIDFiles(ctx, id, "again", "msg", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(fake.applied) != 2 || fake.applied[0] != "low" || fake.applied[1] != "low" {
|
||||
t.Fatalf("stored level not re-applied before turns: %v", fake.applied)
|
||||
}
|
||||
|
||||
// A model that keeps the level keeps it; one without it falls back to its
|
||||
// default; one without levels clears it and offers no control.
|
||||
for _, step := range []struct{ model, stored string }{{"thinker", "low"}, {"other", "max"}, {"plain", ""}} {
|
||||
handleChatModelSwitch(ctx, protocol.Message{ID: "m", ModelRequest: &protocol.ChatModelRequest{SessionID: id, Provider: "prov", Model: step.model}}, manager, capture)
|
||||
if reply.Type != protocol.ChatModelSelect {
|
||||
t.Fatalf("switch reply = %+v", reply)
|
||||
}
|
||||
if stored, err := store.ChatEffort(ctx, id); err != nil || stored != step.stored {
|
||||
t.Fatalf("after switching to %s stored %q, want %q (%v)", step.model, stored, step.stored, err)
|
||||
}
|
||||
}
|
||||
session, _, err = manager.Session(ctx, id)
|
||||
if err != nil || session.Effort != "" || len(session.Efforts) != 0 || session.DefaultEffort != "" {
|
||||
t.Fatalf("level-less model row = %+v, %v", session, err)
|
||||
}
|
||||
handleChatEffort(ctx, protocol.Message{ID: "none", EffortRequest: &protocol.ChatEffortRequest{SessionID: id, Effort: "high"}}, manager, capture)
|
||||
if reply.Type != protocol.Error || reply.Error != errChatEffortsNone.Error() {
|
||||
t.Fatalf("level-less model accepted a level: %+v", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenCodeEffortStaysNativeAndUnsupportedHarnessOffersNone(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store, fake, id := effortFixture(t, filepath.Join(t.TempDir(), "chat.db"), "opencode")
|
||||
defer store.Close()
|
||||
fake.sessionRecord.Effort = "high"
|
||||
fake.sessions = []protocol.ChatSession{fake.sessionRecord}
|
||||
manager := &chatManager{opencode: fake, registry: store, cache: map[string]string{}}
|
||||
session, _, err := manager.Session(ctx, id)
|
||||
if err != nil || session.Effort != "high" || len(session.Efforts) != 2 {
|
||||
t.Fatalf("native level row = %+v, %v", session, err)
|
||||
}
|
||||
state, err := manager.SetEffort(ctx, id, "low")
|
||||
if err != nil || state.Effort != "low" || len(fake.applied) != 1 {
|
||||
t.Fatalf("native set = %+v, %v (applied %v)", state, err, fake.applied)
|
||||
}
|
||||
if stored, _ := store.ChatEffort(ctx, id); stored != "" {
|
||||
t.Fatalf("OpenCode level stored by Pipelines: %q", stored)
|
||||
}
|
||||
// The variant is OpenCode's own state; a turn never re-sends it.
|
||||
if err := manager.Prompt(ctx, id, "hi"); err != nil || len(fake.applied) != 1 {
|
||||
t.Fatalf("turn re-applied a native level: %v %v", fake.applied, err)
|
||||
}
|
||||
|
||||
plain := scriptedChat()
|
||||
plain.sessionRecord = protocol.ChatSession{ID: id, Backend: "opencode", Model: "thinker", ModelProvider: "prov", Effort: "high"}
|
||||
plain.sessionFound = true
|
||||
manager = &chatManager{opencode: plain, registry: store, cache: map[string]string{}}
|
||||
session, _, err = manager.Session(ctx, id)
|
||||
if err != nil || session.Effort != "" || len(session.Efforts) != 0 {
|
||||
t.Fatalf("unsupported harness row = %+v, %v", session, err)
|
||||
}
|
||||
var reply protocol.Message
|
||||
handleChatEffort(ctx, protocol.Message{ID: "x", EffortRequest: &protocol.ChatEffortRequest{SessionID: id, Effort: "high"}}, manager, func(msg protocol.Message) error { reply = msg; return nil })
|
||||
if reply.Type != protocol.Error || reply.Error != errChatEffortsUnsupported.Error() {
|
||||
t.Fatalf("unsupported harness reply = %+v", reply)
|
||||
}
|
||||
}
|
||||
@@ -395,7 +395,7 @@ func (m *chatManager) CreateBackend(ctx context.Context, title, directory, backe
|
||||
m.mu.Unlock()
|
||||
// The created row names its mode like a listed one, so the opened chat
|
||||
// shows the mode control at once rather than after the list re-reads.
|
||||
return m.withMode(ctx, session), nil
|
||||
return m.withEffort(ctx, m.withMode(ctx, session)), nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Create(ctx context.Context, title, directory string) (protocol.ChatSession, error) {
|
||||
@@ -414,6 +414,9 @@ func (m *chatManager) PromptWithMessageID(ctx context.Context, sessionID, text,
|
||||
if err := m.applyStoredMode(ctx, adapter, sessionID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.applyStoredEffort(ctx, adapter, sessionID); err != nil {
|
||||
return err
|
||||
}
|
||||
if isModelBackend(m.backendFor(ctx, sessionID)) {
|
||||
model, err := m.promptModel(ctx, adapter, sessionID)
|
||||
if err != nil {
|
||||
@@ -469,6 +472,9 @@ func (m *chatManager) PromptWithMessageIDFiles(ctx context.Context, sessionID, t
|
||||
if err := m.applyStoredMode(ctx, adapter, sessionID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.applyStoredEffort(ctx, adapter, sessionID); err != nil {
|
||||
return err
|
||||
}
|
||||
if isModelBackend(m.backendFor(ctx, sessionID)) {
|
||||
model, err := m.promptModel(ctx, adapter, sessionID)
|
||||
if err != nil {
|
||||
@@ -582,7 +588,10 @@ func (m *chatManager) SwitchModel(ctx context.Context, sessionID, provider, mode
|
||||
if err := modeler.SwitchModel(ctx, sessionID, provider, model); err != nil {
|
||||
return err
|
||||
}
|
||||
return registry.SetChatModelSelection(ctx, sessionID, provider, model)
|
||||
if err := registry.SetChatModelSelection(ctx, sessionID, provider, model); err != nil {
|
||||
return err
|
||||
}
|
||||
return m.reconcileEffort(ctx, sessionID)
|
||||
}
|
||||
return modeler.SwitchModel(ctx, sessionID, provider, model)
|
||||
}
|
||||
@@ -609,7 +618,7 @@ func (m *chatManager) chatModelSelection(ctx context.Context, id string) (string
|
||||
func (m *chatManager) withModelSelection(ctx context.Context, session protocol.ChatSession) (protocol.ChatSession, error) {
|
||||
session = m.withMode(ctx, session)
|
||||
if !isModelBackend(session.Backend) {
|
||||
return session, nil
|
||||
return m.withEffort(ctx, session), nil
|
||||
}
|
||||
provider, model, err := m.chatModelSelection(ctx, session.ID)
|
||||
if err != nil {
|
||||
@@ -619,7 +628,7 @@ func (m *chatManager) withModelSelection(ctx context.Context, session protocol.C
|
||||
session.ModelProvider, session.Model = provider, model
|
||||
session.ModelSelection = "next_turn"
|
||||
}
|
||||
return session, nil
|
||||
return m.withEffort(ctx, session), nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Stream(ctx context.Context, sessionID string, ready func(), emit func(protocol.ChatEventFrame) error) error {
|
||||
|
||||
@@ -181,7 +181,7 @@ func handleChatModels(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
_ = write(protocol.Message{Type: protocol.ChatModels, ID: request.ID, ChatModels: models})
|
||||
_ = write(protocol.Message{Type: protocol.ChatModels, ID: request.ID, ChatModels: models, EffortRequest: chatModelsEffort(ctx, broker, query.SessionID)})
|
||||
}
|
||||
|
||||
// handleChatModelSwitch changes one session's model for subsequent turns.
|
||||
|
||||
Reference in New Issue
Block a user