From 4dd481560d946528556756c3b4fdfe0ad2fef86f Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 31 Mar 2026 12:11:21 +0800 Subject: [PATCH] refactor(chat): simplify temperature option handling in chat request builders - Streamlined the handling of the temperature option in both OllamaChat and RemoteAPIChat by removing unnecessary conditional checks. - Ensured that the temperature value is directly assigned when options are provided, improving code clarity and reducing complexity. --- internal/models/chat/ollama.go | 4 +--- internal/models/chat/remote_api.go | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/models/chat/ollama.go b/internal/models/chat/ollama.go index 28d73945..fde77fa0 100644 --- a/internal/models/chat/ollama.go +++ b/internal/models/chat/ollama.go @@ -93,9 +93,7 @@ func (c *OllamaChat) buildChatRequest(messages []Message, opts *ChatOptions, isS // 添加可选参数 if opts != nil { - if opts.Temperature > 0 { - chatReq.Options["temperature"] = opts.Temperature - } + chatReq.Options["temperature"] = opts.Temperature if opts.TopP > 0 { chatReq.Options["top_p"] = opts.TopP } diff --git a/internal/models/chat/remote_api.go b/internal/models/chat/remote_api.go index 21d57419..ab16f794 100644 --- a/internal/models/chat/remote_api.go +++ b/internal/models/chat/remote_api.go @@ -177,9 +177,7 @@ func (c *RemoteAPIChat) BuildChatCompletionRequest(messages []Message, opts *Cha } if opts != nil { - if opts.Temperature > 0 { - req.Temperature = float32(opts.Temperature) - } + req.Temperature = float32(opts.Temperature) if opts.TopP > 0 { req.TopP = float32(opts.TopP) }