-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_shared.go
More file actions
111 lines (104 loc) · 2.2 KB
/
Copy pathcommand_shared.go
File metadata and controls
111 lines (104 loc) · 2.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package contexting
import "os"
type CommonFlags struct {
OutputPath string
SynonymCache string
Model string
APIKey string
Endpoint string
BatchSize int
SynonymsPerName int
SynonymsMin int
SynonymsMax int
Verbose bool
ExtraIgnores []string
}
func (c *CommonFlags) normalize() {
// BatchSize 0 means smart batching (up to 1000 names per request)
if c.SynonymsPerName <= 0 {
c.SynonymsPerName = defaultSynonyms
}
// Resolve synonyms min/max: if set, use them; otherwise fall back to SynonymsPerName
if c.SynonymsMin <= 0 {
c.SynonymsMin = c.SynonymsPerName
}
if c.SynonymsMax <= 0 {
c.SynonymsMax = defaultSynonymsMax
}
if c.SynonymsMin > c.SynonymsMax {
c.SynonymsMin = c.SynonymsMax
}
if c.SynonymCache == "" {
c.SynonymCache = ".ctxt/ctx_cache.json"
}
}
func resolveAPIKey(flagValue string) string {
if flagValue != "" {
return flagValue
}
key, err := GetAPIKey()
if err != nil {
return ""
}
return key
}
func resolveLLMConfig(flags CommonFlags, llmCfg LLMConfig) (endpoint, model, apiKey string, temperature float64, maxTokens int, provider string) {
provider = llmCfg.Provider
if provider == "" {
provider = "openrouter"
}
endpoint = flags.Endpoint
if endpoint == "" {
endpoint = llmCfg.Endpoint
}
if endpoint == "" {
endpoint = defaultEndpoint
}
model = flags.Model
if model == "" {
model = llmCfg.Model
}
if model == "" {
model = defaultModel
}
apiKey = flags.APIKey
if apiKey == "" {
apiKey = llmCfg.APIKey
}
if apiKey == "" {
keyEnv := llmCfg.APIKeyEnv
if keyEnv != "" {
apiKey = os.Getenv(keyEnv)
}
}
if apiKey == "" {
apiKey = os.Getenv("LLM_API_KEY")
}
if apiKey == "" {
apiKey = os.Getenv("OPENROUTER_API_KEY")
}
temperature = llmCfg.Temperature
if temperature == 0 {
temperature = 0.9
}
maxTokens = llmCfg.MaxTokens
return
}
func maskAPIKey(key string) string {
if key == "" {
return "[not set]"
}
if len(key) <= 8 {
return key[:max(1, len(key)/2)] + "..."
}
return key[:8] + "..."
}
func emitSynonymWarning(err error) {
if err == nil {
return
}
if isCanceledError(err) {
return
}
LogWarnf("synonym generation failed, continuing without synonyms: %v", err)
}