feat: solution for 'Экзамен: RAG-агент с ChromaDB и веб-поиском'

This commit is contained in:
2026-06-30 11:57:34 +03:00
parent 2f1a172780
commit ef8bb1bd2c
7 changed files with 151 additions and 156 deletions
+13 -11
View File
@@ -1,15 +1,17 @@
import fetch from "node-fetch";
export async function fetchWebContent(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
}
const text = await response.text();
return text;
} catch (err) {
console.error(`Failed to fetch ${url}: ${err.message}`);
return "";
/**
* Performs a simple web search using DuckDuckGo's HTML interface.
* This is a lightweight example and does not use an official API.
* @param {string} query
* @returns {Promise<string>} The raw HTML of the search results page.
*/
export async function webSearch(query) {
const url = `https://duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Web search failed with status ${response.status}`);
}
const html = await response.text();
return html;
}