Skip to content

Commit

Permalink
fix: fixed debug message string fro createLoaderFromMimeType
Browse files Browse the repository at this point in the history
  • Loading branch information
adhityan committed Oct 6, 2024
1 parent 36d474a commit abf5901
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/embedjs/src/util/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseLoader } from '@llm-tools/embedjs-interfaces';
import { TextLoader } from '../loaders/text-loader.js';

export async function createLoaderFromMimeType(loader: string, mimeType: string): Promise<BaseLoader> {
createDebugMessages('embedjs:core:createLoaderFromMimeType')(`Incoming mime type '${mimeType}'`);
createDebugMessages('embedjs:util:createLoaderFromMimeType')(`Incoming mime type '${mimeType}'`);

switch (mimeType) {
case 'application/msword':
Expand All @@ -14,7 +14,7 @@ export async function createLoaderFromMimeType(loader: string, mimeType: string)
'Package `@llm-tools/embedjs-loader-msoffice` needs to be installed to load docx files',
);
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported DocxLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported DocxLoader');
return new DocxLoader({ filePathOrUrl: loader });
}
case 'application/vnd.ms-excel':
Expand All @@ -24,14 +24,14 @@ export async function createLoaderFromMimeType(loader: string, mimeType: string)
'Package `@llm-tools/embedjs-loader-msoffice` needs to be installed to load excel files',
);
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported ExcelLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported ExcelLoader');
return new ExcelLoader({ filePathOrUrl: loader });
}
case 'application/pdf': {
const { PdfLoader } = await import('@llm-tools/embedjs-loader-pdf').catch(() => {
throw new Error('Package `@llm-tools/embedjs-loader-pdf` needs to be installed to load PDF files');
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported PdfLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported PdfLoader');
return new PdfLoader({ filePathOrUrl: loader });
}
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': {
Expand All @@ -40,40 +40,40 @@ export async function createLoaderFromMimeType(loader: string, mimeType: string)
'Package `@llm-tools/embedjs-loader-msoffice` needs to be installed to load pptx files',
);
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported PptLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported PptLoader');
return new PptLoader({ filePathOrUrl: loader });
}
case 'text/plain': {
const fineType = mime.getType(loader);
createDebugMessages('embedjs:core:createLoaderFromMimeType')(`Fine type for '${loader}' is '${fineType}'`);
createDebugMessages('embedjs:util:createLoaderFromMimeType')(`Fine type for '${loader}' is '${fineType}'`);
if (fineType === 'text/csv') {
const { CsvLoader } = await import('@llm-tools/embedjs-loader-csv').catch(() => {
throw new Error('Package `@llm-tools/embedjs-loader-csv` needs to be installed to load csv files');
});

createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported CsvLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported CsvLoader');
return new CsvLoader({ filePathOrUrl: loader });
} else return new TextLoader({ text: loader });
}
case 'application/csv': {
const { CsvLoader } = await import('@llm-tools/embedjs-loader-csv').catch(() => {
throw new Error('Package `@llm-tools/embedjs-loader-csv` needs to be installed to load csv files');
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported CsvLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported CsvLoader');
return new CsvLoader({ filePathOrUrl: loader });
}
case 'text/html': {
const { WebLoader } = await import('@llm-tools/embedjs-loader-web').catch(() => {
throw new Error('Package `@llm-tools/embedjs-loader-web` needs to be installed to load web documents');
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported WebLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported WebLoader');
return new WebLoader({ urlOrContent: loader });
}
case 'text/xml': {
const { SitemapLoader } = await import('@llm-tools/embedjs-loader-sitemap').catch(() => {
throw new Error('Package `@llm-tools/embedjs-loader-sitemap` needs to be installed to load sitemaps');
});
createDebugMessages('embedjs:core:createLoaderFromMimeType')('Dynamically imported SitemapLoader');
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported SitemapLoader');

if (await SitemapLoader.test(loader)) {
return new SitemapLoader({ url: loader });
Expand Down

0 comments on commit abf5901

Please sign in to comment.