fix(confidence-engine): expose failed provider path

This commit is contained in:
2026-09-05 17:00:33 +01:00
parent 677f5e5757
commit dabd9e2245
9 changed files with 81 additions and 6 deletions
+12 -5
View File
@@ -119,7 +119,8 @@ class OllamaLlmProvider {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 60000);
apiUsed = "/api/chat";
const res = await fetch(`${baseUrl}/api/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -180,14 +181,14 @@ class OllamaLlmProvider {
}
fullResponseData = await res.json();
rawResponse = typeof fullResponseData.response === "string"
? fullResponseData.response
: JSON.stringify(fullResponseData);
} catch (e) {
if (apiUsed === "/api/generate") {
throw new Error(
const error = new Error(
`Ollama /api/generate request timed out after 5 minutes.\n\n` +
`This usually means:\n` +
`1. The model is loading into memory for the first time (cold start) — this can take several minutes\n` +
@@ -198,6 +199,8 @@ class OllamaLlmProvider {
`- Use a smaller model (e.g., llama3.1 instead of llama3.1:70b)\n` +
`- Check Ollama logs: \`ollama serve\` or look at your system logs`
);
error.providerApiPath = apiUsed;
throw error;
}
throw e;
}
@@ -225,7 +228,7 @@ class OllamaLlmProvider {
}
}
throw new Error(
const error = new Error(
"Model produced empty output.\n\n" +
"API used: " + (apiUsed || "none") + "\n" +
"/api/chat supported: " + chatSupported + "\n" +
@@ -236,6 +239,8 @@ class OllamaLlmProvider {
"- This Ollama version does not support format:json — using prompt instructions only (reliability varies)\n" +
"- If your model is very small (e.g., tinyllama, phi), try a larger one like llama3.1 or mistral"
);
error.providerApiPath = apiUsed;
throw error;
}
// ================================================================
@@ -245,7 +250,7 @@ class OllamaLlmProvider {
return recoverJson(rawResponse);
} catch (e) {
if (e instanceof SyntaxError) {
throw new Error(
const error = new Error(
"Model returned output that could not be parsed as valid JSON.\n\n" +
"API used: " + (apiUsed || "none") + "\n" +
"/api/chat supported: " + chatSupported + "\n" +
@@ -256,6 +261,8 @@ class OllamaLlmProvider {
"- Shorten your scenario to under 500 words\n" +
"- Consider upgrading Ollama: https://ollama.com/download"
);
error.providerApiPath = apiUsed;
throw error;
}
throw e;
}