mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-16 14:15:20 +08:00
强制启用文件拆分(实际模型忽略)
This commit is contained in:
@@ -100,6 +100,7 @@ func (c *Config) NormalizeCredentials() {
|
||||
}
|
||||
|
||||
c.normalizeModelAliases()
|
||||
c.forceHistorySplitEnabled()
|
||||
}
|
||||
|
||||
// DropInvalidAccounts removes accounts that cannot be addressed by admin APIs
|
||||
@@ -140,6 +141,14 @@ func (c *Config) normalizeModelAliases() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) forceHistorySplitEnabled() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
enabled := true
|
||||
c.HistorySplit.Enabled = &enabled
|
||||
}
|
||||
|
||||
type CompatConfig struct {
|
||||
WideInputStrictOutput *bool `json:"wide_input_strict_output,omitempty"`
|
||||
StripReferenceMarkers *bool `json:"strip_reference_markers,omitempty"`
|
||||
|
||||
@@ -164,12 +164,7 @@ func (s *Store) AutoDeleteSessions() bool {
|
||||
}
|
||||
|
||||
func (s *Store) HistorySplitEnabled() bool {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
if s.cfg.HistorySplit.Enabled == nil {
|
||||
return true
|
||||
}
|
||||
return *s.cfg.HistorySplit.Enabled
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Store) HistorySplitTriggerAfterTurns() int {
|
||||
|
||||
@@ -18,10 +18,25 @@ func TestStoreHistorySplitAccessors(t *testing.T) {
|
||||
TriggerAfterTurns: &turns,
|
||||
}
|
||||
|
||||
if store.HistorySplitEnabled() {
|
||||
t.Fatal("expected history split disabled after override")
|
||||
if !store.HistorySplitEnabled() {
|
||||
t.Fatal("expected history split to stay enabled after legacy disabled override")
|
||||
}
|
||||
if got := store.HistorySplitTriggerAfterTurns(); got != 3 {
|
||||
t.Fatalf("history split trigger_after_turns=%d want=3", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreHistorySplitLegacyDisabledConfigNormalizesToEnabled(t *testing.T) {
|
||||
t.Setenv("DS2API_CONFIG_JSON", `{"keys":["k1"],"history_split":{"enabled":false,"trigger_after_turns":2}}`)
|
||||
store := LoadStore()
|
||||
if !store.HistorySplitEnabled() {
|
||||
t.Fatal("expected history split enabled when legacy config disables it")
|
||||
}
|
||||
snap := store.Snapshot()
|
||||
if snap.HistorySplit.Enabled == nil || !*snap.HistorySplit.Enabled {
|
||||
t.Fatalf("expected normalized history_split.enabled=true, got %#v", snap.HistorySplit.Enabled)
|
||||
}
|
||||
if got := store.HistorySplitTriggerAfterTurns(); got != 2 {
|
||||
t.Fatalf("history split trigger_after_turns=%d want=2", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,8 +189,8 @@ func TestUpdateSettingsHistorySplit(t *testing.T) {
|
||||
t.Fatalf("expected 200, got %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
snap := h.Store.Snapshot()
|
||||
if snap.HistorySplit.Enabled == nil || *snap.HistorySplit.Enabled {
|
||||
t.Fatalf("expected history_split.enabled=false, got %#v", snap.HistorySplit.Enabled)
|
||||
if snap.HistorySplit.Enabled == nil || !*snap.HistorySplit.Enabled {
|
||||
t.Fatalf("expected history_split.enabled to be forced true, got %#v", snap.HistorySplit.Enabled)
|
||||
}
|
||||
if snap.HistorySplit.TriggerAfterTurns == nil || *snap.HistorySplit.TriggerAfterTurns != 3 {
|
||||
t.Fatalf("expected history_split.trigger_after_turns=3, got %#v", snap.HistorySplit.TriggerAfterTurns)
|
||||
|
||||
@@ -152,10 +152,8 @@ func parseSettingsUpdateRequest(req map[string]any) (*config.AdminConfig, *confi
|
||||
|
||||
if raw, ok := req["history_split"].(map[string]any); ok {
|
||||
cfg := &config.HistorySplitConfig{}
|
||||
if v, exists := raw["enabled"]; exists {
|
||||
b := boolFrom(v)
|
||||
cfg.Enabled = &b
|
||||
}
|
||||
enabled := true
|
||||
cfg.Enabled = &enabled
|
||||
if v, exists := raw["trigger_after_turns"]; exists {
|
||||
n := intFrom(v)
|
||||
if err := config.ValidateIntRange("history_split.trigger_after_turns", n, 1, 1000, true); err != nil {
|
||||
|
||||
@@ -27,9 +27,6 @@ func (s Service) Apply(ctx context.Context, a *auth.RequestAuth, stdReq promptco
|
||||
if s.DS == nil || s.Store == nil || a == nil {
|
||||
return stdReq, nil
|
||||
}
|
||||
if !s.Store.HistorySplitEnabled() {
|
||||
return stdReq, nil
|
||||
}
|
||||
|
||||
promptMessages, historyMessages := SplitOpenAIHistoryMessages(stdReq.Messages, s.Store.HistorySplitTriggerAfterTurns())
|
||||
if len(historyMessages) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user