Download task_010/solution/code/index.html from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 4.57 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_010/solution/code/index.html
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_010/solution/code/index.html
-
curl -L -o index.html https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_010/solution/code/index.html
4.57 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Prompt Response API Solution v2</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; padding: 24px; } | |
| textarea { width: min(520px, 100%); height: 80px; display: block; box-sizing: border-box; } | |
| output { display: block; margin-top: 12px; min-height: 48px; white-space: pre-wrap; } | |
| .error { color: #b91c1c; } | |
| </style> | |
| <script src="config.js"></script> | |
| </head> | |
| <body> | |
| <main> | |
| <label>Prompt<textarea data-testid="prompt-input"></textarea></label> | |
| <button data-testid="send-button">Generate</button> | |
| <h1 data-testid="generated-title"></h1> | |
| <output data-testid="generated-content"></output> | |
| <p data-testid="generation-status">idle</p> | |
| </main> | |
| <script> | |
| let mockMode = 'normal'; | |
| let mockChunks = null; | |
| let requestVersion = 0; | |
| window.__setMockMode = mode => { mockMode = mode; }; | |
| window.__setMockChunks = chunks => { mockChunks = chunks === null ? null : [...chunks]; }; | |
| function makeTitle(prompt) { | |
| const words = prompt.split(/\s+/).filter(Boolean).slice(0, 5).join(' '); | |
| return `Plan for ${words}`; | |
| } | |
| function parseChunk(chunk) { | |
| const text = String(chunk); | |
| const match = text.match(/^\s*\d+:(.*)$/s); | |
| if (!match) return text; | |
| const parsed = JSON.parse(match[1]); | |
| if (typeof parsed !== 'string') throw new Error('invalid text frame'); | |
| return parsed; | |
| } | |
| async function* streamChunks(prompt, config) { | |
| if (!config || ['key', 'baseurl', 'modelname'].some(name => | |
| typeof config[name] !== 'string' || !config[name].trim())) { | |
| throw new Error('missing API configuration'); | |
| } | |
| if (mockMode === 'timeout') throw new Error('request timeout'); | |
| if (mockChunks !== null) { | |
| yield* mockChunks; | |
| return; | |
| } | |
| if (mockMode === 'malformed') { | |
| yield '0:"Hello"'; | |
| yield '0:"world"'; | |
| return; | |
| } | |
| const topic = prompt.split(/[::;;.!?\n]/u, 1)[0].trim() || 'the requested work'; | |
| if (/\brisk register|mitigat/i.test(prompt)) { | |
| yield `List hazards, affected components and a mitigation owner for ${topic}. `; | |
| yield 'Rate each hazard by likelihood and severity, then document how to verify the mitigation.'; | |
| return; | |
| } | |
| if (/\b(?:restor\w*|repair\w*|renovat\w*)\b/i.test(topic)) { | |
| yield `Document the current condition of ${topic} and identify what can be preserved. `; | |
| yield 'Stabilize the most fragile components first. Test repairs on a small, reversible area before expanding.'; | |
| } else if (/\b(?:inspect\w*|audit\w*)\b/i.test(topic)) { | |
| yield `Identify the critical components and safe access points for ${topic}. `; | |
| yield 'Record the evidence for each finding, then prioritize defects by severity and urgency.'; | |
| } else { | |
| yield `Set a concrete deliverable for ${topic} and list the inputs needed to produce it. `; | |
| yield 'Complete a small first pass, check it against the deliverable, then handle the remaining cases.'; | |
| } | |
| } | |
| async function generate() { | |
| const version = ++requestVersion; | |
| const prompt = document.querySelector('[data-testid="prompt-input"]').value; | |
| const status = document.querySelector('[data-testid="generation-status"]'); | |
| const title = document.querySelector('[data-testid="generated-title"]'); | |
| const content = document.querySelector('[data-testid="generated-content"]'); | |
| status.className = ''; | |
| status.textContent = 'loading stream'; | |
| title.textContent = 'Loading title...'; | |
| content.textContent = 'Loading content...'; | |
| try { | |
| const config = {...window.aiConfig}; | |
| await new Promise(resolve => setTimeout(resolve, 20)); | |
| if (version !== requestVersion) return; | |
| title.textContent = makeTitle(prompt); | |
| content.textContent = ''; | |
| for await (const chunk of streamChunks(prompt, config)) { | |
| if (version !== requestVersion) return; | |
| content.textContent += parseChunk(chunk); | |
| await new Promise(resolve => setTimeout(resolve, 60)); | |
| } | |
| if (version !== requestVersion) return; | |
| status.textContent = 'complete'; | |
| } catch (err) { | |
| if (version !== requestVersion) return; | |
| status.className = 'error'; | |
| status.textContent = `failed: ${err.message || err}`; | |
| } | |
| } | |
| document.querySelector('[data-testid="send-button"]').addEventListener('click', generate); | |
| </script> | |
| </body> | |
| </html> | |