Update index.html
Browse files- index.html +18 -2
index.html
CHANGED
|
@@ -624,6 +624,15 @@ async function fetchJson(url, opts) {
|
|
| 624 |
|
| 625 |
// Solo se envia el tema (query); nunca la conversacion. Sin claves: Tavily keyless
|
| 626 |
// (doc oficial: docs.tavily.com/documentation/keyless) y Wikipedia action API (origin=*).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
async function fetchWebContext(query) {
|
| 628 |
const sources = [];
|
| 629 |
const failed = [];
|
|
@@ -656,7 +665,9 @@ async function fetchWebContext(query) {
|
|
| 656 |
failed.push('Wikipedia respondi\u00f3 ' + r.status);
|
| 657 |
}
|
| 658 |
} catch (e) { failed.push('Wikipedia no accesible (' + (e && e.name === 'AbortError' ? 'tiempo de espera' : 'red') + ')'); }
|
| 659 |
-
|
|
|
|
|
|
|
| 660 |
}
|
| 661 |
|
| 662 |
function renderSourcesMsg(sources, failed) {
|
|
@@ -693,7 +704,12 @@ async function prepareWebContext(q) {
|
|
| 693 |
if (webSources.length) {
|
| 694 |
webContext = webSources.map((s, i) => '[' + (i + 1) + '] ' + s.title + ' \u2014 ' + s.url + '\n' + s.snippet).join('\n');
|
| 695 |
if (webContext.length > 1600) webContext = webContext.slice(0, 1600);
|
| 696 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
} else {
|
| 698 |
webContext = '';
|
| 699 |
addSys(b => { b.textContent = '\u26a0\uFE0F B\u00fasqueda web sin resultados ahora (' + (res.failed.join(' \u00b7 ') || 'error') + '). El debate contin\u00faa sin contexto web.'; });
|
|
|
|
| 624 |
|
| 625 |
// Solo se envia el tema (query); nunca la conversacion. Sin claves: Tavily keyless
|
| 626 |
// (doc oficial: docs.tavily.com/documentation/keyless) y Wikipedia action API (origin=*).
|
| 627 |
+
const SEARCH_STOPWORDS = new Set(('sobre entre contra desde donde cuando cuanto mejor peor debe deberia ' +
|
| 628 |
+
'puede podria conviene hacer tener porque para como cuales cual estos estas esto esta aquellos aquellas ' +
|
| 629 |
+
'merece pena aprender espanol idioma cosas algo cada muy mas').split(' '));
|
| 630 |
+
function normTxt(t) { return String(t).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, ''); }
|
| 631 |
+
function topicTerms(q) {
|
| 632 |
+
return normTxt(q).replace(/[^a-z0-9\u00f1\s]/g, ' ').split(/\s+/)
|
| 633 |
+
.filter(w => w.length >= 4 && !SEARCH_STOPWORDS.has(w))
|
| 634 |
+
.sort((a, b) => b.length - a.length);
|
| 635 |
+
}
|
| 636 |
async function fetchWebContext(query) {
|
| 637 |
const sources = [];
|
| 638 |
const failed = [];
|
|
|
|
| 665 |
failed.push('Wikipedia respondi\u00f3 ' + r.status);
|
| 666 |
}
|
| 667 |
} catch (e) { failed.push('Wikipedia no accesible (' + (e && e.name === 'AbortError' ? 'tiempo de espera' : 'red') + ')'); }
|
| 668 |
+
const top = topicTerms(query).slice(0, 2);
|
| 669 |
+
const missing = top.filter(t => !sources.some(x => normTxt(x.title + ' ' + x.snippet).includes(t)));
|
| 670 |
+
return { sources: sources.slice(0, 6), failed: failed, missing: missing };
|
| 671 |
}
|
| 672 |
|
| 673 |
function renderSourcesMsg(sources, failed) {
|
|
|
|
| 704 |
if (webSources.length) {
|
| 705 |
webContext = webSources.map((s, i) => '[' + (i + 1) + '] ' + s.title + ' \u2014 ' + s.url + '\n' + s.snippet).join('\n');
|
| 706 |
if (webContext.length > 1600) webContext = webContext.slice(0, 1600);
|
| 707 |
+
const warns = res.failed.slice();
|
| 708 |
+
if (res.missing && res.missing.length) {
|
| 709 |
+
warns.push('Ninguna fuente encontrada menciona \u00ab' + res.missing.join('\u00bb ni \u00ab') +
|
| 710 |
+
'\u00bb: es contexto general, no evidencia espec\u00edfica de ese t\u00e9rmino.');
|
| 711 |
+
}
|
| 712 |
+
renderSourcesMsg(webSources, warns);
|
| 713 |
} else {
|
| 714 |
webContext = '';
|
| 715 |
addSys(b => { b.textContent = '\u26a0\uFE0F B\u00fasqueda web sin resultados ahora (' + (res.failed.join(' \u00b7 ') || 'error') + '). El debate contin\u00faa sin contexto web.'; });
|