Przeglądaj źródła

fix: ask Ollama for JSON instead of only checking whether we got any

"Response Format: JSON object" parsed the reply and failed the attempt when it
did not parse - but the model was never told. The request carried model,
messages, stream and temperature and nothing else, so nothing stopped an
almost-JSON reply being generated.

One eventually was. A missing opening quote:

  { "title_hu":Tuzfenyes ejszakai olelkezes", "title_en": "Firelit Night ...

failed all three attempts and took the workflow down with it - at temperature
0.4, over a long bilingual answer, which is where the odds catch up.

The node now sends Ollama's format parameter when JSON is asked for, so
decoding is constrained and a malformed reply cannot be produced. What is left
for the parse below to handle is an empty or truncated response, not a mangled
one.

This was a one-node gap: every OpenAI-compatible sibling already sends
response_format. Ollama's native API names the parameter differently, and it
was the one that got missed.

Verified against the setup that failed - glm-5.2:cloud on https://ollama.com,
same credential and temperature, retries disabled so each run was a single
attempt: 4/4 valid JSON with all four expected keys.

Node suite: 90 passed, 0 failed, 2 skipped (both sd.cpp cases needing a model
loaded on that server, which is not loaded here).
fszontagh 1 miesiąc temu
rodzic
commit
e70882256c
1 zmienionych plików z 17 dodań i 0 usunięć
  1. 17 0
      nodes/ai/ollama-chat.js

+ 17 - 0
nodes/ai/ollama-chat.js

@@ -290,6 +290,23 @@ function callOllama(config, base64, headers) {
         messages: messages
     };
 
+    // Ask the server for JSON, rather than only checking afterwards whether we
+    // got any.
+    //
+    // "JSON object" used to mean nothing more than "parse the reply and fail
+    // the attempt if it does not parse". The model was never told, so nothing
+    // stopped it emitting almost-JSON - and a reply missing one opening quote
+    //
+    //   { "title_hu":Tuzfenyes ejszakai olelkezes", "title_en": "..."
+    //
+    // failed all three attempts and took the workflow down with it. Ollama's
+    // format parameter constrains decoding so a malformed reply cannot be
+    // produced in the first place; the parse below then only has to deal with
+    // an empty or truncated response.
+    if (config.responseFormat === 'json') {
+        payload.format = 'json';
+    }
+
     const response = smartbotic.http.request({
         method: 'POST',
         url: String(config.baseUrl).replace(/\/+$/, '') + '/api/chat',