aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-10-17 11:14:51 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-10-17 11:14:51 -0400
commit14f412611299fc350f13b6f96be913d59533cfb3 (patch)
tree79e05a3467a44b5a3a5db5baaec2febce72a2526 /src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
parent80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d (diff)
Removed awaits inside loops and made Parameters readonly for better type safety
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
index e91ebdad1..f2e3863a6 100644
--- a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
@@ -72,25 +72,28 @@ export class WebsiteInfoScraperTool extends BaseTool<WebsiteInfoScraperToolParam
async execute(args: ParametersType<WebsiteInfoScraperToolParamsType>): Promise<Observation[]> {
const urls = args.urls;
- const results: Observation[] = [];
- for (const url of urls) {
+ // Create an array of promises, each one handling a website scrape for a URL
+ const scrapingPromises = urls.map(async url => {
try {
const { website_plain_text } = await Networking.PostToServer('/scrapeWebsite', { url });
const id = uuidv4();
this._addLinkedUrlDoc(url, id);
- results.push({
+ return {
type: 'text',
text: `<chunk chunk_id="${id}" chunk_type="url">\n${website_plain_text}\n</chunk>`,
- });
+ } as Observation;
} catch (error) {
console.log(error);
- results.push({
+ return {
type: 'text',
text: `An error occurred while scraping the website: ${url}`,
- });
+ } as Observation;
}
- }
+ });
+
+ // Wait for all scraping promises to resolve
+ const results = await Promise.all(scrapingPromises);
return results;
}