-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentupload.js
38 lines (24 loc) · 1.01 KB
/
documentupload.js
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
34
35
36
37
38
import {RecursiveCharacterTextSplitter} from "langchain/text_splitter"
import {createClient} from "@supabase/supabase-js"
import { SupabaseVectorStore } from "@langchain/community/vectorstores/supabase";
import { OpenAIEmbeddings,ChatOpenAI } from "@langchain/openai";
import { promises as fs } from 'fs';
try {
const text = await fs.readFile("scrimba-info.text","utf-8")
const splitter = new RecursiveCharacterTextSplitter({
chunkSize:500,
separators:['\n\n','\n',' ',''],
chunkOverlap:50
})
const output = await splitter.createDocuments([text])
const sbApiKey= process.env.SUPABASE_API_KEY
const sbUrl= process.env.SUPABASE_URL_CHAT_BOT
const openAIApiKey = process.env.OPENAI_API_KEY
const embeddings = new OpenAIEmbeddings({openAIApiKey});
const client = createClient(
sbUrl, sbApiKey
);
await SupabaseVectorStore.fromDocuments(output,embeddings,{client,tableName:'documents'});
} catch (error) {
console.log(error)
}