From fdfc7297defc8bafe7c6b5fd4180ad1c1524275a Mon Sep 17 00:00:00 2001 From: lawrence Date: Wed, 1 Jul 2026 11:08:03 +0800 Subject: [PATCH] fix(vlm): allow configurable temperature for VLM models Some VLM models (e.g. certain vision models) only accept temperature=1. Previously temperature was hardcoded to 0.1. Now reads from model's ExtraConfig["temperature"] with fallback to default 0.1. Usage: set ExtraConfig.temperature=1 in the VLM model configuration. --- internal/models/vlm/remote_api.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/internal/models/vlm/remote_api.go b/internal/models/vlm/remote_api.go index 46747bbf..e82b8339 100644 --- a/internal/models/vlm/remote_api.go +++ b/internal/models/vlm/remote_api.go @@ -40,10 +40,11 @@ func vlmHTTPTimeout() time.Duration { // RemoteAPIVLM implements VLM via an OpenAI-compatible chat completions API. type RemoteAPIVLM struct { - modelName string - modelID string - client *openai.Client - baseURL string + modelName string + modelID string + client *openai.Client + baseURL string + temperature float32 } // NewRemoteAPIVLM creates a remote-API backed VLM instance. @@ -81,11 +82,23 @@ func NewRemoteAPIVLM(config *Config) (*RemoteAPIVLM, error) { apiCfg.HTTPClient = httpClient } + temp := defaultTemp + if config.Extra != nil { + if v, ok := config.Extra["temperature"]; ok { + if vs, ok := v.(string); ok { + if f, err := strconv.ParseFloat(vs, 32); err == nil { + temp = float32(f) + } + } + } + } + return &RemoteAPIVLM{ - modelName: config.ModelName, - modelID: config.ModelID, - client: openai.NewClientWithConfig(apiCfg), - baseURL: config.BaseURL, + modelName: config.ModelName, + modelID: config.ModelID, + client: openai.NewClientWithConfig(apiCfg), + baseURL: config.BaseURL, + temperature: temp, }, nil } @@ -124,7 +137,7 @@ func (v *RemoteAPIVLM) Predict(ctx context.Context, imgBytesList [][]byte, promp }, }, MaxTokens: defaultMaxToks, - Temperature: defaultTemp, + Temperature: v.temperature, } totalImageSize := 0