Use official ollama npm client for all LLM calls

Replaces hand-rolled fetch to /api/chat with the ollama@0.6.3 package.

The package supplies proper Accept/Content-Type/User-Agent headers and

auto-handles the Ollama protocol, fixing the CDN 403s Node's bare fetch

gets against ollama.com during filing.

Both organize and search LLM ranking now route through controller/ollama.js.

Signed-off-by: William Mantly <wmantly@gmail.com>
This commit is contained in:
2026-07-20 12:43:25 -04:00
parent 47a930eddb
commit bd9f058f26
4 changed files with 43 additions and 60 deletions
+4 -32
View File
@@ -22,17 +22,6 @@ function humanSize(bytes){
return `${bytes.toFixed(bytes < 10 && i > 0 ? 1 : 0)} ${units[i]}`;
}
async function fetchJSON(url, options){
let res = await fetch(url, options);
if(!res.ok){
let error = new Error(`UpstreamError`);
error.message = `Request to ${url.split('?')[0]} failed( ${res.status})`;
error.status = 502;
throw error;
}
return await res.json();
}
// Turn a raw TPB category id into 'movie' | 'tv' | null.
function videoKind(category){
category = parseInt(category, 10);
@@ -179,27 +168,10 @@ async function rankReleases(candidates, meta){
imdb: t.imdb || null,
}));
let body = {
model: conf.ollama.model,
stream: false,
format: 'json',
messages: [
{ role: 'system', content: buildSystemPrompt(meta.title, meta.year, meta.today) },
{ role: 'user', content: JSON.stringify(compact) },
],
};
let data = await fetchJSON(`${conf.ollama.url}/api/chat`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${conf.ollama.apiKey}`,
'User-Agent': 'tpbproxy/1.0 (search; +https://github.com/wmantly/tpbproxy)',
},
body: JSON.stringify(body),
});
let parsed = extractJSON(data.message && data.message.content);
let parsed = await ollama.chatJSON(
buildSystemPrompt(meta.title, meta.year, meta.today),
JSON.stringify(compact)
);
let options = Array.isArray(parsed.options) ? parsed.options : [];
if(!options.length) throw new Error('Model returned no options');
return options;