Files
ekzamen-rag-agent-s-chromad…/src/webSearch.js
T

17 lines
579 B
JavaScript

import fetch from "node-fetch";
/**
* 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;
}