mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
refactor: title generation logic
- Changed the title generation endpoint from POST to GET, allowing for more efficient retrieval of titles based on conversation ID. - Implemented exponential backoff for title fetching retries, improving responsiveness and reducing server load. - Introduced a queuing mechanism for title generation, ensuring titles are generated only after job completion. - Updated relevant components and hooks to utilize the new title generation logic, enhancing user experience and application performance.
This commit is contained in:
parent
5a278f4f4f
commit
1ea35373ae
9 changed files with 118 additions and 97 deletions
|
|
@ -67,16 +67,17 @@ router.get('/:conversationId', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.post('/gen_title', async (req, res) => {
|
||||
const { conversationId } = req.body;
|
||||
router.get('/gen_title/:conversationId', async (req, res) => {
|
||||
const { conversationId } = req.params;
|
||||
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
||||
const key = `${req.user.id}-${conversationId}`;
|
||||
let title = await titleCache.get(key);
|
||||
|
||||
if (!title) {
|
||||
// Retry every 1s for up to 20s
|
||||
for (let i = 0; i < 20; i++) {
|
||||
await sleep(1000);
|
||||
// Exponential backoff: 500ms, 1s, 2s, 4s, 8s (total ~15.5s max wait)
|
||||
const delays = [500, 1000, 2000, 4000, 8000];
|
||||
for (const delay of delays) {
|
||||
await sleep(delay);
|
||||
title = await titleCache.get(key);
|
||||
if (title) {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue