import { Config, Provide } from '@midwayjs/core';
import {
  UnstructuredLoader,
  UnstructuredLoaderOptions,
} from '@langchain/community/document_loaders/fs/unstructured';

/**
 * 非结构化文档加载器
 */
@Provide()
export class KnowUnstructuredLoader {
  @Config('module.know.unstructured')
  options: UnstructuredLoaderOptions;

  /**
   * 加载文档
   * @param filePath
   */
  async loadFile(filePath: string) {
    const loader = new UnstructuredLoader(filePath, this.options);
    const docs = await loader.load();
    return docs;
  }
}
