feat: solution for 'Экзамен: RAG-агент с ChromaDB и веб-поиском'
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
async function webSearch(query) {
|
||||
const url = `https://duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
// Very naive parsing: extract titles from <a> tags
|
||||
const titles = [];
|
||||
const regex = /<a class="result__a"[^>]*>([^<]+)<\/a>/g;
|
||||
let match;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
titles.push(match[1]);
|
||||
}
|
||||
return titles.slice(0, 5);
|
||||
}
|
||||
|
||||
module.exports = { webSearch };
|
||||
Reference in New Issue
Block a user