diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 04:06:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 04:06:39 +0200 |
| commit | d985ff9b90cb8476301b2b611023a4332b47a2f0 (patch) | |
| tree | fa5987d2633991182f90805155b509dd6f3a1125 /internal/llmutils/temperature.go | |
| parent | 8f31040cc388943601cfd8a026ea85f0790e66c2 (diff) | |
Centralize GPT-5 temperature override into llmutils.ResolveTemperature
Eliminates identical temperature resolution logic duplicated in
hexaiaction, hexaicli, and lsp packages.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/llmutils/temperature.go')
| -rw-r--r-- | internal/llmutils/temperature.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/llmutils/temperature.go b/internal/llmutils/temperature.go new file mode 100644 index 0000000..8e10c66 --- /dev/null +++ b/internal/llmutils/temperature.go @@ -0,0 +1,37 @@ +// Package llmutils provides shared utilities for LLM configuration. +// ResolveTemperature centralizes the GPT-5 temperature override logic +// that was previously duplicated across hexaiaction, hexaicli, and lsp. +package llmutils + +import "strings" + +// isGPT5 returns true when the model name indicates an OpenAI GPT-5 variant. +func isGPT5(provider, model string) bool { + return provider == "openai" && + strings.HasPrefix(strings.ToLower(model), "gpt-5") +} + +// ResolveTemperature picks the effective temperature from an optional +// per-surface override (entryTemp) or the global coding temperature +// (codingTemp). For OpenAI GPT-5 models the default coding temperature +// of 0.2 is automatically raised to 1.0, and when no temperature is +// configured at all GPT-5 defaults to 1.0. +// +// Returns (temperature, true) when a value was resolved, or (0, false) +// when no temperature should be sent (let the provider choose). +func ResolveTemperature(provider, model string, entryTemp, codingTemp *float64) (float64, bool) { + if entryTemp != nil { + return *entryTemp, true + } + if codingTemp != nil { + temp := *codingTemp + if isGPT5(provider, model) && temp == 0.2 { + temp = 1.0 + } + return temp, true + } + if isGPT5(provider, model) { + return 1.0, true + } + return 0, false +} |
