]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Update gpt.lua to support newer models without temperature attribute
authorhunter-nl <junobox@gmail.com>
Thu, 14 Aug 2025 12:24:36 +0000 (14:24 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Aug 2025 12:24:36 +0000 (14:24 +0200)
Newer models do not support temperature attribute anymore.

src/plugins/lua/gpt.lua

index 968127a28732a83a621e2707c3bb39050b6800ed..5a8bb10abb1858f010244fa13f6ad030e57e6933 100644 (file)
@@ -702,9 +702,22 @@ local function openai_check(task, content, sel_part)
     return 'max_tokens'
   end
 
+  -- Only send temperature if model supports it
+  local function supports_temperature(model)
+    if not model then return true end
+    -- Disallow for reasoning models and GPT-5 family
+    if model:match('^gpt%-5') or
+       model:match('^o%d') or
+       model:match('^o%d%-mini') or
+       model:match('^gpt%-4%.1') or
+       model:match('reasoning') then
+      return false
+    end
+    return true
+  end
+    
   local body = {
     model = settings.model,
-    temperature = settings.temperature,
     messages = {
       {
         role = 'system',
@@ -732,7 +745,12 @@ local function openai_check(task, content, sel_part)
   -- Set the correct token limit field
   local token_field = get_max_tokens_field(settings.model)
   body[token_field] = settings.max_tokens
-    
+
+  -- Set the temperature field if model supports it
+  if supports_temperature(settings.model) then
+    body.temperature = settings.temperature
+  end
+
   -- Conditionally add response_format
   if settings.include_response_format then
     body.response_format = { type = "json_object" }