|
@@ -290,6 +290,23 @@ function callOllama(config, base64, headers) {
|
|
|
messages: messages
|
|
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({
|
|
const response = smartbotic.http.request({
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
url: String(config.baseUrl).replace(/\/+$/, '') + '/api/chat',
|
|
url: String(config.baseUrl).replace(/\/+$/, '') + '/api/chat',
|