Skip to content

Commit

Permalink
Merge branch 'main' of github.com:b4s36t4/local-rag
Browse files Browse the repository at this point in the history
  • Loading branch information
b4s36t4 committed Jun 25, 2024
2 parents 8a20c35 + 9c39a7f commit 0c015ca
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
69 changes: 69 additions & 0 deletions src/agents/ChatSQL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { SearchResult } from "voy-search";
import { ModelInstance } from "./BaseInstance";
import type { MLCEngine } from "@mlc-ai/web-llm";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { WorkerPostTypes } from "../const";

export class ChatSQL extends ModelInstance {
static instance: ModelInstance | null = null;
model: MLCEngine | null = null;
splitter: RecursiveCharacterTextSplitter | null = null;
// loader: WebPDFLoader | null = null
worker: Worker | null = null;

cacheHandle: FileSystemDirectoryHandle | null = null;

static cacheNameStatic: string = "chat_sql";

constructor(model: MLCEngine, worker: Worker) {
super("chat_sql", "chat_sql");
this.model = model;
this.splitter = new RecursiveCharacterTextSplitter({
chunkSize: 500,
chunkOverlap: 12,
});
this.worker = worker;

this.worker.addEventListener("message", (event) => {
const { type } = event.data;

if (type === WorkerPostTypes.embedDocument) {
console.log("[Embed] Document embed created");
if (!event.data.data?.length) {
console.log(
"%c[Embed Error]",
"background-color: red;padding:2px;color:white",
"Can't embed"
);
return;
}
window.db.add({
embeddings: [
{
embeddings: event.data.data.at(0),
id: crypto.randomUUID(),
title: event.data.payload,
url: "",
},
],
});
console.log("[Embed] Added into Vector Search");
}

return;
});
}

addIndex(data: string | string[]): void {
throw new Error("Method not implemented.");
}
search(question: number[], count?: number): SearchResult {
return window.db.search(question as any, count || 5);
}
saveToCache(): void {
throw new Error("Method not implemented.");
}
loadCache(): void {
throw new Error("Method not implemented.");
}
}
1 change: 1 addition & 0 deletions src/embed/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface EmbedEvent {
data: string | string[];
id: string;
type: "embedDocument" | "embedQuestion" | "initiate";
from?: "chat_pdf" | "chat_sql";
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/pages/agents.astro
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ const agents = [
});
window.modal.open();

console.log(editor.getValue(), "value");

monacoInstance?.classList.remove("hidden");
};

Expand Down

0 comments on commit 0c015ca

Please sign in to comment.