
"Before I begin, note that this version makes use of the Prompt API, which is still behind a flag in Chrome. For this demo to work for you, you would need the latest Chrome and the right flags enabled. The Prompt API is available in extensions without the flag and it wouldn't surprise me if this requirement is removed in the next few months. Than again, I don't speak for Google so take that with a Greenland-sized grain of salt."
"In the JavaScript, I once again use feature detection: async function canDoIt() { if(!window.LanguageModel) return false; return (await LanguageModel.availability()) !== 'unavailable'; } // in my DOMContentLoaded event handler: // do an early check let weCanDoIt = await canDoIt(); if(!weCanDoIt) { alert("Sorry, this browser can't use the Prompt API."); return; } After the user has selected a PDF and the text is parsed, I then run enableChat: async function enableChat(text,title) { $chatArea.style.display = 'block'; let session = await LanguageModel.create({ init"
Two demos implement an in-browser PDF question-and-answer system that parses PDFs with PDF.js and uses Chrome's on-device Prompt API to answer user questions entirely client-side. The Prompt API currently requires a feature flag in Chrome, though extensions can access it without the flag. The UI hides the question box until a PDF is selected and parsed. JavaScript performs feature detection using window.LanguageModel and LanguageModel.availability(), and runs an early check in DOMContentLoaded to alert if unavailable. After parsing, enableChat reveals the chat area, creates a LanguageModel session, and provides an input and Ask button to query the parsed text.
Read at Raymondcamden
Unable to calculate read time
Collection
[
|
...
]