-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
97 lines (79 loc) · 2.29 KB
/
options.go
File metadata and controls
97 lines (79 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package tok
import "github.com/GrayCodeAI/tok/internal/filter"
// Option configures compression behavior.
type Option interface {
apply(*config)
}
// Pre-built option presets (use directly as options).
var (
Minimal Option = WithMode(ModeMinimal)
Aggressive Option = WithMode(ModeAggressive)
Surface Option = WithTier(TierSurface)
Adaptive Option = WithTier(TierAdaptive)
Code Option = WithTier(TierCode)
Log Option = WithTier(TierLog)
)
// Mode controls compression aggressiveness.
type Mode string
const (
ModeMinimal Mode = "minimal"
ModeAggressive Mode = "aggressive"
)
// Tier selects a pre-built pipeline profile.
type Tier string
const (
TierSurface Tier = "surface" // 4 layers, fast
TierTrim Tier = "trim" // 8 layers, balanced
TierExtract Tier = "extract" // 20 layers, max compression
TierCore Tier = "core" // 20 layers, quality-first
TierCode Tier = "code" // code-aware
TierLog Tier = "log" // log-aware
TierThread Tier = "thread" // conversation-aware
TierAdaptive Tier = "adaptive" // auto-detect content type
)
// WithMode sets the compression mode.
func WithMode(m Mode) Option {
return optFunc(func(c *config) { c.mode = m })
}
// WithBudget sets a hard token limit for the output.
func WithBudget(tokens int) Option {
return optFunc(func(c *config) { c.budget = tokens })
}
// WithQuery provides intent context for goal-driven filtering.
func WithQuery(intent string) Option {
return optFunc(func(c *config) { c.query = intent })
}
// WithTier selects a pipeline profile.
func WithTier(t Tier) Option {
return optFunc(func(c *config) { c.tier = t })
}
type optFunc func(*config)
func (f optFunc) apply(c *config) { f(c) }
type config struct {
mode Mode
budget int
query string
tier Tier
}
func buildConfig(opts []Option) config {
cfg := config{mode: ModeMinimal}
for _, opt := range opts {
opt.apply(&cfg)
}
return cfg
}
func (c *config) toPipelineConfig() filter.PipelineConfig {
mode := filter.ModeMinimal
if c.mode == ModeAggressive {
mode = filter.ModeAggressive
}
var cfg filter.PipelineConfig
if c.tier != "" {
cfg = filter.TierConfig(filter.Tier(c.tier), mode)
} else {
cfg = filter.TierConfig(filter.TierCore, mode)
}
cfg.Budget = c.budget
cfg.QueryIntent = c.query
return cfg
}