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)