feat: update report to use multiple models

This commit is contained in:
2026-09-04 06:40:00 +05:00
parent 137f5e0488
commit f4f48edf14
4 changed files with 316 additions and 95 deletions
+6 -4
View File
@@ -1,20 +1,21 @@
const DEFAULT_URL = "http://localhost:11434";
export class Ollama {
constructor({ url = DEFAULT_URL } = {}) {
constructor({ url = DEFAULT_URL, timeoutMs = 600000 } = {}) {
this.url = url.replace(/\/$/, "");
this.timeoutMs = timeoutMs;
}
async ping() {
async ping({ timeoutMs = 30000 } = {}) {
if (process.env.OLLAMA_SKIP_PING === "1") return { ok: true, model: process.env.OLLAMA_MODEL };
const res = await fetch(`${this.url}/api/tags`);
const res = await fetch(`${this.url}/api/tags`, { signal: AbortSignal.timeout(timeoutMs) });
if (!res.ok) throw new Error(`Ollama not reachable (HTTP ${res.status}) at ${this.url}`);
const data = await res.json();
const models = (data.models ?? []).map((m) => m.name);
return { ok: true, models };
}
async chat({ model, messages, tools, temperature = 0, numCtx = 8192 }) {
async chat({ model, messages, tools, temperature = 0, numCtx = 8192, timeoutMs }) {
const body = {
model,
messages,
@@ -28,6 +29,7 @@ export class Ollama {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
signal: AbortSignal.timeout(timeoutMs ?? this.timeoutMs),
});
if (!res.ok) {
const t = await res.text();