mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
feat: reorganize api files, add mongoMeili
This commit is contained in:
parent
854f1c3572
commit
9995a159aa
15 changed files with 200 additions and 45 deletions
|
|
@ -1,52 +0,0 @@
|
|||
const { ModelOperations } = require('@vscode/vscode-languagedetection');
|
||||
const languages = require('../utils/languages.js');
|
||||
const codeRegex = /(```[\s\S]*?```)/g;
|
||||
// const languageMatch = /```(\w+)/;
|
||||
const replaceRegex = /```\w+\n/g;
|
||||
|
||||
const detectCode = async (input) => {
|
||||
try {
|
||||
let text = input;
|
||||
if (!text.match(codeRegex)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const langMatches = text.match(replaceRegex);
|
||||
|
||||
if (langMatches?.length > 0) {
|
||||
langMatches.forEach(match => {
|
||||
let lang = match.split('```')[1].trim();
|
||||
|
||||
if (languages.has(lang)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[detectCode.js] replacing', match, 'with', '```shell');
|
||||
text = text.replace(match, '```shell\n');
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
const modelOperations = new ModelOperations();
|
||||
const regexSplit = (await import('./regexSplit.mjs')).default;
|
||||
const parts = regexSplit(text, codeRegex);
|
||||
|
||||
const output = parts.map(async (part) => {
|
||||
if (part.match(codeRegex)) {
|
||||
const code = part.slice(3, -3);
|
||||
let lang = (await modelOperations.runModel(code))[0].languageId;
|
||||
return part.replace(/^```/, `\`\`\`${languages.has(lang) ? lang : 'shell'}`);
|
||||
} else {
|
||||
return part;
|
||||
}
|
||||
});
|
||||
|
||||
return (await Promise.all(output)).join('');
|
||||
} catch (e) {
|
||||
console.log('Error in detectCode function\n', e);
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = detectCode;
|
||||
Loading…
Add table
Add a link
Reference in a new issue