mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
feat: api will disable search if no meilisearch connection
This commit is contained in:
parent
97a6cd801b
commit
94c0fbb525
2 changed files with 25 additions and 4 deletions
|
|
@ -21,10 +21,16 @@ OPENAI_KEY=
|
|||
CHATGPT_TOKEN=
|
||||
BING_TOKEN=
|
||||
|
||||
# User System
|
||||
# Enable Message/Convo Search
|
||||
# Requires installation of self-hosted Meilisearch or Paid Remote Plan
|
||||
# this is taken care of you if you use the docker-compose file.
|
||||
# SEARCH=TRUE
|
||||
SEARCH=
|
||||
MEILI_HOST='http://localhost:7700'
|
||||
MEILI_KEY='MASTER_KEY'
|
||||
|
||||
# User System
|
||||
# global enable/disable the sample user system.
|
||||
# this is not a ready to use user system.
|
||||
# dont't use it, unless you can write your own code.
|
||||
SEARCH=
|
||||
ENABLE_USER_SYSTEM=
|
||||
ENABLE_USER_SYSTEM=
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { MeiliSearch } = require('meilisearch');
|
||||
const { Message } = require('../../models/Message');
|
||||
const { Conversation, getConvosQueried } = require('../../models/Conversation');
|
||||
const { reduceHits } = require('../../lib/utils/reduceHits');
|
||||
|
|
@ -79,7 +80,21 @@ router.get('/test', async function (req, res) {
|
|||
});
|
||||
|
||||
router.get('/enable', async function (req, res) {
|
||||
res.send(!!process.env.SEARCH);
|
||||
let result = false;
|
||||
const client = new MeiliSearch({
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY
|
||||
});
|
||||
|
||||
try {
|
||||
const { status } = await client.health();
|
||||
console.log(`Meilisearch: ${status}`);
|
||||
result = status === 'available' && !!process.env.SEARCH;
|
||||
return res.send(result);
|
||||
} catch(error) {
|
||||
console.error(error);
|
||||
return res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue