feat: solution for 'Экзамен: RAG-агент с ChromaDB и веб-поиском'
This commit is contained in:
+13
-11
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user