(fileType: string, filePath: string)
| 8 | import {UnstructuredLoader} from "langchain/document_loaders/fs/unstructured"; |
| 9 | |
| 10 | export 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 | |
| 50 | export function getDirectoryLoader(path: string): DocumentLoader { |
| 51 | const zipFilePath = path.split('.')[0]; |
no test coverage detected