Codex's memories had a model of their own, its compaction did not. Codex's row has a compaction model square (compact_model, settings.CodexCompactModel), read by the gateway on each compaction (codexCompactTo, before codexCompact). Only a compaction magpie makes is moved: it asks for a plain-text summary any model reads back. One a ChatGPT account seals, or a pick that compacts natively, is left, since only the writing account reads it (#1099); a disabled, unserved or key-barred pick is left with a log line. The text sent to the model is unchanged. Run on mote: TestCodexCompactOnItsOwnModel (red with the move taken out) and TestCodexCompactToLeavesNative; go test for gui, settings, settingsapi, agent, provider, gateway; darwin, linux and windows vet; the GUI files in both engines. Not tried: a real Codex session compacting on the chosen model.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// CodexCompactModel is the model Codex's compactions made by magpie are
|
|
// put on, "" for the session's own. A provider renamed since it was set is
|
|
// named by its new id (RenamedRef).
|
|
func CodexCompactModel() string {
|
|
id := strings.TrimSpace(heldSettings().CodexCompactModel)
|
|
if id == "" {
|
|
return ""
|
|
}
|
|
return RenamedRef(id)
|
|
}
|
|
|
|
// SetCodexCompactModel puts Codex's compactions on id, a model or routing
|
|
// group of magpie's (provider/model, group/<id>); "" leaves each on the
|
|
// session's model. One magpie doesn't serve now is kept all the same: the
|
|
// gateway leaves compactions where they are until it is served.
|
|
func SetCodexCompactModel(id string) error {
|
|
id = strings.TrimSpace(id)
|
|
if pid, model, ok := strings.Cut(id, "/"); id != "" && (!ok || pid == "" || model == "") {
|
|
return fmt.Errorf("Codex's compaction can't be put on %q: pick one of magpie's models (provider/model)", id)
|
|
}
|
|
s := settings.Load()
|
|
if s.CodexCompactModel == id {
|
|
return nil
|
|
}
|
|
s.CodexCompactModel = id
|
|
if err := settings.Save(s); err != nil {
|
|
return err
|
|
}
|
|
Changed()
|
|
return nil
|
|
}
|