mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
feat(ai): integrate Tier 3 WebLLM engine onto canonical codebase
This commit is contained in:
parent
0d49204a3b
commit
45e49dda4f
1 changed files with 22 additions and 0 deletions
|
|
@ -454,6 +454,28 @@
|
|||
// Tier 2: BYOK (Bring Your Own Key) Fallback
|
||||
const key = store('byok_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
|
||||
}
|
||||
const resp = await fetch('https://api.openai.com/v1/chat/completions', {
|
||||
|
|
|
|||
Loading…
Reference in a new issue