fix: Token estimate count cannot be updated on the UI when typing quickly.
This commit is contained in:
parent
012e79a7e2
commit
d62ff69351
@ -94,11 +94,24 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
||||
|
||||
const showKnowledgeIcon = useSidebarIconShow('knowledge')
|
||||
|
||||
const estimateTextTokens = useCallback(debounce(estimateTxtTokens, 1000), [])
|
||||
const inputTokenCount = useMemo(
|
||||
() => (showInputEstimatedTokens ? estimateTextTokens(text) || 0 : 0),
|
||||
[estimateTextTokens, showInputEstimatedTokens, text]
|
||||
const [tokenCount, setTokenCount] = useState(0)
|
||||
|
||||
const debouncedEstimate = useCallback(
|
||||
debounce((newText) => {
|
||||
if (showInputEstimatedTokens) {
|
||||
const count = estimateTxtTokens(newText) || 0
|
||||
setTokenCount(count)
|
||||
}
|
||||
}, 500),
|
||||
[showInputEstimatedTokens]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
debouncedEstimate(text)
|
||||
}, [text, debouncedEstimate])
|
||||
|
||||
const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0
|
||||
|
||||
const newTopicShortcut = useShortcutDisplay('new_topic')
|
||||
const newContextShortcut = useShortcutDisplay('toggle_new_context')
|
||||
const cleanTopicShortcut = useShortcutDisplay('clear_topic')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user