返回 DeepSeek-Reasonix
stepfun_context.go
根目录 / internal / config / stepfun_context.go
1 package config
2
3 import (
4 "slices"
5 "strings"
6 )
7
8 // stepfunContextWindow is the limit StepFun serves for every model its presets
9 // list; the API refuses a request above 262144 tokens.
10 const stepfunContextWindow = 262_144
11
12 var stepfunPresetIDs = []string{"stepfun", "stepfun-responses", "stepfun-anthropic", "stepfun-api", "stepfun-api-anthropic"}
13
14 // normalizeLegacyStepFunContextWindows gives an installed StepFun preset that
15 // still has no window the one its preset declares. A zero window turns
16 // automatic compaction off, so the session grows until the API refuses it.
17 // Either official host counts, since the region is the user's; a custom
18 // endpoint, a model StepFun does not serve, or any window already set stays.
19 func normalizeLegacyStepFunContextWindows(c *Config) bool {
20 if c == nil {
21 return false
22 }
23 changed := false
24 for i := range c.Providers {
25 p := &c.Providers[i]
26 presetID := strings.TrimSpace(p.PresetID)
27 if p.ContextWindow != 0 || !slices.Contains(stepfunPresetIDs, presetID) {
28 continue
29 }
30 preset, ok := CuratedProviderPreset(presetID)
31 if !ok || len(preset.Entries) != 1 {
32 continue
33 }
34 canonical := preset.Entries[0]
35 if canonical.ContextWindow <= 0 ||
36 !strings.EqualFold(strings.TrimSpace(p.Kind), strings.TrimSpace(canonical.Kind)) ||
37 !stepfunOfficialBaseURL(p.BaseURL, canonical.BaseURL) ||
38 !stepfunServesAll(p.ModelList(), canonical.Models) {
39 continue
40 }
41 p.ContextWindow = canonical.ContextWindow
42 changed = true
43 }
44 return changed
45 }
46
47 func stepfunOfficialBaseURL(raw, canonical string) bool {
48 got := normalizedBaseURLForMigration(raw)
49 want := normalizedBaseURLForMigration(canonical)
50 return got == want || got == strings.Replace(want, "://api.stepfun.com", "://api.stepfun.ai", 1)
51 }
52
53 func stepfunServesAll(models, served []string) bool {
54 if len(models) == 0 {
55 return false
56 }
57 for _, m := range models {
58 if !slices.Contains(served, strings.TrimSpace(m)) {
59 return false
60 }
61 }
62 return true
63 }
64
64 lines GO