feat(llm): WithTemperature, default unchanged

Zero is sent as zero (the field has no omitempty). The reconciler's measured accuracy
was at temperature 0, so it runs there; every other caller keeps 0.2.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 23:25:10 +02:00
co-authored by Claude Sonnet 5.5
parent 7891675393
commit 505670c0e1
+12 -1
View File
@@ -25,12 +25,16 @@ import (
// docs/homelab-integration.md.
const defaultMaxTokens = 8192
// defaultTemperature is what every caller got before WithTemperature existed.
const defaultTemperature = 0.2
// Client calls an OpenAI-compatible chat completions endpoint.
type Client struct {
baseURL string
apiKey string
model string
maxTokens int
temp float64
httpClient *http.Client
usageHook func(model string, prompt, completion int)
}
@@ -51,6 +55,12 @@ func WithMaxTokens(n int) Option {
}
}
// WithTemperature overrides the sampling temperature. Zero IS a valid value and is sent
// as zero: the reconciler's accuracy was measured at temperature 0 and must run there.
func WithTemperature(t float64) Option {
return func(c *Client) { c.temp = t }
}
// WithUsageHook registers a callback fired after a successful completion with the
// model and the prompt/completion token counts from the response usage block. It
// keeps this copied, stdlib-only package (ADR-004) decoupled from metrics: the
@@ -66,6 +76,7 @@ func New(baseURL, apiKey, model string, timeout time.Duration, opts ...Option) *
apiKey: apiKey,
model: model,
maxTokens: defaultMaxTokens,
temp: defaultTemperature,
httpClient: &http.Client{Timeout: timeout},
}
for _, opt := range opts {
@@ -105,7 +116,7 @@ func (c *Client) Complete(ctx context.Context, system, user string) (string, err
{Role: "system", Content: system},
{Role: "user", Content: user},
},
Temperature: 0.2,
Temperature: c.temp,
MaxTokens: c.maxTokens,
}
b, err := json.Marshal(body)