MCPcopy
hub / github.com/guangzhengli/ChatFiles / getDocumentLoader

Function getDocumentLoader

utils/langchain/documentLoader.ts:10–48  ·  view source on GitHub ↗
(fileType: string, filePath: string)

Source from the content-addressed store, hash-verified

8import {UnstructuredLoader} from "langchain/document_loaders/fs/unstructured";
9
10export function getDocumentLoader(fileType: string, filePath: string): DocumentLoader {
11 let loader;
12 switch (fileType) {
13 case "pdf":
14 loader = new PDFLoader(filePath, {
15 splitPages: false,
16 });
17 return loader;
18 case "epub":
19 loader = new EPubLoader(
20 filePath, {
21 splitChapters: false,
22 });
23 return loader;
24 case "docx":
25 loader = new DocxLoader(
26 filePath
27 );
28 return loader;
29 case "txt":
30 loader = new TextLoader(filePath);
31 return loader;
32 case "md":
33 loader = new TextLoader(filePath);
34 return loader;
35 case "json":
36 // JSONLoader is not implemented with split option
37 loader = new TextLoader(filePath);
38 return loader;
39 case "csv":
40 loader = new CSVLoader(filePath);
41 return loader;
42 case "zip":
43 return getDirectoryLoader(filePath)
44 default:
45 loader = new UnstructuredLoader(filePath);
46 return loader;
47 }
48}
49
50export function getDirectoryLoader(path: string): DocumentLoader {
51 const zipFilePath = path.split('.')[0];

Callers 2

handlerFunction · 0.90
getDirectoryLoaderFunction · 0.85

Calls 1

getDirectoryLoaderFunction · 0.85

Tested by

no test coverage detected