mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
Merge branch 'feat/sprint-6-ai-tier3'
All checks were successful
Build and Deploy / deploy (push) Successful in 49s
All checks were successful
Build and Deploy / deploy (push) Successful in 49s
This commit is contained in:
commit
0200cf65cd
1 changed files with 22 additions and 0 deletions
|
|
@ -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', {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue