Merge branch 'feat/sprint-6-ai-tier3'
All checks were successful
Build and Deploy / deploy (push) Successful in 49s

This commit is contained in:
djg 2026-09-23 19:38:52 +00:00
commit 0200cf65cd

View file

@ -497,6 +497,28 @@
// Tier 2: BYOK (Bring Your Own Key) Fallback // Tier 2: BYOK (Bring Your Own Key) Fallback
const key = store('byok_key'); const key = store('byok_key');
if (!key) { if (!key) {
// Try Tier 3 (WebLLM) as the last resort fallback
if (store('ai_webllm_enabled') === 'true') {
if (!window.webllmEngine) {
const { CreateMLCEngine } = await import("https://cdn.jsdelivr.net/npm/@mlc-ai/web-llm/+esm");
window.webllmEngine = await CreateMLCEngine("Llama-3.2-1B-Instruct-q4f16_1-MLC", {
initProgressCallback: (progress) => {
console.log("WebLLM Progress:", progress);
const el = document.getElementById('webllm-progress');
if(el) el.innerText = Math.round(progress.progress * 100) + '% - ' + progress.text;
}
});
}
try {
const reply = await window.webllmEngine.chat.completions.create({
messages: [{ role: 'user', content: prompt }]
});
return reply.choices[0].message.content.split('\n').filter(s=>s.trim().length>0);
} catch(e) {
console.error("WebLLM Context/OOM crash:", e);
throw new Error("NO_AI_AVAILABLE");
}
}
throw new Error("NO_AI_AVAILABLE"); // Let UI prompt for key or let Tier 3 try throw new Error("NO_AI_AVAILABLE"); // Let UI prompt for key or let Tier 3 try
} }
const resp = await fetch('https://api.openai.com/v1/chat/completions', { const resp = await fetch('https://api.openai.com/v1/chat/completions', {