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.
This commit is contained in:
lawrence
2026-07-01 11:08:03 +08:00
committed by lyingbug
parent 9682ad67a6
commit fdfc7297de
+22 -9
View File
@@ -40,10 +40,11 @@ func vlmHTTPTimeout() time.Duration {
// RemoteAPIVLM implements VLM via an OpenAI-compatible chat completions API. // RemoteAPIVLM implements VLM via an OpenAI-compatible chat completions API.
type RemoteAPIVLM struct { type RemoteAPIVLM struct {
modelName string modelName string
modelID string modelID string
client *openai.Client client *openai.Client
baseURL string baseURL string
temperature float32
} }
// NewRemoteAPIVLM creates a remote-API backed VLM instance. // NewRemoteAPIVLM creates a remote-API backed VLM instance.
@@ -81,11 +82,23 @@ func NewRemoteAPIVLM(config *Config) (*RemoteAPIVLM, error) {
apiCfg.HTTPClient = httpClient 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{ return &RemoteAPIVLM{
modelName: config.ModelName, modelName: config.ModelName,
modelID: config.ModelID, modelID: config.ModelID,
client: openai.NewClientWithConfig(apiCfg), client: openai.NewClientWithConfig(apiCfg),
baseURL: config.BaseURL, baseURL: config.BaseURL,
temperature: temp,
}, nil }, nil
} }
@@ -124,7 +137,7 @@ func (v *RemoteAPIVLM) Predict(ctx context.Context, imgBytesList [][]byte, promp
}, },
}, },
MaxTokens: defaultMaxToks, MaxTokens: defaultMaxToks,
Temperature: defaultTemp, Temperature: v.temperature,
} }
totalImageSize := 0 totalImageSize := 0