mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-26 20:34:10 +01:00
🔄 refactor: improved RAG animations/messages (#2616)
* fix: warning slow process rag message * refactor: improved useProgress hook for Files
This commit is contained in:
parent
b77bd19092
commit
2aec4a6250
4 changed files with 52 additions and 11 deletions
|
|
@ -1,9 +1,36 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
|
||||
export default function useProgress(initialProgress = 0.01, increment = 0.007) {
|
||||
const [incrementValue] = useState(increment);
|
||||
export default function useProgress(initialProgress = 0.01, increment = 0.007, fileSize?: number) {
|
||||
const calculateIncrement = (size?: number) => {
|
||||
const baseRate = 0.05;
|
||||
const minRate = 0.002;
|
||||
const sizeMB = size ? size / (1024 * 1024) : 0;
|
||||
|
||||
if (!size) {
|
||||
return increment;
|
||||
}
|
||||
|
||||
if (sizeMB <= 1) {
|
||||
return baseRate * 2;
|
||||
} else {
|
||||
return Math.max(baseRate / Math.sqrt(sizeMB), minRate);
|
||||
}
|
||||
};
|
||||
|
||||
const incrementValue = calculateIncrement(fileSize);
|
||||
const [progress, setProgress] = useState(initialProgress);
|
||||
|
||||
const getDynamicIncrement = (currentProgress: number) => {
|
||||
if (!fileSize) {
|
||||
return incrementValue;
|
||||
}
|
||||
if (currentProgress < 0.7) {
|
||||
return incrementValue;
|
||||
} else {
|
||||
return Math.max(0.0005, incrementValue * (1 - currentProgress));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
let timer: ReturnType<typeof setInterval>;
|
||||
|
|
@ -21,7 +48,8 @@ export default function useProgress(initialProgress = 0.01, increment = 0.007) {
|
|||
clearInterval(timer);
|
||||
return 1;
|
||||
}
|
||||
return Math.min(prevProgress + incrementValue, 0.95);
|
||||
const currentIncrement = getDynamicIncrement(prevProgress);
|
||||
return Math.min(prevProgress + currentIncrement, 0.95);
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
|
|
@ -30,7 +58,7 @@ export default function useProgress(initialProgress = 0.01, increment = 0.007) {
|
|||
clearInterval(timer);
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}, [progress, initialProgress, incrementValue]);
|
||||
}, [progress, initialProgress, incrementValue, fileSize]);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue