🔧 fix: Catch deleteVectors Errors & Update RAG API docs (#2299)

* fix(deleteVectors): handle errors gracefully

* chore: update docs based on new alternate env vars prefixed with RAG to avoid conflicts with LibreChat keys
This commit is contained in:
Danny Avila 2024-04-03 14:24:46 -04:00 committed by GitHub
parent e3c236ba3b
commit e418edd3dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 22 deletions

View file

@ -18,9 +18,12 @@ const { logger } = require('~/config');
* file path is invalid or if there is an error in deletion.
*/
const deleteVectors = async (req, file) => {
if (file.embedded && process.env.RAG_API_URL) {
if (!file.embedded || !process.env.RAG_API_URL) {
return;
}
try {
const jwtToken = req.headers.authorization.split(' ')[1];
axios.delete(`${process.env.RAG_API_URL}/documents`, {
return await axios.delete(`${process.env.RAG_API_URL}/documents`, {
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
@ -28,6 +31,9 @@ const deleteVectors = async (req, file) => {
},
data: [file.file_id],
});
} catch (error) {
logger.error('Error deleting vectors', error);
throw new Error(error.message || 'An error occurred during file deletion.');
}
};