@yuktishaalaa/yuktai 5.3.7 → 5.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/dist/{agent-JGLAYQMX.mjs → agent-G67IA7MY.mjs} +1 -1
- package/dist/chunk-P2PBML6K.mjs +11 -0
- package/dist/chunk-UO7IGXCC.mjs +13 -0
- package/dist/index.d.mts +45 -20
- package/dist/index.d.ts +45 -20
- package/dist/index.js +94 -81
- package/dist/index.mjs +44 -42
- package/dist/rag-Q3LUXSSD.mjs +1 -0
- package/dist/transformers-rag-MQZRMFTG.mjs +1 -0
- package/package.json +2 -2
- package/vanilla/README.md +1 -0
- package/vanilla/index.js +1348 -766
- package/vanilla/index.min.js +54 -53
- package/dist/chunk-3VGU4YGK.mjs +0 -6
- package/dist/chunk-XQMQZMAH.mjs +0 -7
- package/dist/rag-MKBAGH6J.mjs +0 -1
- package/dist/transformers-rag-HW4QKA5T.mjs +0 -1
package/dist/chunk-3VGU4YGK.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
function i(){return new Promise(t=>{let n=setTimeout(t,1500),e=new MutationObserver(()=>{clearTimeout(n),n=setTimeout(()=>{e.disconnect(),t()},500)});e.observe(document.body,{childList:!0,subtree:!0})})}function c(){let t=[],n=document.querySelectorAll("*");for(let e of n){if(e.closest("[data-yuktai-panel]"))continue;let s=e.innerText?.trim();s&&s.length>30&&t.push(s);let r=e.getAttribute("aria-label");if(r&&r.length>10&&t.push(r),(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&(e.placeholder&&t.push(e.placeholder),e.value&&t.push(e.value)),e instanceof HTMLButtonElement){let a=e.innerText||e.getAttribute("aria-label");a&&t.push(a)}}return t.join(" ").slice(0,3500)}async function l(t){if(!t.trim())return{success:!1,answer:"",error:"Please type a question."};try{let n=window,e=n.LanguageModel||n.ai?.languageModel;if(!e)return{success:!1,answer:"",error:"Gemini Nano not available."};await i();let s=c();if(!s||s.length<100)return{success:!1,answer:"",error:"Page content not readable."};let r;try{r=await e.create({systemPrompt:`Answer ONLY using page content.
|
|
2
|
-
Keep answer short (2\u20133 sentences).
|
|
3
|
-
If not found say: "I could not find that on this page."`,outputLanguage:"en"})}catch{r=await e.create()}let a=`Page:
|
|
4
|
-
${s}
|
|
5
|
-
|
|
6
|
-
Q: ${t}`,o=await r.prompt(a);return r?.destroy&&r.destroy(),{success:!0,answer:o?.trim()||"No answer found."}}catch(n){return{success:!1,answer:"",error:n instanceof Error?n.message:"Error occurred"}}}export{l as a};
|
package/dist/chunk-XQMQZMAH.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var m=null,h=null,l=!1,f=!1;function g(){return typeof navigator>"u"?!1:/Android|iPhone|iPad|iPod|Mobile|Tablet/i.test(navigator.userAgent)}function p(){if(g())return"wasm";try{if(typeof navigator<"u"&&"gpu"in navigator&&navigator.gpu!==void 0)return"webgpu"}catch{}return"wasm"}async function w(){if(!f){if(l){for(;l;)await new Promise(e=>setTimeout(e,200));return}l=!0;try{let{pipeline:e,env:t}=await import("@huggingface/transformers");t.allowRemoteModels=!0,t.allowLocalModels=!1,typeof window<"u"&&typeof caches<"u"&&(t.useWasmCache=!0);let n=p(),o=g();console.log(`yuktai: Transformers.js \u2014 device: ${n}, mobile: ${o}`),m=await e("feature-extraction","Xenova/all-MiniLM-L6-v2",{device:n,dtype:o?"q4":"fp32"}),h=await e("text2text-generation","Xenova/flan-t5-small",{device:n,dtype:o?"q4":"fp32"}),f=!0,l=!1,console.log("yuktai: Transformers.js models loaded \u2705")}catch(e){throw l=!1,console.error("yuktai: Transformers.js model load failed",e),e}}}function y(){return new Promise(e=>{let t=setTimeout(e,1500),n=new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>{n.disconnect(),e()},500)});n.observe(document.body,{childList:!0,subtree:!0})})}function b(){let e=[],t=new Set,n=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, td, th, label, figcaption, blockquote, span, a, button, div");for(let s of n){if(s.closest("[data-yuktai-panel]")||s.querySelector("p, h1, h2, h3, h4, li, td, div"))continue;let i=s.innerText?.trim();if(!i||i.length<15||t.has(i))continue;t.add(i),e.push(i);let c=s.getAttribute("aria-label")?.trim();c&&c.length>8&&!t.has(c)&&(t.add(c),e.push(c))}let o=document.title?.trim();o&&!t.has(o)&&e.unshift(o);let r=document.querySelector('meta[name="description"]')?.getAttribute("content")?.trim();return r&&!t.has(r)&&e.unshift(r),e.join(" ").slice(0,8e3)}function v(e,t=150,n=30){if(typeof e!="string")try{e=String(e??"")}catch{return[]}let o=e.trim();if(!o)return[];let a=Math.min(n,Math.floor(t/2)),r=o.split(/\s+/),s=[],u=t-a;for(let i=0;i<r.length;i+=u){let c=r.slice(i,i+t).join(" ");c.trim().length>20&&s.push(c)}return s}function k(e,t){let n=0,o=0,a=0;for(let r=0;r<e.length;r++)n+=e[r]*t[r],o+=e[r]*e[r],a+=t[r]*t[r];return n/(Math.sqrt(o)*Math.sqrt(a)+1e-8)}async function d(e){let t=await m(e,{pooling:"mean",normalize:!0}),n=t?.data??t;return Array.from(n)}async function T(e,t,n=3){let o=await d(e),a=await Promise.all(t.map(async r=>{let s=await d(r),u=k(o,s);return{chunk:r,score:u}}));return a.sort((r,s)=>s.score-r.score),a.slice(0,n).map(r=>r.chunk)}async function x(e){if(!e.trim())return{success:!1,answer:"",error:"Please type a question."};try{await w(),await y();let t=b();if(!t||t.length<50)return{success:!1,answer:"",error:"Not enough content on this page."};let n=v(t);if(n.length===0)return{success:!1,answer:"",error:"Could not process page content."};let r=`Answer the question based on the context. Give a complete answer in 2-3 sentences.
|
|
2
|
-
|
|
3
|
-
Context: ${(await T(e,n,3)).join(" ").slice(0,1200)}
|
|
4
|
-
|
|
5
|
-
Question: ${e}
|
|
6
|
-
|
|
7
|
-
Answer:`,u=(await h(r,{max_new_tokens:120,min_new_tokens:10}))?.[0]?.generated_text?.trim()||"";return u?{success:!0,answer:u}:{success:!0,answer:"I could not find a specific answer on this page."}}catch(t){console.error("yuktai: Transformers RAG error",t);let n=t instanceof Error?t.message:"";return n.includes("Out of memory")||n.includes("memory")?{success:!1,answer:"",error:"Not enough device memory. Try on a device with more RAM or use desktop Chrome with Gemini Nano."}:{success:!1,answer:"",error:n||"Transformers.js error."}}}function P(){try{return typeof WebAssembly<"u"&&typeof Worker<"u"}catch{return!1}}function A(){return f?"ready":l?"loading":"idle"}export{x as a,P as b,A as c};
|
package/dist/rag-MKBAGH6J.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-3VGU4YGK.mjs";export{a as askPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c}from"./chunk-XQMQZMAH.mjs";export{a as askPageWithTransformers,c as getModelLoadStatus,b as isTransformersSupported};
|