-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.js
More file actions
33 lines (28 loc) · 995 Bytes
/
temp.js
File metadata and controls
33 lines (28 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import fs from "fs/promises";
import { createClient } from "@supabase/supabase-js";
import { SupabaseVectorStore } from "langchain/vectorstores/supabase";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
try {
const text = await fs.readFile("knowledge/info.txt", "utf-8");
const splitter = new RecursiveCharacterTextSplitter({
chunkSize: 500,
chunkOverlap: 50,
});
const output = await splitter.createDocuments([text]);
const sbApiKey = process.env.SUPABASE_API_KEY;
const sbUrl = process.env.SUPABASE_URL_LC_CHATBOT;
const openAIApiKey = process.env.OPENAI_API_KEY;
const client = createClient(sbUrl, sbApiKey);
let res = await SupabaseVectorStore.fromDocuments(
output,
new OpenAIEmbeddings({ openAIApiKey }),
{
client,
tableName: "documents",
}
);
console.log("Supabase", res);
} catch (error) {
console.dir("This went wrong:", error);
}