langchain 0.2.18 → 0.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/openai_functions/index.cjs +2 -2
- package/dist/agents/openai_functions/index.js +2 -2
- package/dist/chains/combine_documents/stuff.cjs +2 -2
- package/dist/chains/combine_documents/stuff.js +2 -2
- package/dist/chains/openai_functions/openapi.cjs +3 -1
- package/dist/chains/openai_functions/openapi.js +3 -1
- package/dist/load/import_constants.cjs +2 -39
- package/dist/load/import_constants.js +2 -39
- package/dist/load/import_map.cjs +2 -3
- package/dist/load/import_map.d.ts +0 -1
- package/dist/load/import_map.js +0 -1
- package/dist/smith/config.d.ts +1 -5
- package/package.json +31 -854
- package/dist/document_loaders/fs/chatgpt.cjs +0 -90
- package/dist/document_loaders/fs/chatgpt.d.ts +0 -8
- package/dist/document_loaders/fs/chatgpt.js +0 -86
- package/dist/document_loaders/fs/csv.cjs +0 -73
- package/dist/document_loaders/fs/csv.d.ts +0 -65
- package/dist/document_loaders/fs/csv.js +0 -69
- package/dist/document_loaders/fs/docx.cjs +0 -58
- package/dist/document_loaders/fs/docx.d.ts +0 -25
- package/dist/document_loaders/fs/docx.js +0 -54
- package/dist/document_loaders/fs/epub.cjs +0 -103
- package/dist/document_loaders/fs/epub.d.ts +0 -33
- package/dist/document_loaders/fs/epub.js +0 -99
- package/dist/document_loaders/fs/notion.cjs +0 -26
- package/dist/document_loaders/fs/notion.d.ts +0 -12
- package/dist/document_loaders/fs/notion.js +0 -22
- package/dist/document_loaders/fs/obsidian.cjs +0 -247
- package/dist/document_loaders/fs/obsidian.d.ts +0 -28
- package/dist/document_loaders/fs/obsidian.js +0 -240
- package/dist/document_loaders/fs/openai_whisper_audio.cjs +0 -49
- package/dist/document_loaders/fs/openai_whisper_audio.d.ts +0 -23
- package/dist/document_loaders/fs/openai_whisper_audio.js +0 -45
- package/dist/document_loaders/fs/pdf.cjs +0 -148
- package/dist/document_loaders/fs/pdf.d.ts +0 -49
- package/dist/document_loaders/fs/pdf.js +0 -144
- package/dist/document_loaders/fs/pptx.cjs +0 -46
- package/dist/document_loaders/fs/pptx.d.ts +0 -25
- package/dist/document_loaders/fs/pptx.js +0 -42
- package/dist/document_loaders/fs/srt.cjs +0 -57
- package/dist/document_loaders/fs/srt.d.ts +0 -32
- package/dist/document_loaders/fs/srt.js +0 -50
- package/dist/document_loaders/fs/unstructured.cjs +0 -338
- package/dist/document_loaders/fs/unstructured.d.ts +0 -125
- package/dist/document_loaders/fs/unstructured.js +0 -333
- package/dist/document_loaders/web/apify_dataset.cjs +0 -130
- package/dist/document_loaders/web/apify_dataset.d.ts +0 -85
- package/dist/document_loaders/web/apify_dataset.js +0 -126
- package/dist/document_loaders/web/assemblyai.cjs +0 -200
- package/dist/document_loaders/web/assemblyai.d.ts +0 -95
- package/dist/document_loaders/web/assemblyai.js +0 -193
- package/dist/document_loaders/web/azure_blob_storage_container.cjs +0 -73
- package/dist/document_loaders/web/azure_blob_storage_container.d.ts +0 -46
- package/dist/document_loaders/web/azure_blob_storage_container.js +0 -69
- package/dist/document_loaders/web/azure_blob_storage_file.cjs +0 -124
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +0 -53
- package/dist/document_loaders/web/azure_blob_storage_file.js +0 -97
- package/dist/document_loaders/web/browserbase.cjs +0 -93
- package/dist/document_loaders/web/browserbase.d.ts +0 -48
- package/dist/document_loaders/web/browserbase.js +0 -86
- package/dist/document_loaders/web/cheerio.cjs +0 -118
- package/dist/document_loaders/web/cheerio.d.ts +0 -77
- package/dist/document_loaders/web/cheerio.js +0 -114
- package/dist/document_loaders/web/college_confidential.cjs +0 -41
- package/dist/document_loaders/web/college_confidential.d.ts +0 -25
- package/dist/document_loaders/web/college_confidential.js +0 -37
- package/dist/document_loaders/web/confluence.cjs +0 -190
- package/dist/document_loaders/web/confluence.d.ts +0 -114
- package/dist/document_loaders/web/confluence.js +0 -186
- package/dist/document_loaders/web/couchbase.cjs +0 -95
- package/dist/document_loaders/web/couchbase.d.ts +0 -32
- package/dist/document_loaders/web/couchbase.js +0 -91
- package/dist/document_loaders/web/figma.cjs +0 -102
- package/dist/document_loaders/web/figma.d.ts +0 -82
- package/dist/document_loaders/web/figma.js +0 -98
- package/dist/document_loaders/web/firecrawl.cjs +0 -95
- package/dist/document_loaders/web/firecrawl.d.ts +0 -50
- package/dist/document_loaders/web/firecrawl.js +0 -88
- package/dist/document_loaders/web/gitbook.cjs +0 -110
- package/dist/document_loaders/web/gitbook.d.ts +0 -55
- package/dist/document_loaders/web/gitbook.js +0 -106
- package/dist/document_loaders/web/github.cjs +0 -615
- package/dist/document_loaders/web/github.d.ts +0 -203
- package/dist/document_loaders/web/github.js +0 -608
- package/dist/document_loaders/web/hn.cjs +0 -90
- package/dist/document_loaders/web/hn.d.ts +0 -42
- package/dist/document_loaders/web/hn.js +0 -86
- package/dist/document_loaders/web/imsdb.cjs +0 -44
- package/dist/document_loaders/web/imsdb.d.ts +0 -23
- package/dist/document_loaders/web/imsdb.js +0 -40
- package/dist/document_loaders/web/notionapi.cjs +0 -404
- package/dist/document_loaders/web/notionapi.d.ts +0 -133
- package/dist/document_loaders/web/notionapi.js +0 -392
- package/dist/document_loaders/web/notiondb.cjs +0 -199
- package/dist/document_loaders/web/notiondb.d.ts +0 -56
- package/dist/document_loaders/web/notiondb.js +0 -195
- package/dist/document_loaders/web/pdf.cjs +0 -140
- package/dist/document_loaders/web/pdf.d.ts +0 -35
- package/dist/document_loaders/web/pdf.js +0 -136
- package/dist/document_loaders/web/playwright.cjs +0 -89
- package/dist/document_loaders/web/playwright.d.ts +0 -58
- package/dist/document_loaders/web/playwright.js +0 -85
- package/dist/document_loaders/web/puppeteer.cjs +0 -139
- package/dist/document_loaders/web/puppeteer.d.ts +0 -82
- package/dist/document_loaders/web/puppeteer.js +0 -135
- package/dist/document_loaders/web/recursive_url.cjs +0 -198
- package/dist/document_loaders/web/recursive_url.d.ts +0 -33
- package/dist/document_loaders/web/recursive_url.js +0 -194
- package/dist/document_loaders/web/s3.cjs +0 -164
- package/dist/document_loaders/web/s3.d.ts +0 -78
- package/dist/document_loaders/web/s3.js +0 -137
- package/dist/document_loaders/web/searchapi.cjs +0 -150
- package/dist/document_loaders/web/searchapi.d.ts +0 -76
- package/dist/document_loaders/web/searchapi.js +0 -146
- package/dist/document_loaders/web/serpapi.cjs +0 -127
- package/dist/document_loaders/web/serpapi.d.ts +0 -62
- package/dist/document_loaders/web/serpapi.js +0 -123
- package/dist/document_loaders/web/sitemap.cjs +0 -118
- package/dist/document_loaders/web/sitemap.d.ts +0 -41
- package/dist/document_loaders/web/sitemap.js +0 -114
- package/dist/document_loaders/web/sonix_audio.cjs +0 -68
- package/dist/document_loaders/web/sonix_audio.d.ts +0 -36
- package/dist/document_loaders/web/sonix_audio.js +0 -64
- package/dist/document_loaders/web/sort_xyz_blockchain.cjs +0 -157
- package/dist/document_loaders/web/sort_xyz_blockchain.d.ts +0 -78
- package/dist/document_loaders/web/sort_xyz_blockchain.js +0 -153
- package/dist/document_loaders/web/youtube.cjs +0 -116
- package/dist/document_loaders/web/youtube.d.ts +0 -55
- package/dist/document_loaders/web/youtube.js +0 -112
- package/dist/experimental/tools/pyinterpreter.cjs +0 -248
- package/dist/experimental/tools/pyinterpreter.d.ts +0 -18
- package/dist/experimental/tools/pyinterpreter.js +0 -244
- package/dist/retrievers/self_query/chroma.cjs +0 -48
- package/dist/retrievers/self_query/chroma.d.ts +0 -26
- package/dist/retrievers/self_query/chroma.js +0 -44
- package/dist/retrievers/self_query/pinecone.cjs +0 -47
- package/dist/retrievers/self_query/pinecone.d.ts +0 -26
- package/dist/retrievers/self_query/pinecone.js +0 -43
- package/dist/retrievers/self_query/supabase.cjs +0 -278
- package/dist/retrievers/self_query/supabase.d.ts +0 -109
- package/dist/retrievers/self_query/supabase.js +0 -274
- package/dist/retrievers/self_query/supabase_utils.cjs +0 -264
- package/dist/retrievers/self_query/supabase_utils.d.ts +0 -101
- package/dist/retrievers/self_query/supabase_utils.js +0 -259
- package/dist/retrievers/self_query/vectara.cjs +0 -143
- package/dist/retrievers/self_query/vectara.d.ts +0 -42
- package/dist/retrievers/self_query/vectara.js +0 -139
- package/dist/retrievers/self_query/weaviate.cjs +0 -201
- package/dist/retrievers/self_query/weaviate.d.ts +0 -99
- package/dist/retrievers/self_query/weaviate.js +0 -197
- package/dist/types/assemblyai-types.cjs +0 -2
- package/dist/types/assemblyai-types.d.ts +0 -4
- package/dist/types/assemblyai-types.js +0 -1
- package/document_loaders/fs/chatgpt.cjs +0 -1
- package/document_loaders/fs/chatgpt.d.cts +0 -1
- package/document_loaders/fs/chatgpt.d.ts +0 -1
- package/document_loaders/fs/chatgpt.js +0 -1
- package/document_loaders/fs/csv.cjs +0 -1
- package/document_loaders/fs/csv.d.cts +0 -1
- package/document_loaders/fs/csv.d.ts +0 -1
- package/document_loaders/fs/csv.js +0 -1
- package/document_loaders/fs/docx.cjs +0 -1
- package/document_loaders/fs/docx.d.cts +0 -1
- package/document_loaders/fs/docx.d.ts +0 -1
- package/document_loaders/fs/docx.js +0 -1
- package/document_loaders/fs/epub.cjs +0 -1
- package/document_loaders/fs/epub.d.cts +0 -1
- package/document_loaders/fs/epub.d.ts +0 -1
- package/document_loaders/fs/epub.js +0 -1
- package/document_loaders/fs/notion.cjs +0 -1
- package/document_loaders/fs/notion.d.cts +0 -1
- package/document_loaders/fs/notion.d.ts +0 -1
- package/document_loaders/fs/notion.js +0 -1
- package/document_loaders/fs/obsidian.cjs +0 -1
- package/document_loaders/fs/obsidian.d.cts +0 -1
- package/document_loaders/fs/obsidian.d.ts +0 -1
- package/document_loaders/fs/obsidian.js +0 -1
- package/document_loaders/fs/openai_whisper_audio.cjs +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.cts +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.ts +0 -1
- package/document_loaders/fs/openai_whisper_audio.js +0 -1
- package/document_loaders/fs/pdf.cjs +0 -1
- package/document_loaders/fs/pdf.d.cts +0 -1
- package/document_loaders/fs/pdf.d.ts +0 -1
- package/document_loaders/fs/pdf.js +0 -1
- package/document_loaders/fs/pptx.cjs +0 -1
- package/document_loaders/fs/pptx.d.cts +0 -1
- package/document_loaders/fs/pptx.d.ts +0 -1
- package/document_loaders/fs/pptx.js +0 -1
- package/document_loaders/fs/srt.cjs +0 -1
- package/document_loaders/fs/srt.d.cts +0 -1
- package/document_loaders/fs/srt.d.ts +0 -1
- package/document_loaders/fs/srt.js +0 -1
- package/document_loaders/fs/unstructured.cjs +0 -1
- package/document_loaders/fs/unstructured.d.cts +0 -1
- package/document_loaders/fs/unstructured.d.ts +0 -1
- package/document_loaders/fs/unstructured.js +0 -1
- package/document_loaders/web/apify_dataset.cjs +0 -1
- package/document_loaders/web/apify_dataset.d.cts +0 -1
- package/document_loaders/web/apify_dataset.d.ts +0 -1
- package/document_loaders/web/apify_dataset.js +0 -1
- package/document_loaders/web/assemblyai.cjs +0 -1
- package/document_loaders/web/assemblyai.d.cts +0 -1
- package/document_loaders/web/assemblyai.d.ts +0 -1
- package/document_loaders/web/assemblyai.js +0 -1
- package/document_loaders/web/azure_blob_storage_container.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_container.js +0 -1
- package/document_loaders/web/azure_blob_storage_file.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_file.js +0 -1
- package/document_loaders/web/browserbase.cjs +0 -1
- package/document_loaders/web/browserbase.d.cts +0 -1
- package/document_loaders/web/browserbase.d.ts +0 -1
- package/document_loaders/web/browserbase.js +0 -1
- package/document_loaders/web/cheerio.cjs +0 -1
- package/document_loaders/web/cheerio.d.cts +0 -1
- package/document_loaders/web/cheerio.d.ts +0 -1
- package/document_loaders/web/cheerio.js +0 -1
- package/document_loaders/web/college_confidential.cjs +0 -1
- package/document_loaders/web/college_confidential.d.cts +0 -1
- package/document_loaders/web/college_confidential.d.ts +0 -1
- package/document_loaders/web/college_confidential.js +0 -1
- package/document_loaders/web/confluence.cjs +0 -1
- package/document_loaders/web/confluence.d.cts +0 -1
- package/document_loaders/web/confluence.d.ts +0 -1
- package/document_loaders/web/confluence.js +0 -1
- package/document_loaders/web/couchbase.cjs +0 -1
- package/document_loaders/web/couchbase.d.cts +0 -1
- package/document_loaders/web/couchbase.d.ts +0 -1
- package/document_loaders/web/couchbase.js +0 -1
- package/document_loaders/web/figma.cjs +0 -1
- package/document_loaders/web/figma.d.cts +0 -1
- package/document_loaders/web/figma.d.ts +0 -1
- package/document_loaders/web/figma.js +0 -1
- package/document_loaders/web/firecrawl.cjs +0 -1
- package/document_loaders/web/firecrawl.d.cts +0 -1
- package/document_loaders/web/firecrawl.d.ts +0 -1
- package/document_loaders/web/firecrawl.js +0 -1
- package/document_loaders/web/gitbook.cjs +0 -1
- package/document_loaders/web/gitbook.d.cts +0 -1
- package/document_loaders/web/gitbook.d.ts +0 -1
- package/document_loaders/web/gitbook.js +0 -1
- package/document_loaders/web/github.cjs +0 -1
- package/document_loaders/web/github.d.cts +0 -1
- package/document_loaders/web/github.d.ts +0 -1
- package/document_loaders/web/github.js +0 -1
- package/document_loaders/web/hn.cjs +0 -1
- package/document_loaders/web/hn.d.cts +0 -1
- package/document_loaders/web/hn.d.ts +0 -1
- package/document_loaders/web/hn.js +0 -1
- package/document_loaders/web/imsdb.cjs +0 -1
- package/document_loaders/web/imsdb.d.cts +0 -1
- package/document_loaders/web/imsdb.d.ts +0 -1
- package/document_loaders/web/imsdb.js +0 -1
- package/document_loaders/web/notionapi.cjs +0 -1
- package/document_loaders/web/notionapi.d.cts +0 -1
- package/document_loaders/web/notionapi.d.ts +0 -1
- package/document_loaders/web/notionapi.js +0 -1
- package/document_loaders/web/notiondb.cjs +0 -1
- package/document_loaders/web/notiondb.d.cts +0 -1
- package/document_loaders/web/notiondb.d.ts +0 -1
- package/document_loaders/web/notiondb.js +0 -1
- package/document_loaders/web/pdf.cjs +0 -1
- package/document_loaders/web/pdf.d.cts +0 -1
- package/document_loaders/web/pdf.d.ts +0 -1
- package/document_loaders/web/pdf.js +0 -1
- package/document_loaders/web/playwright.cjs +0 -1
- package/document_loaders/web/playwright.d.cts +0 -1
- package/document_loaders/web/playwright.d.ts +0 -1
- package/document_loaders/web/playwright.js +0 -1
- package/document_loaders/web/puppeteer.cjs +0 -1
- package/document_loaders/web/puppeteer.d.cts +0 -1
- package/document_loaders/web/puppeteer.d.ts +0 -1
- package/document_loaders/web/puppeteer.js +0 -1
- package/document_loaders/web/recursive_url.cjs +0 -1
- package/document_loaders/web/recursive_url.d.cts +0 -1
- package/document_loaders/web/recursive_url.d.ts +0 -1
- package/document_loaders/web/recursive_url.js +0 -1
- package/document_loaders/web/s3.cjs +0 -1
- package/document_loaders/web/s3.d.cts +0 -1
- package/document_loaders/web/s3.d.ts +0 -1
- package/document_loaders/web/s3.js +0 -1
- package/document_loaders/web/searchapi.cjs +0 -1
- package/document_loaders/web/searchapi.d.cts +0 -1
- package/document_loaders/web/searchapi.d.ts +0 -1
- package/document_loaders/web/searchapi.js +0 -1
- package/document_loaders/web/serpapi.cjs +0 -1
- package/document_loaders/web/serpapi.d.cts +0 -1
- package/document_loaders/web/serpapi.d.ts +0 -1
- package/document_loaders/web/serpapi.js +0 -1
- package/document_loaders/web/sitemap.cjs +0 -1
- package/document_loaders/web/sitemap.d.cts +0 -1
- package/document_loaders/web/sitemap.d.ts +0 -1
- package/document_loaders/web/sitemap.js +0 -1
- package/document_loaders/web/sonix_audio.cjs +0 -1
- package/document_loaders/web/sonix_audio.d.cts +0 -1
- package/document_loaders/web/sonix_audio.d.ts +0 -1
- package/document_loaders/web/sonix_audio.js +0 -1
- package/document_loaders/web/sort_xyz_blockchain.cjs +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.cts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.ts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.js +0 -1
- package/document_loaders/web/youtube.cjs +0 -1
- package/document_loaders/web/youtube.d.cts +0 -1
- package/document_loaders/web/youtube.d.ts +0 -1
- package/document_loaders/web/youtube.js +0 -1
- package/experimental/tools/pyinterpreter.cjs +0 -1
- package/experimental/tools/pyinterpreter.d.cts +0 -1
- package/experimental/tools/pyinterpreter.d.ts +0 -1
- package/experimental/tools/pyinterpreter.js +0 -1
- package/memory/index.cjs +0 -1
- package/memory/index.d.cts +0 -1
- package/memory/index.d.ts +0 -1
- package/memory/index.js +0 -1
- package/retrievers/self_query/chroma.cjs +0 -1
- package/retrievers/self_query/chroma.d.cts +0 -1
- package/retrievers/self_query/chroma.d.ts +0 -1
- package/retrievers/self_query/chroma.js +0 -1
- package/retrievers/self_query/pinecone.cjs +0 -1
- package/retrievers/self_query/pinecone.d.cts +0 -1
- package/retrievers/self_query/pinecone.d.ts +0 -1
- package/retrievers/self_query/pinecone.js +0 -1
- package/retrievers/self_query/supabase.cjs +0 -1
- package/retrievers/self_query/supabase.d.cts +0 -1
- package/retrievers/self_query/supabase.d.ts +0 -1
- package/retrievers/self_query/supabase.js +0 -1
- package/retrievers/self_query/vectara.cjs +0 -1
- package/retrievers/self_query/vectara.d.cts +0 -1
- package/retrievers/self_query/vectara.d.ts +0 -1
- package/retrievers/self_query/vectara.js +0 -1
- package/retrievers/self_query/weaviate.cjs +0 -1
- package/retrievers/self_query/weaviate.d.cts +0 -1
- package/retrievers/self_query/weaviate.d.ts +0 -1
- package/retrievers/self_query/weaviate.js +0 -1
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.S3Loader = void 0;
|
|
27
|
-
const fsDefault = __importStar(require("node:fs"));
|
|
28
|
-
const path = __importStar(require("node:path"));
|
|
29
|
-
const os = __importStar(require("node:os"));
|
|
30
|
-
const node_stream_1 = require("node:stream");
|
|
31
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
32
|
-
const base_js_1 = require("../base.cjs");
|
|
33
|
-
const unstructured_js_1 = require("../fs/unstructured.cjs");
|
|
34
|
-
const entrypoint_deprecation_js_1 = require("../../util/entrypoint_deprecation.cjs");
|
|
35
|
-
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion020MigrationWarning)({
|
|
36
|
-
oldEntrypointName: "document_loaders/web/s3",
|
|
37
|
-
newPackageName: "@langchain/community",
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/s3" instead. This entrypoint will be removed in 0.3.0.
|
|
41
|
-
*
|
|
42
|
-
* A class that extends the BaseDocumentLoader class. It represents a
|
|
43
|
-
* document loader for loading files from an S3 bucket.
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const loader = new S3Loader({
|
|
47
|
-
* bucket: "my-document-bucket-123",
|
|
48
|
-
* key: "AccountingOverview.pdf",
|
|
49
|
-
* s3Config: {
|
|
50
|
-
* region: "us-east-1",
|
|
51
|
-
* credentials: {
|
|
52
|
-
* accessKeyId: "<YourAccessKeyId>",
|
|
53
|
-
* secretAccessKey: "<YourSecretAccessKey>",
|
|
54
|
-
* },
|
|
55
|
-
* },
|
|
56
|
-
* unstructuredAPIURL: "<YourUnstructuredAPIURL>",
|
|
57
|
-
* unstructuredAPIKey: "<YourUnstructuredAPIKey>",
|
|
58
|
-
* });
|
|
59
|
-
* const docs = await loader.load();
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
class S3Loader extends base_js_1.BaseDocumentLoader {
|
|
63
|
-
constructor({ bucket, key, unstructuredAPIURL, unstructuredAPIKey, s3Config = {}, fs = fsDefault, UnstructuredLoader = unstructured_js_1.UnstructuredLoader, }) {
|
|
64
|
-
super();
|
|
65
|
-
Object.defineProperty(this, "bucket", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true,
|
|
69
|
-
value: void 0
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(this, "key", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
value: void 0
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(this, "unstructuredAPIURL", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
configurable: true,
|
|
80
|
-
writable: true,
|
|
81
|
-
value: void 0
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(this, "unstructuredAPIKey", {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
configurable: true,
|
|
86
|
-
writable: true,
|
|
87
|
-
value: void 0
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(this, "s3Config", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
configurable: true,
|
|
92
|
-
writable: true,
|
|
93
|
-
value: void 0
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(this, "_fs", {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
configurable: true,
|
|
98
|
-
writable: true,
|
|
99
|
-
value: void 0
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(this, "_UnstructuredLoader", {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
configurable: true,
|
|
104
|
-
writable: true,
|
|
105
|
-
value: void 0
|
|
106
|
-
});
|
|
107
|
-
this.bucket = bucket;
|
|
108
|
-
this.key = key;
|
|
109
|
-
this.unstructuredAPIURL = unstructuredAPIURL;
|
|
110
|
-
this.unstructuredAPIKey = unstructuredAPIKey;
|
|
111
|
-
this.s3Config = s3Config;
|
|
112
|
-
this._fs = fs;
|
|
113
|
-
this._UnstructuredLoader = UnstructuredLoader;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Loads the file from the S3 bucket, saves it to a temporary directory,
|
|
117
|
-
* and then uses the UnstructuredLoader to load the file as a document.
|
|
118
|
-
* @returns An array of Document objects representing the loaded documents.
|
|
119
|
-
*/
|
|
120
|
-
async load() {
|
|
121
|
-
const tempDir = this._fs.mkdtempSync(path.join(os.tmpdir(), "s3fileloader-"));
|
|
122
|
-
const filePath = path.join(tempDir, this.key);
|
|
123
|
-
try {
|
|
124
|
-
const s3Client = new client_s3_1.S3Client(this.s3Config);
|
|
125
|
-
const getObjectCommand = new client_s3_1.GetObjectCommand({
|
|
126
|
-
Bucket: this.bucket,
|
|
127
|
-
Key: this.key,
|
|
128
|
-
});
|
|
129
|
-
const response = await s3Client.send(getObjectCommand);
|
|
130
|
-
const objectData = await new Promise((resolve, reject) => {
|
|
131
|
-
const chunks = [];
|
|
132
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
133
|
-
if (response.Body instanceof node_stream_1.Readable) {
|
|
134
|
-
response.Body.on("data", (chunk) => chunks.push(chunk));
|
|
135
|
-
response.Body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
136
|
-
response.Body.on("error", reject);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
reject(new Error("Response body is not a readable stream."));
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
this._fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
143
|
-
this._fs.writeFileSync(filePath, objectData);
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
throw new Error(`Failed to download file ${this.key} from S3 bucket ${this.bucket}: ${e.message}`);
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
const options = {
|
|
151
|
-
apiUrl: this.unstructuredAPIURL,
|
|
152
|
-
apiKey: this.unstructuredAPIKey,
|
|
153
|
-
};
|
|
154
|
-
const unstructuredLoader = new this._UnstructuredLoader(filePath, options);
|
|
155
|
-
const docs = await unstructuredLoader.load();
|
|
156
|
-
return docs;
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
throw new Error(`Failed to load file ${filePath} using unstructured loader: ${e.message}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.S3Loader = S3Loader;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import * as fsDefault from "node:fs";
|
|
3
|
-
import { S3ClientConfig } from "@aws-sdk/client-s3";
|
|
4
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
5
|
-
import { UnstructuredLoader as UnstructuredLoaderDefault } from "../fs/unstructured.js";
|
|
6
|
-
/**
|
|
7
|
-
* Represents the configuration options for the S3 client. It extends the
|
|
8
|
-
* S3ClientConfig interface from the "@aws-sdk/client-s3" package and
|
|
9
|
-
* includes additional deprecated properties for access key ID and secret
|
|
10
|
-
* access key.
|
|
11
|
-
*/
|
|
12
|
-
export type S3Config = S3ClientConfig & {
|
|
13
|
-
/** @deprecated Use the credentials object instead */
|
|
14
|
-
accessKeyId?: string;
|
|
15
|
-
/** @deprecated Use the credentials object instead */
|
|
16
|
-
secretAccessKey?: string;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/s3" instead. This entrypoint will be removed in 0.3.0.
|
|
20
|
-
*
|
|
21
|
-
* Represents the parameters for the S3Loader class. It includes
|
|
22
|
-
* properties such as the S3 bucket, key, unstructured API URL,
|
|
23
|
-
* unstructured API key, S3 configuration, file system module, and
|
|
24
|
-
* UnstructuredLoader module.
|
|
25
|
-
*/
|
|
26
|
-
export interface S3LoaderParams {
|
|
27
|
-
bucket: string;
|
|
28
|
-
key: string;
|
|
29
|
-
unstructuredAPIURL: string;
|
|
30
|
-
unstructuredAPIKey: string;
|
|
31
|
-
s3Config?: S3Config & {
|
|
32
|
-
/** @deprecated Use the credentials object instead */
|
|
33
|
-
accessKeyId?: string;
|
|
34
|
-
/** @deprecated Use the credentials object instead */
|
|
35
|
-
secretAccessKey?: string;
|
|
36
|
-
};
|
|
37
|
-
fs?: typeof fsDefault;
|
|
38
|
-
UnstructuredLoader?: typeof UnstructuredLoaderDefault;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/s3" instead. This entrypoint will be removed in 0.3.0.
|
|
42
|
-
*
|
|
43
|
-
* A class that extends the BaseDocumentLoader class. It represents a
|
|
44
|
-
* document loader for loading files from an S3 bucket.
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const loader = new S3Loader({
|
|
48
|
-
* bucket: "my-document-bucket-123",
|
|
49
|
-
* key: "AccountingOverview.pdf",
|
|
50
|
-
* s3Config: {
|
|
51
|
-
* region: "us-east-1",
|
|
52
|
-
* credentials: {
|
|
53
|
-
* accessKeyId: "<YourAccessKeyId>",
|
|
54
|
-
* secretAccessKey: "<YourSecretAccessKey>",
|
|
55
|
-
* },
|
|
56
|
-
* },
|
|
57
|
-
* unstructuredAPIURL: "<YourUnstructuredAPIURL>",
|
|
58
|
-
* unstructuredAPIKey: "<YourUnstructuredAPIKey>",
|
|
59
|
-
* });
|
|
60
|
-
* const docs = await loader.load();
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare class S3Loader extends BaseDocumentLoader {
|
|
64
|
-
private bucket;
|
|
65
|
-
private key;
|
|
66
|
-
private unstructuredAPIURL;
|
|
67
|
-
private unstructuredAPIKey;
|
|
68
|
-
private s3Config;
|
|
69
|
-
private _fs;
|
|
70
|
-
private _UnstructuredLoader;
|
|
71
|
-
constructor({ bucket, key, unstructuredAPIURL, unstructuredAPIKey, s3Config, fs, UnstructuredLoader, }: S3LoaderParams);
|
|
72
|
-
/**
|
|
73
|
-
* Loads the file from the S3 bucket, saves it to a temporary directory,
|
|
74
|
-
* and then uses the UnstructuredLoader to load the file as a document.
|
|
75
|
-
* @returns An array of Document objects representing the loaded documents.
|
|
76
|
-
*/
|
|
77
|
-
load(): Promise<import("@langchain/core/documents").Document<Record<string, any>>[]>;
|
|
78
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import * as fsDefault from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as os from "node:os";
|
|
4
|
-
import { Readable } from "node:stream";
|
|
5
|
-
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
|
6
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
7
|
-
import { UnstructuredLoader as UnstructuredLoaderDefault } from "../fs/unstructured.js";
|
|
8
|
-
import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation.js";
|
|
9
|
-
/* #__PURE__ */ logVersion020MigrationWarning({
|
|
10
|
-
oldEntrypointName: "document_loaders/web/s3",
|
|
11
|
-
newPackageName: "@langchain/community",
|
|
12
|
-
});
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/s3" instead. This entrypoint will be removed in 0.3.0.
|
|
15
|
-
*
|
|
16
|
-
* A class that extends the BaseDocumentLoader class. It represents a
|
|
17
|
-
* document loader for loading files from an S3 bucket.
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const loader = new S3Loader({
|
|
21
|
-
* bucket: "my-document-bucket-123",
|
|
22
|
-
* key: "AccountingOverview.pdf",
|
|
23
|
-
* s3Config: {
|
|
24
|
-
* region: "us-east-1",
|
|
25
|
-
* credentials: {
|
|
26
|
-
* accessKeyId: "<YourAccessKeyId>",
|
|
27
|
-
* secretAccessKey: "<YourSecretAccessKey>",
|
|
28
|
-
* },
|
|
29
|
-
* },
|
|
30
|
-
* unstructuredAPIURL: "<YourUnstructuredAPIURL>",
|
|
31
|
-
* unstructuredAPIKey: "<YourUnstructuredAPIKey>",
|
|
32
|
-
* });
|
|
33
|
-
* const docs = await loader.load();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export class S3Loader extends BaseDocumentLoader {
|
|
37
|
-
constructor({ bucket, key, unstructuredAPIURL, unstructuredAPIKey, s3Config = {}, fs = fsDefault, UnstructuredLoader = UnstructuredLoaderDefault, }) {
|
|
38
|
-
super();
|
|
39
|
-
Object.defineProperty(this, "bucket", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "key", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, "unstructuredAPIURL", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "unstructuredAPIKey", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "s3Config", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "_fs", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: void 0
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(this, "_UnstructuredLoader", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
|
-
this.bucket = bucket;
|
|
82
|
-
this.key = key;
|
|
83
|
-
this.unstructuredAPIURL = unstructuredAPIURL;
|
|
84
|
-
this.unstructuredAPIKey = unstructuredAPIKey;
|
|
85
|
-
this.s3Config = s3Config;
|
|
86
|
-
this._fs = fs;
|
|
87
|
-
this._UnstructuredLoader = UnstructuredLoader;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Loads the file from the S3 bucket, saves it to a temporary directory,
|
|
91
|
-
* and then uses the UnstructuredLoader to load the file as a document.
|
|
92
|
-
* @returns An array of Document objects representing the loaded documents.
|
|
93
|
-
*/
|
|
94
|
-
async load() {
|
|
95
|
-
const tempDir = this._fs.mkdtempSync(path.join(os.tmpdir(), "s3fileloader-"));
|
|
96
|
-
const filePath = path.join(tempDir, this.key);
|
|
97
|
-
try {
|
|
98
|
-
const s3Client = new S3Client(this.s3Config);
|
|
99
|
-
const getObjectCommand = new GetObjectCommand({
|
|
100
|
-
Bucket: this.bucket,
|
|
101
|
-
Key: this.key,
|
|
102
|
-
});
|
|
103
|
-
const response = await s3Client.send(getObjectCommand);
|
|
104
|
-
const objectData = await new Promise((resolve, reject) => {
|
|
105
|
-
const chunks = [];
|
|
106
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
107
|
-
if (response.Body instanceof Readable) {
|
|
108
|
-
response.Body.on("data", (chunk) => chunks.push(chunk));
|
|
109
|
-
response.Body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
110
|
-
response.Body.on("error", reject);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
reject(new Error("Response body is not a readable stream."));
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
this._fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
117
|
-
this._fs.writeFileSync(filePath, objectData);
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
throw new Error(`Failed to download file ${this.key} from S3 bucket ${this.bucket}: ${e.message}`);
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
const options = {
|
|
125
|
-
apiUrl: this.unstructuredAPIURL,
|
|
126
|
-
apiKey: this.unstructuredAPIKey,
|
|
127
|
-
};
|
|
128
|
-
const unstructuredLoader = new this._UnstructuredLoader(filePath, options);
|
|
129
|
-
const docs = await unstructuredLoader.load();
|
|
130
|
-
return docs;
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
-
}
|
|
133
|
-
catch (e) {
|
|
134
|
-
throw new Error(`Failed to load file ${filePath} using unstructured loader: ${e.message}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchApiLoader = void 0;
|
|
4
|
-
const documents_1 = require("@langchain/core/documents");
|
|
5
|
-
const env_1 = require("@langchain/core/utils/env");
|
|
6
|
-
const base_js_1 = require("../base.cjs");
|
|
7
|
-
const entrypoint_deprecation_js_1 = require("../../util/entrypoint_deprecation.cjs");
|
|
8
|
-
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion020MigrationWarning)({
|
|
9
|
-
oldEntrypointName: "document_loaders/web/searchapi",
|
|
10
|
-
newPackageName: "@langchain/community",
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/searchapi" instead. This entrypoint will be removed in 0.3.0.
|
|
14
|
-
*
|
|
15
|
-
* Class representing a document loader for loading search results from
|
|
16
|
-
* the SearchApi. It extends the BaseDocumentLoader class.
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const loader = new SearchApiLoader({
|
|
20
|
-
* q: "{query}",
|
|
21
|
-
* apiKey: "{apiKey}",
|
|
22
|
-
* engine: "google",
|
|
23
|
-
* });
|
|
24
|
-
* const docs = await loader.load();
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
class SearchApiLoader extends base_js_1.BaseDocumentLoader {
|
|
28
|
-
constructor(params) {
|
|
29
|
-
super();
|
|
30
|
-
Object.defineProperty(this, "apiKey", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "parameters", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
const { apiKey = (0, env_1.getEnvironmentVariable)("SEARCHAPI_API_KEY") } = params;
|
|
43
|
-
if (typeof apiKey !== "string") {
|
|
44
|
-
throw new Error("Invalid type for apiKey. Expected string.");
|
|
45
|
-
}
|
|
46
|
-
if (!apiKey) {
|
|
47
|
-
throw new Error("SearchApi API key not set. You can set it as SEARCHAPI_API_KEY in your .env file, or pass it to SearchApi.");
|
|
48
|
-
}
|
|
49
|
-
this.apiKey = apiKey;
|
|
50
|
-
this.parameters = { ...params };
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Builds the URL for the SearchApi search request.
|
|
54
|
-
* @returns The URL for the search request.
|
|
55
|
-
*/
|
|
56
|
-
buildUrl() {
|
|
57
|
-
this.parameters = {
|
|
58
|
-
engine: "google",
|
|
59
|
-
api_key: this.apiKey,
|
|
60
|
-
...this.parameters,
|
|
61
|
-
};
|
|
62
|
-
const preparedParams = Object.entries(this.parameters)
|
|
63
|
-
.filter(([key, value]) => value !== undefined && value !== null && key !== "apiKey")
|
|
64
|
-
.map(([key, value]) => [key, `${value}`]);
|
|
65
|
-
const searchParams = new URLSearchParams(preparedParams);
|
|
66
|
-
return `https://www.searchapi.io/api/v1/search?${searchParams}`;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Extracts documents from the provided output.
|
|
70
|
-
* @param output - The output to extract documents from.
|
|
71
|
-
* @param responseType - The type of the response to extract documents from.
|
|
72
|
-
* @returns An array of Documents.
|
|
73
|
-
*/
|
|
74
|
-
extractDocuments(output, responseType) {
|
|
75
|
-
const documents = [];
|
|
76
|
-
const results = Array.isArray(output) ? output : [output];
|
|
77
|
-
if (responseType === "transcripts") {
|
|
78
|
-
const pageContent = results.map((result) => result.text).join("\n");
|
|
79
|
-
const metadata = {
|
|
80
|
-
source: "SearchApi",
|
|
81
|
-
responseType,
|
|
82
|
-
};
|
|
83
|
-
documents.push(new documents_1.Document({ pageContent, metadata }));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
for (const result of results) {
|
|
87
|
-
const pageContent = JSON.stringify(result);
|
|
88
|
-
const metadata = {
|
|
89
|
-
source: "SearchApi",
|
|
90
|
-
responseType,
|
|
91
|
-
};
|
|
92
|
-
documents.push(new documents_1.Document({ pageContent, metadata }));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return documents;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Processes the response data from the SearchApi search request and converts it into an array of Documents.
|
|
99
|
-
* @param data - The response data from the SearchApi search request.
|
|
100
|
-
* @returns An array of Documents.
|
|
101
|
-
*/
|
|
102
|
-
processResponseData(data) {
|
|
103
|
-
const documents = [];
|
|
104
|
-
const responseTypes = [
|
|
105
|
-
"answer_box",
|
|
106
|
-
"shopping_results",
|
|
107
|
-
"knowledge_graph",
|
|
108
|
-
"organic_results",
|
|
109
|
-
"transcripts",
|
|
110
|
-
];
|
|
111
|
-
for (const responseType of responseTypes) {
|
|
112
|
-
if (responseType in data) {
|
|
113
|
-
documents.push(...this.extractDocuments(data[responseType], responseType));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return documents;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Fetches the data from the provided URL and returns it as a JSON object.
|
|
120
|
-
* If an error occurs during the fetch operation, an exception is thrown with the error message.
|
|
121
|
-
* @param url - The URL to fetch data from.
|
|
122
|
-
* @returns A promise that resolves to the fetched data as a JSON object.
|
|
123
|
-
* @throws An error if the fetch operation fails.
|
|
124
|
-
*/
|
|
125
|
-
async fetchData(url) {
|
|
126
|
-
const response = await fetch(url);
|
|
127
|
-
const data = await response.json();
|
|
128
|
-
if (data.error) {
|
|
129
|
-
throw new Error(`Failed to load search results from SearchApi due to: ${data.error}`);
|
|
130
|
-
}
|
|
131
|
-
return data;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Loads the search results from the SearchApi.
|
|
135
|
-
* @returns An array of Documents representing the search results.
|
|
136
|
-
* @throws An error if the search results could not be loaded.
|
|
137
|
-
*/
|
|
138
|
-
async load() {
|
|
139
|
-
const url = this.buildUrl();
|
|
140
|
-
const data = await this.fetchData(url);
|
|
141
|
-
try {
|
|
142
|
-
return this.processResponseData(data);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
console.error(error);
|
|
146
|
-
throw new Error(`Failed to process search results from SearchApi: ${error}`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.SearchApiLoader = SearchApiLoader;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Document } from "@langchain/core/documents";
|
|
2
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
3
|
-
type JSONPrimitive = string | number | boolean | null;
|
|
4
|
-
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
5
|
-
interface JSONObject {
|
|
6
|
-
[key: string]: JSONValue;
|
|
7
|
-
}
|
|
8
|
-
interface JSONArray extends Array<JSONValue> {
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* SearchApiParameters Type Definition.
|
|
12
|
-
*
|
|
13
|
-
* For more parameters and supported search engines, refer specific engine documentation:
|
|
14
|
-
* Google - https://www.searchapi.io/docs/google
|
|
15
|
-
* Google News - https://www.searchapi.io/docs/google-news
|
|
16
|
-
* Google Scholar - https://www.searchapi.io/docs/google-scholar
|
|
17
|
-
* YouTube Transcripts - https://www.searchapi.io/docs/youtube-transcripts
|
|
18
|
-
* and others.
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
type SearchApiParameters = {
|
|
22
|
-
[key: string]: JSONValue;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated - Import from "@langchain/community/document_loaders/web/searchapi" instead. This entrypoint will be removed in 0.3.0.
|
|
26
|
-
*
|
|
27
|
-
* Class representing a document loader for loading search results from
|
|
28
|
-
* the SearchApi. It extends the BaseDocumentLoader class.
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const loader = new SearchApiLoader({
|
|
32
|
-
* q: "{query}",
|
|
33
|
-
* apiKey: "{apiKey}",
|
|
34
|
-
* engine: "google",
|
|
35
|
-
* });
|
|
36
|
-
* const docs = await loader.load();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare class SearchApiLoader extends BaseDocumentLoader {
|
|
40
|
-
private apiKey;
|
|
41
|
-
private parameters;
|
|
42
|
-
constructor(params: SearchApiParameters);
|
|
43
|
-
/**
|
|
44
|
-
* Builds the URL for the SearchApi search request.
|
|
45
|
-
* @returns The URL for the search request.
|
|
46
|
-
*/
|
|
47
|
-
buildUrl(): string;
|
|
48
|
-
/**
|
|
49
|
-
* Extracts documents from the provided output.
|
|
50
|
-
* @param output - The output to extract documents from.
|
|
51
|
-
* @param responseType - The type of the response to extract documents from.
|
|
52
|
-
* @returns An array of Documents.
|
|
53
|
-
*/
|
|
54
|
-
private extractDocuments;
|
|
55
|
-
/**
|
|
56
|
-
* Processes the response data from the SearchApi search request and converts it into an array of Documents.
|
|
57
|
-
* @param data - The response data from the SearchApi search request.
|
|
58
|
-
* @returns An array of Documents.
|
|
59
|
-
*/
|
|
60
|
-
processResponseData(data: Record<string, unknown>): Document[];
|
|
61
|
-
/**
|
|
62
|
-
* Fetches the data from the provided URL and returns it as a JSON object.
|
|
63
|
-
* If an error occurs during the fetch operation, an exception is thrown with the error message.
|
|
64
|
-
* @param url - The URL to fetch data from.
|
|
65
|
-
* @returns A promise that resolves to the fetched data as a JSON object.
|
|
66
|
-
* @throws An error if the fetch operation fails.
|
|
67
|
-
*/
|
|
68
|
-
private fetchData;
|
|
69
|
-
/**
|
|
70
|
-
* Loads the search results from the SearchApi.
|
|
71
|
-
* @returns An array of Documents representing the search results.
|
|
72
|
-
* @throws An error if the search results could not be loaded.
|
|
73
|
-
*/
|
|
74
|
-
load(): Promise<Document[]>;
|
|
75
|
-
}
|
|
76
|
-
export {};
|