-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathscraper.ts
More file actions
28 lines (24 loc) · 778 Bytes
/
scraper.ts
File metadata and controls
28 lines (24 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import axios from "axios";
import { Document } from "@llamaindex/core/schema";
const SCRAPER_API_URL = process.env.SCRAPER_API_URL || "http://localhost:5001/scrape";
export async function scrapeWebDocuments(urls: string[]): Promise<Document[]> {
try {
const response = await axios.post(SCRAPER_API_URL, { urls });
if (!Array.isArray(response.data)) {
console.warn("Unexpected response format from scraper:", response.data);
return [];
}
return response.data.map((entry: any) =>
new Document({
text: entry.text,
metadata: {
source: entry.url || "web",
private: "false",
},
})
);
} catch (error) {
console.error("Error calling web scraper service:", error);
return [];
}
}