This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check availability first | |
| const availability = await LanguageModel.availability({ | |
| }) | |
| // Create session with monitoring | |
| const session = await LanguageModel.create({ | |
| temperature: 0.7, | |
| monitor(m) { | |
| m.addEventListener('downloadprogress', (e) => { | |
| console.log(`Downloaded ${e.loaded * 100}%`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const initialPrompts = [ | |
| { | |
| role: 'system', | |
| content: `You are a knowledgeable Thai food and cuisine specialist. Your role is to help customers learn about authentic Thai dishes, ingredients, cooking methods, and food culture using accurate information from the FAQ data. Be enthusiastic about Thai cuisine and highlight its unique flavors and traditions. | |
| Key guidelines: | |
| - Use the provided FAQ information to give accurate, helpful answers about Thai food | |
| - Emphasize the authentic flavors, spices, and cooking techniques of Thai cuisine | |
| - Mention popular dishes like Pad Thai, Tom Yum, Green Curry, and Som Tam | |
| - Highlight the balance of sweet, sour, spicy, and savory flavors in Thai cooking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { pipeline, env } from '@huggingface/transformers'; | |
| import faqs from "@/faq.json"; | |
| const extractor = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2"); | |
| const embeddings = []; | |
| for (const faq of faqs) { | |
| const embedding = await extractor(faq.question + " " + faq.answer, { | |
| pooling: "mean", | |
| normalize: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| FilesetResolver, | |
| LlmInference, | |
| } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai"; | |
| const genai = await FilesetResolver.forGenAiTasks( | |
| "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai@latest/wasm" | |
| ); | |
| llmInference = await LlmInference.createFromOptions(genai, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (HTMLScriptElement.supports && HTMLScriptElement.supports('speculationrules')) { | |
| console.log('Your browser supports the Speculation Rules API.'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (HTMLScriptElement.supports?.('speculationrules')) { | |
| const specScript = document.createElement('script'); | |
| specScript.type = 'speculationrules'; | |
| const specRules = { | |
| prerender: [ | |
| { | |
| urls: ['/next.html'], | |
| }, | |
| ], | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="speculationrules"> | |
| { | |
| "prerender": [ | |
| { | |
| "source": "list", | |
| "urls": ["next.html", "next2.html"], | |
| "eagerness": "moderate" | |
| }, | |
| { | |
| "where": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @media all and (display-mode: picture-in-picture) { | |
| ...... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipWindow.addEventListener("pagehide", (event) => { | |
| const chatScreen Container = document.querySelector("#chat-screen-container"); | |
| const pipChatScreen = event.target.querySelector("#chat-screen"); | |
| playerContainer.append(pipPlayer); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipButton.addEventListener("click", async () => { | |
| const chatScreen = document.querySelector("#chat-screen"); | |
| // Open a Picture-in-Picture window. | |
| const pipWindow = await documentPictureInPicture.requestWindow(); | |
| // Copy style sheets over from the initial document | |
| // so that the player looks the same. | |
| [...document.styleSheets].forEach((styleSheet) => { | |
| try { |
NewerOlder