cfg: expose all generation params in session cfg file

This commit is contained in:
Levi Neely 2026-05-16 07:32:24 +02:00
parent 73b166d276
commit 5b86ff06fb
1 changed files with 266 additions and 0 deletions

View File

@ -255,11 +255,32 @@ func (h *sessionHelper) cfgContent() string {
fmt.Fprintf(&sb, "agent=%s\n", h.sess.Core.AgentName())
fmt.Fprintf(&sb, "cwd=%s\n", h.sess.Core.CWD())
fmt.Fprintf(&sb, "maxTokens=%d\n", p.MaxTokens)
fmt.Fprintf(&sb, "maxCompletionTokens=%d\n", p.MaxCompletionTokens)
if p.Temperature != nil {
fmt.Fprintf(&sb, "temperature=%g\n", *p.Temperature)
} else {
sb.WriteString("temperature=\n")
}
if p.TopP != nil {
fmt.Fprintf(&sb, "topP=%g\n", *p.TopP)
} else {
sb.WriteString("topP=\n")
}
if p.TopK != nil {
fmt.Fprintf(&sb, "topK=%d\n", *p.TopK)
} else {
sb.WriteString("topK=\n")
}
if p.MinP != nil {
fmt.Fprintf(&sb, "minP=%g\n", *p.MinP)
} else {
sb.WriteString("minP=\n")
}
if p.TopA != nil {
fmt.Fprintf(&sb, "topA=%g\n", *p.TopA)
} else {
sb.WriteString("topA=\n")
}
if p.FrequencyPenalty != nil {
fmt.Fprintf(&sb, "frequencyPenalty=%g\n", *p.FrequencyPenalty)
} else {
@ -270,6 +291,37 @@ func (h *sessionHelper) cfgContent() string {
} else {
sb.WriteString("presencePenalty=\n")
}
if p.RepetitionPenalty != nil {
fmt.Fprintf(&sb, "repetitionPenalty=%g\n", *p.RepetitionPenalty)
} else {
sb.WriteString("repetitionPenalty=\n")
}
fmt.Fprintf(&sb, "reasoning=%d\n", p.ThinkingBudget)
if p.ReasoningEffort != "" {
fmt.Fprintf(&sb, "reasoningEffort=%s\n", p.ReasoningEffort)
} else {
sb.WriteString("reasoningEffort=\n")
}
if p.IncludeReasoning != nil {
fmt.Fprintf(&sb, "includeReasoning=%t\n", *p.IncludeReasoning)
} else {
sb.WriteString("includeReasoning=\n")
}
if p.ResponseFormat != "" {
fmt.Fprintf(&sb, "responseFormat=%s\n", p.ResponseFormat)
} else {
sb.WriteString("responseFormat=\n")
}
if len(p.Stop) > 0 {
fmt.Fprintf(&sb, "stop=%s\n", strings.Join(p.Stop, ","))
} else {
sb.WriteString("stop=\n")
}
if p.Verbosity != "" {
fmt.Fprintf(&sb, "verbosity=%s\n", p.Verbosity)
} else {
sb.WriteString("verbosity=\n")
}
return sb.String()
}
@ -309,6 +361,13 @@ func (h *sessionHelper) handleCfg(input string) error {
} else if n, err := strconv.Atoi(v); err == nil {
p.MaxTokens = n
}
case "maxCompletionTokens":
hasParams = true
if v == "" {
p.MaxCompletionTokens = 0
} else if n, err := strconv.Atoi(v); err == nil {
p.MaxCompletionTokens = n
}
case "temperature":
hasParams = true
if v == "" {
@ -316,6 +375,34 @@ func (h *sessionHelper) handleCfg(input string) error {
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.Temperature = &f
}
case "topP":
hasParams = true
if v == "" {
p.TopP = nil
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.TopP = &f
}
case "topK":
hasParams = true
if v == "" {
p.TopK = nil
} else if n, err := strconv.Atoi(v); err == nil {
p.TopK = &n
}
case "minP":
hasParams = true
if v == "" {
p.MinP = nil
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.MinP = &f
}
case "topA":
hasParams = true
if v == "" {
p.TopA = nil
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.TopA = &f
}
case "frequencyPenalty":
hasParams = true
if v == "" {
@ -330,6 +417,44 @@ func (h *sessionHelper) handleCfg(input string) error {
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.PresencePenalty = &f
}
case "repetitionPenalty":
hasParams = true
if v == "" {
p.RepetitionPenalty = nil
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
p.RepetitionPenalty = &f
}
case "reasoning":
hasParams = true
if v == "" {
p.ThinkingBudget = 0
} else if n, err := strconv.Atoi(v); err == nil {
p.ThinkingBudget = n
}
case "reasoningEffort":
hasParams = true
p.ReasoningEffort = v
case "includeReasoning":
hasParams = true
if v == "" {
p.IncludeReasoning = nil
} else {
b := v == "true"
p.IncludeReasoning = &b
}
case "responseFormat":
hasParams = true
p.ResponseFormat = v
case "stop":
hasParams = true
if v == "" {
p.Stop = nil
} else {
p.Stop = strings.Split(v, ",")
}
case "verbosity":
hasParams = true
p.Verbosity = v
// state → read-only, silently ignored
}
}
@ -411,11 +536,32 @@ func (h *sessionHelper) handleCtl(input string) error {
func FormatParams(p backend.GenerationParams) string {
var sb strings.Builder
fmt.Fprintf(&sb, "maxTokens=%d\n", p.MaxTokens)
fmt.Fprintf(&sb, "maxCompletionTokens=%d\n", p.MaxCompletionTokens)
if p.Temperature != nil {
fmt.Fprintf(&sb, "temperature=%g\n", *p.Temperature)
} else {
fmt.Fprintf(&sb, "temperature=\n")
}
if p.TopP != nil {
fmt.Fprintf(&sb, "topP=%g\n", *p.TopP)
} else {
fmt.Fprintf(&sb, "topP=\n")
}
if p.TopK != nil {
fmt.Fprintf(&sb, "topK=%d\n", *p.TopK)
} else {
fmt.Fprintf(&sb, "topK=\n")
}
if p.MinP != nil {
fmt.Fprintf(&sb, "minP=%g\n", *p.MinP)
} else {
fmt.Fprintf(&sb, "minP=\n")
}
if p.TopA != nil {
fmt.Fprintf(&sb, "topA=%g\n", *p.TopA)
} else {
fmt.Fprintf(&sb, "topA=\n")
}
if p.FrequencyPenalty != nil {
fmt.Fprintf(&sb, "frequencyPenalty=%g\n", *p.FrequencyPenalty)
} else {
@ -426,6 +572,37 @@ func FormatParams(p backend.GenerationParams) string {
} else {
fmt.Fprintf(&sb, "presencePenalty=\n")
}
if p.RepetitionPenalty != nil {
fmt.Fprintf(&sb, "repetitionPenalty=%g\n", *p.RepetitionPenalty)
} else {
fmt.Fprintf(&sb, "repetitionPenalty=\n")
}
fmt.Fprintf(&sb, "reasoning=%d\n", p.ThinkingBudget)
if p.ReasoningEffort != "" {
fmt.Fprintf(&sb, "reasoningEffort=%s\n", p.ReasoningEffort)
} else {
fmt.Fprintf(&sb, "reasoningEffort=\n")
}
if p.IncludeReasoning != nil {
fmt.Fprintf(&sb, "includeReasoning=%t\n", *p.IncludeReasoning)
} else {
fmt.Fprintf(&sb, "includeReasoning=\n")
}
if p.ResponseFormat != "" {
fmt.Fprintf(&sb, "responseFormat=%s\n", p.ResponseFormat)
} else {
fmt.Fprintf(&sb, "responseFormat=\n")
}
if len(p.Stop) > 0 {
fmt.Fprintf(&sb, "stop=%s\n", strings.Join(p.Stop, ","))
} else {
fmt.Fprintf(&sb, "stop=\n")
}
if p.Verbosity != "" {
fmt.Fprintf(&sb, "verbosity=%s\n", p.Verbosity)
} else {
fmt.Fprintf(&sb, "verbosity=\n")
}
return sb.String()
}
@ -450,6 +627,16 @@ func ParseParams(input string, current backend.GenerationParams) (backend.Genera
}
p.MaxTokens = n
}
case "maxCompletionTokens":
if v == "" {
p.MaxCompletionTokens = 0
} else {
n, err := strconv.Atoi(v)
if err != nil {
return p, fmt.Errorf("invalid maxCompletionTokens: %s", v)
}
p.MaxCompletionTokens = n
}
case "temperature":
if v == "" {
p.Temperature = nil
@ -460,6 +647,46 @@ func ParseParams(input string, current backend.GenerationParams) (backend.Genera
}
p.Temperature = &f
}
case "topP":
if v == "" {
p.TopP = nil
} else {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return p, fmt.Errorf("invalid topP: %s", v)
}
p.TopP = &f
}
case "topK":
if v == "" {
p.TopK = nil
} else {
n, err := strconv.Atoi(v)
if err != nil {
return p, fmt.Errorf("invalid topK: %s", v)
}
p.TopK = &n
}
case "minP":
if v == "" {
p.MinP = nil
} else {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return p, fmt.Errorf("invalid minP: %s", v)
}
p.MinP = &f
}
case "topA":
if v == "" {
p.TopA = nil
} else {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return p, fmt.Errorf("invalid topA: %s", v)
}
p.TopA = &f
}
case "frequencyPenalty":
if v == "" {
p.FrequencyPenalty = nil
@ -480,6 +707,45 @@ func ParseParams(input string, current backend.GenerationParams) (backend.Genera
}
p.PresencePenalty = &f
}
case "repetitionPenalty":
if v == "" {
p.RepetitionPenalty = nil
} else {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return p, fmt.Errorf("invalid repetitionPenalty: %s", v)
}
p.RepetitionPenalty = &f
}
case "reasoning":
if v == "" {
p.ThinkingBudget = 0
} else {
n, err := strconv.Atoi(v)
if err != nil {
return p, fmt.Errorf("invalid reasoning: %s", v)
}
p.ThinkingBudget = n
}
case "reasoningEffort":
p.ReasoningEffort = v
case "includeReasoning":
if v == "" {
p.IncludeReasoning = nil
} else {
b := v == "true"
p.IncludeReasoning = &b
}
case "responseFormat":
p.ResponseFormat = v
case "stop":
if v == "" {
p.Stop = nil
} else {
p.Stop = strings.Split(v, ",")
}
case "verbosity":
p.Verbosity = v
}
}
return p, nil