]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
The gpt4all api which is openai compatible does not support response_format and defau... 5276/head
authorJohn Quaglieri <john@mail.baby>
Thu, 2 Jan 2025 14:14:21 +0000 (09:14 -0500)
committerJohn Quaglieri <john@mail.baby>
Thu, 2 Jan 2025 14:14:21 +0000 (09:14 -0500)
  include_response_format = false;

In the gpt.conf local.d settings

and exclude sending response_format. No other changes are needed for gpt4all api fixing the error:

 gpt.lua:365: got reply: {"error":{"code":null,"message":"'response_format' is not supported","param":null,"type":"invalid_request_error"}}

src/plugins/lua/gpt.lua

index feccae73ff29f4ef2895eca9438c27748b414480..e4a77c6dd873ffa389ef31423fb920ae63794c38 100644 (file)
@@ -48,6 +48,8 @@ gpt {
   allow_passthrough = false;
   # Check messages that are apparent ham (no action and negative score)
   allow_ham = false;
+  # default send response_format field { type = "json_object" }
+  include_response_format = true,
 }
   ]])
   return
@@ -393,7 +395,6 @@ local function default_llm_check(task)
     model = settings.model,
     max_tokens = settings.max_tokens,
     temperature = settings.temperature,
-    response_format = { type = "json_object" },
     messages = {
       {
         role = 'system',
@@ -418,6 +419,11 @@ local function default_llm_check(task)
     }
   }
 
+  -- Conditionally add response_format
+  if settings.include_response_format then
+    body.response_format = { type = "json_object" }
+  end
+
   upstream = settings.upstreams:get_upstream_round_robin()
   local http_params = {
     url = settings.url,
@@ -498,7 +504,6 @@ local function ollama_check(task)
     model = settings.model,
     max_tokens = settings.max_tokens,
     temperature = settings.temperature,
-    response_format = { type = "json_object" },
     messages = {
       {
         role = 'system',
@@ -523,6 +528,11 @@ local function ollama_check(task)
     }
   }
 
+  -- Conditionally add response_format
+  if settings.include_response_format then
+    body.response_format = { type = "json_object" }
+  end
+
   upstream = settings.upstreams:get_upstream_round_robin()
   local http_params = {
     url = settings.url,
@@ -618,4 +628,4 @@ if opts then
     parent = id,
     score = -2.0,
   })
-end
\ No newline at end of file
+end