Spaces:
Running
Running
Page reading: stub detection, defuddle.md and Wayback tiers
Browse filesFiles changed (2)
- index.html+1-1
- tools.js+19-17
41 unmodified lines4243444546474841 unmodified lines<p><b>Agent.</b> The prompt, the two tools (<code>search</code>, <code>webterminal</code>), the 150-call budget and the final-answer warning are from<a href="https://github.com/allenai/dr-tulu2" target="_blank" rel="noopener">allenai/dr-tulu2</a>. Its live mode uses paid Serper and Jina keys; here there is no server at all:<code>search</code> reads DuckDuckGo results (Brave as backup) and <code>browse</code> reads pages through <a href="https://jina.ai/reader" target="_blank" rel="noopener">Jina Reader</a>'s anonymous, browser-friendly endpoint(it renders JavaScript and gets past most bot walls), with Wikipedia and OpenAlex search and the Wayback Machine as fallbacks.The terminal is a small safe runner written in JavaScript for <code>head tail rg grep sed wc sort uniq cut tr nl</code>; there is no shell. Private and local addresses are refused, as are huggingface.co pages (as upstream blocks them). Each filter pipeline is limited to 5 seconds.</p><p><b>One addition.</b> The system prompt is Ai2's, plus one line giving today's date (the model does not know it and otherwise searches for old news). Add <code>?date=0</code> to the address to remove it.</p><p><b>Honest limits.</b> A 4-bit-class model on a free search stack is not the paper's setup: results can be thinner than the reported benchmarks, the free services rate-limit (about 20 page reads a minute, so steps can pause), and answers can be wrong. Check the sources it cites.41 unmodified lines4243444546474841 unmodified lines<p><b>Agent.</b> The prompt, the two tools (<code>search</code>, <code>webterminal</code>), the 150-call budget and the final-answer warning are from<a href="https://github.com/allenai/dr-tulu2" target="_blank" rel="noopener">allenai/dr-tulu2</a>. Its live mode uses paid Serper and Jina keys; here there is no server at all:<code>search</code> reads DuckDuckGo results (Brave as backup) and <code>browse</code> reads pages through <a href="https://jina.ai/reader" target="_blank" rel="noopener">Jina Reader</a>'s anonymous, browser-friendly endpoint(it renders JavaScript and gets past most bot walls); if a site refuses it, the page is retried through defuddle.md, a direct read and the newest Wayback Machine copy. Hard paywalls and bot-protected news sites (Reuters, NYT…) stay unreadable, and the model is told so. Search falls back to Wikipedia and OpenAlex.The terminal is a small safe runner written in JavaScript for <code>head tail rg grep sed wc sort uniq cut tr nl</code>; there is no shell. Private and local addresses are refused, as are huggingface.co pages (as upstream blocks them). Each filter pipeline is limited to 5 seconds.</p><p><b>One addition.</b> The system prompt is Ai2's, plus one line giving today's date (the model does not know it and otherwise searches for old news). Add <code>?date=0</code> to the address to remove it.</p><p><b>Honest limits.</b> A 4-bit-class model on a free search stack is not the paper's setup: results can be thinner than the reported benchmarks, the free services rate-limit (about 20 page reads a minute, so steps can pause), and answers can be wrong. Check the sources it cites.
47 unmodified lines4849505152535455565758596061626364656667686970717273747547 unmodified linesreturn p.href;}const pageCache = new Map();export async function fetchPage(url) {url = checkUrl(url);if (pageCache.has(url)) return pageCache.get(url);const tried = []; let text = '';try { // tier 1: Jina Reader (renders JS, strips boilerplate)const r = await getText(url, { reader: true, timeout: 45000 });tried.push(`reader HTTP ${r.status}`);if (r.status < 400 && r.text.trim()) text = r.text;if (BLOCK.test(text.slice(0, 1500)) && text.length < 3000) text = '';} catch (e) { tried.push(`reader ${e.name}`); }if (!text.trim()) try { // tier 2: the page itself, when its server allows cross-origin readsconst r = await getText(url, { timeout: 15000 });tried.push(`direct HTTP ${r.status}`);if (r.status < 400) text = htmlToText(r.text);} catch (e) { tried.push(`direct ${e.name === 'AbortError' ? 'timeout' : 'blocked by CORS'}`); }if (!text.trim()) try { // tier 3: Wayback Machine snapshotconst av = await getText(`https://archive.org/wayback/available?url=${encodeURIComponent(url)}`, { timeout: 15000 });const snap = JSON.parse(av.text)?.archived_snapshots?.closest?.url;if (snap) { const r = await getText(snap.replace(/^http:/, 'https:'), { reader: true, timeout: 45000 }); tried.push(`archive HTTP ${r.status}`); if (r.status < 400) text = r.text; }else tried.push('archive none');} catch (e) { tried.push(`archive ${e.name}`); }text = text.trim() || `BLOCKED/EMPTY: could not get readable content from ${url} (${tried.join(', ')}). Try another source.`;pageCache.set(url, text); if (pageCache.size > 100) pageCache.delete(pageCache.keys().next().value);return text;}47 unmodified lines48495051525354555657585960616263646566676869707172737475767747 unmodified linesreturn p.href;}const pageCache = new Map();// Jina answers 200 even for blocked pages, with a header and a "Warning: Target URL returned error 401": that is a failure, not content.const usable = (t) => { const body = (t.split('Markdown Content:')[1] ?? t).trim(); return body.length >= 400 && !(BLOCK.test(body.slice(0, 1500)) && body.length < 3000); };export async function fetchPage(url) {url = checkUrl(url);if (pageCache.has(url)) return pageCache.get(url);const tried = []; let text = '';const attempt = async (name, fn) => { // run one tier; keep its text only if it is real contentif (text) return;try { const r = await fn(); tried.push(`${name} HTTP ${r.status}`); if (r.status < 400 && usable(r.text)) text = r.text; }catch (e) { if (e?.name === 'AbortError' && outer?.aborted) throw e; tried.push(`${name} ${e?.name === 'AbortError' ? 'timeout' : 'unreachable'}`); }};await attempt('reader', () => getText(url, { reader: true, timeout: 45000 })); // 1. Jina Reader: renders JavaScript, strips boilerplateawait attempt('defuddle', () => getText('https://defuddle.md/' + url, { timeout: 30000 })); // 2. defuddle.md: another free, CORS-enabled reader; fetches from other IPs than Jina (reads some sites Jina refuses)await attempt('direct', async () => { const r = await getText(url, { timeout: 15000 }); return { ...r, text: r.status < 400 ? htmlToText(r.text) : '' }; }); // 3. the page itself, when its server allows cross-origin readsif (!text) try { // 4. newest Wayback Machine snapshot (CORS-enabled API), raw copy first, then through defuddleconst av = await getText(`https://archive.org/wayback/available?url=${encodeURIComponent(url)}`, { timeout: 15000 });const snap = JSON.parse(av.text)?.archived_snapshots?.closest?.url?.replace(/^http:/, 'https:');if (snap) {const raw = snap.replace(/\/web\/(\d+)\//, '/web/$1id_/');await attempt('archive', async () => { const r = await getText(raw, { timeout: 30000 }); return { ...r, text: r.status < 400 ? htmlToText(r.text) : '' }; });await attempt('archive via defuddle', () => getText('https://defuddle.md/' + raw, { timeout: 45000 }));} else tried.push('archive none');} catch (e) { if (e?.name === 'AbortError' && outer?.aborted) throw e; tried.push('archive unreachable'); }text = text.trim() || `BLOCKED/EMPTY: could not get readable content from ${url} (${tried.join(', ')}). The site blocks automated readers or needs a login; use a different source.`;pageCache.set(url, text); if (pageCache.size > 100) pageCache.delete(pageCache.keys().next().value);return text;}
index.html+1-1
tools.js+19-17