mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00

* chore: bun scripts * feat: comparisons * refactor: move scripts to own folder * feat: generated prompts script and Es output * feat: generated prompts * created prompts * feat: Russian localization prompts * translation setup * additional ES translations * additional ES translations * translation services * feat: additional translations * fix regex for parseParamPrompt * RU translations * remove stores from git * update gitignore * update gitignore * ZH translations * move gen prompt output location * ZH traditional translations * AR translations * chore: rename * JP * cleanup scripts * add additional instruction prompts * fix translation prompt and add DE * FR translations (rate limited so not complete) * chore: update translation comparisons * chore: remove unused AnthropicClient changes * refactor: use compositional styling for archive/delete buttons, fix manage archive table styling
43 lines
No EOL
1.5 KiB
TypeScript
43 lines
No EOL
1.5 KiB
TypeScript
import dotenv from 'dotenv';
|
|
dotenv.config({
|
|
path: './',
|
|
});
|
|
import { OpenAIEmbeddings } from "@langchain/openai";
|
|
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
|
|
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
export const storeEmbeddings = async (modulePath: string) => {
|
|
try {
|
|
const text = fs.readFileSync(modulePath, "utf8");
|
|
const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 600 });
|
|
const docs = await textSplitter.createDocuments([text]);
|
|
const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings());
|
|
const directory = `./config/translations/stores/${path.basename(modulePath)}`;
|
|
|
|
if (!fs.existsSync(directory)) {
|
|
fs.mkdirSync(directory, { recursive: true });
|
|
console.log(`Directory created: ${directory}`);
|
|
} else {
|
|
console.log(`Directory already exists: ${directory}`);
|
|
return;
|
|
}
|
|
|
|
await vectorStore.save(directory);
|
|
} catch (error) {
|
|
console.error(`Error storing embeddings`);
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
export const loadEmbeddings = async (modulePath: string) => {
|
|
try {
|
|
const directory = `./config/translations/stores/${path.basename(modulePath)}`;
|
|
const loadedVectorStore = await HNSWLib.load(directory, new OpenAIEmbeddings());
|
|
return loadedVectorStore;
|
|
} catch (error) {
|
|
console.error(`Error loading embeddings`);
|
|
console.error(error);
|
|
}
|
|
} |