Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
feat: add typescript support (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
cachho authored Jul 6, 2023
1 parent d8b439d commit 36d8baf
Show file tree
Hide file tree
Showing 41 changed files with 2,398 additions and 460 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ dist
.pnp.*

.ideas.md
.todos.md
.todos.md

# Custom
dist
types
build
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const { createHash } = require("crypto");
import { createHash } from "crypto";
import { BaseLoader, } from "../loaders";
import { Input, LoaderResult } from "../models";
import { ChunkResult } from "../models/ChunkResult";

class BaseChunker {
constructor(text_splitter) {
text_splitter: any; // the type of text_splitter is not specified in your code

constructor(text_splitter: any) {
this.text_splitter = text_splitter;
}

async create_chunks(loader, url) {
const documents = [];
const ids = [];
const datas = await loader.load_data(url);
const metadatas = [];
async create_chunks(loader: BaseLoader, url: Input): Promise<ChunkResult> {
const documents: ChunkResult['documents'] = [];
const ids: ChunkResult['ids'] = [];
const datas: LoaderResult = await loader.load_data(url);
const metadatas: ChunkResult['metadatas'] = [];
for (const data of datas) {
const content = data["content"];
const meta_data = data["meta_data"];
Expand All @@ -32,4 +37,4 @@ class BaseChunker {
}
}

module.exports = { BaseChunker };
export { BaseChunker };
25 changes: 25 additions & 0 deletions embedchain/chunkers/PdfFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseChunker } from "./BaseChunker";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";

interface TextSplitterChunkParams {
chunkSize: number;
chunkOverlap: number;
keepSeparator: boolean;
}

const TEXT_SPLITTER_CHUNK_PARAMS: TextSplitterChunkParams = {
chunkSize: 1000,
chunkOverlap: 0,
keepSeparator: false,
};

class PdfFileChunker extends BaseChunker {
constructor() {
const text_splitter = new RecursiveCharacterTextSplitter(
TEXT_SPLITTER_CHUNK_PARAMS
);
super(text_splitter);
}
}

export { PdfFileChunker };
25 changes: 25 additions & 0 deletions embedchain/chunkers/QnaPair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseChunker } from "./BaseChunker";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";

interface TextSplitterChunkParams {
chunkSize: number;
chunkOverlap: number;
keepSeparator: boolean;
}

const TEXT_SPLITTER_CHUNK_PARAMS: TextSplitterChunkParams = {
chunkSize: 300,
chunkOverlap: 0,
keepSeparator: false,
};

class QnaPairChunker extends BaseChunker {
constructor() {
const text_splitter = new RecursiveCharacterTextSplitter(
TEXT_SPLITTER_CHUNK_PARAMS
);
super(text_splitter);
}
}

export { QnaPairChunker };
25 changes: 25 additions & 0 deletions embedchain/chunkers/WebPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseChunker } from "./BaseChunker";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";

interface TextSplitterChunkParams {
chunkSize: number;
chunkOverlap: number;
keepSeparator: boolean;
}

const TEXT_SPLITTER_CHUNK_PARAMS: TextSplitterChunkParams = {
chunkSize: 500,
chunkOverlap: 0,
keepSeparator: false,
};

class WebPageChunker extends BaseChunker {
constructor() {
const text_splitter = new RecursiveCharacterTextSplitter(
TEXT_SPLITTER_CHUNK_PARAMS
);
super(text_splitter);
}
}

export { WebPageChunker };
9 changes: 0 additions & 9 deletions embedchain/chunkers/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions embedchain/chunkers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BaseChunker } from "./BaseChunker";
import { PdfFileChunker } from "./PdfFile";
import { QnaPairChunker } from "./QnaPair";
import { WebPageChunker } from "./WebPage";

export { BaseChunker, PdfFileChunker, QnaPairChunker, WebPageChunker }
19 changes: 0 additions & 19 deletions embedchain/chunkers/pdf_file.js

This file was deleted.

19 changes: 0 additions & 19 deletions embedchain/chunkers/qna_pair.js

This file was deleted.

19 changes: 0 additions & 19 deletions embedchain/chunkers/web_page.js

This file was deleted.

Loading

0 comments on commit 36d8baf

Please sign in to comment.