From 505670c0e1c32e2e37515539f37d2a31b73fa6eb Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 1 Oct 2026 23:25:10 +0200 Subject: [PATCH] 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 --- internal/adapters/llm/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/adapters/llm/client.go b/internal/adapters/llm/client.go index f2fc1a6..5ced970 100644 --- a/internal/adapters/llm/client.go +++ b/internal/adapters/llm/client.go @@ -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)