mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-15 23:18:09 +01:00
🔃 fix: Draft Clearing, Claude Titles, Remove Default Vision Max Tokens (#6501)
* refactor: remove legacy max_tokens setting for vision models in OpenAIClient (intended for gpt-4-preview) * refactor: streamline capability checks in loadAgentTools function, still allow actions if tools are disabled * fix: enhance error handling for token limits in AnthropicClient and update error message in translations * feat: append timestamp to cloned agent names for better identification * chore: update @librechat/agents dependency to version 2.3.94 * refactor: remove clearDraft helper from useSubmitMessage and centralize draft clearing logic to SSE handling, helps prevent user message loss if logout occurs * refactor: increase debounce time for clearDraft function to improve auto-save performance
This commit is contained in:
parent
20f353630e
commit
4b85fe9206
11 changed files with 634 additions and 590 deletions
|
|
@ -93,7 +93,7 @@ const ChatForm = ({ index = 0 }) => {
|
|||
} = useAddedChatContext();
|
||||
const showStopAdded = useRecoilValue(store.showStopButtonByIndex(addedIndex));
|
||||
|
||||
const { clearDraft } = useAutoSave({
|
||||
useAutoSave({
|
||||
conversationId: useMemo(() => conversation?.conversationId, [conversation]),
|
||||
textAreaRef,
|
||||
files,
|
||||
|
|
@ -101,7 +101,7 @@ const ChatForm = ({ index = 0 }) => {
|
|||
});
|
||||
|
||||
const assistantMap = useAssistantsMapContext();
|
||||
const { submitMessage, submitPrompt } = useSubmitMessage({ clearDraft });
|
||||
const { submitMessage, submitPrompt } = useSubmitMessage();
|
||||
|
||||
const { endpoint: _endpoint, endpointType } = conversation ?? { endpoint: null };
|
||||
const endpoint = endpointType ?? _endpoint;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import { useChatFormContext } from '~/Providers';
|
|||
import { useGetFiles } from '~/data-provider';
|
||||
import store from '~/store';
|
||||
|
||||
const clearDraft = debounce((id?: string | null) => {
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${id ?? ''}`);
|
||||
}, 2500);
|
||||
|
||||
export const useAutoSave = ({
|
||||
conversationId,
|
||||
textAreaRef,
|
||||
|
|
@ -103,7 +107,7 @@ export const useAutoSave = ({
|
|||
}
|
||||
// Save the draft of the current conversation before switching
|
||||
if (textAreaRef.current.value === '') {
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${id}`);
|
||||
clearDraft(id);
|
||||
} else {
|
||||
localStorage.setItem(
|
||||
`${LocalStorageKeys.TEXT_DRAFT}${id}`,
|
||||
|
|
@ -208,13 +212,4 @@ export const useAutoSave = ({
|
|||
);
|
||||
}
|
||||
}, [files, conversationId, saveDrafts, currentConversationId, fileIds]);
|
||||
|
||||
const clearDraft = useCallback(() => {
|
||||
if (conversationId != null && conversationId) {
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`);
|
||||
localStorage.removeItem(`${LocalStorageKeys.FILES_DRAFT}${conversationId}`);
|
||||
}
|
||||
}, [conversationId]);
|
||||
|
||||
return { clearDraft };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const appendIndex = (index: number, value?: string) => {
|
|||
return `${value}${Constants.COMMON_DIVIDER}${index}`;
|
||||
};
|
||||
|
||||
export default function useSubmitMessage(helpers?: { clearDraft?: () => void }) {
|
||||
export default function useSubmitMessage() {
|
||||
const { user } = useAuthContext();
|
||||
const methods = useChatFormContext();
|
||||
const { ask, index, getMessages, setMessages, latestMessage } = useChatContext();
|
||||
|
|
@ -66,12 +66,10 @@ export default function useSubmitMessage(helpers?: { clearDraft?: () => void })
|
|||
);
|
||||
}
|
||||
methods.reset();
|
||||
helpers?.clearDraft && helpers.clearDraft();
|
||||
},
|
||||
[
|
||||
ask,
|
||||
methods,
|
||||
helpers,
|
||||
addedIndex,
|
||||
addedConvo,
|
||||
setMessages,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import { SSE } from 'sse.js';
|
|||
import { useSetRecoilState } from 'recoil';
|
||||
import {
|
||||
request,
|
||||
Constants,
|
||||
/* @ts-ignore */
|
||||
createPayload,
|
||||
isAgentsEndpoint,
|
||||
LocalStorageKeys,
|
||||
removeNullishValues,
|
||||
isAssistantsEndpoint,
|
||||
} from 'librechat-data-provider';
|
||||
|
|
@ -18,6 +20,16 @@ import { useAuthContext } from '~/hooks/AuthContext';
|
|||
import useEventHandlers from './useEventHandlers';
|
||||
import store from '~/store';
|
||||
|
||||
const clearDraft = (conversationId?: string | null) => {
|
||||
if (conversationId) {
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`);
|
||||
localStorage.removeItem(`${LocalStorageKeys.FILES_DRAFT}${conversationId}`);
|
||||
} else {
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${Constants.NEW_CONVO}`);
|
||||
localStorage.removeItem(`${LocalStorageKeys.FILES_DRAFT}${Constants.NEW_CONVO}`);
|
||||
}
|
||||
};
|
||||
|
||||
type ChatHelpers = Pick<
|
||||
EventHandlerParams,
|
||||
| 'setMessages'
|
||||
|
|
@ -112,6 +124,7 @@ export default function useSSE(
|
|||
const data = JSON.parse(e.data);
|
||||
|
||||
if (data.final != null) {
|
||||
clearDraft(submission.conversationId);
|
||||
const { plugins } = data;
|
||||
finalHandler(data, { ...submission, plugins } as EventSubmission);
|
||||
(startupConfig?.balance?.enabled ?? false) && balanceQuery.refetch();
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@
|
|||
"com_error_files_upload": "An error occurred while uploading the file.",
|
||||
"com_error_files_upload_canceled": "The file upload request was canceled. Note: the file upload may still be processing and will need to be manually deleted.",
|
||||
"com_error_files_validation": "An error occurred while validating the file.",
|
||||
"com_error_input_length": "The latest message token count is too long, exceeding the token limit ({{0}} respectively). Please shorten your message, adjust the max context size from the conversation parameters, or fork the conversation to continue.",
|
||||
"com_error_input_length": "The latest message token count is too long, exceeding the token limit, or your token limit parameters are misconfigured, adversely affecting the context window. More info: {{0}}. Please shorten your message, adjust the max context size from the conversation parameters, or fork the conversation to continue.",
|
||||
"com_error_invalid_user_key": "Invalid key provided. Please provide a valid key and try again.",
|
||||
"com_error_moderation": "It appears that the content submitted has been flagged by our moderation system for not aligning with our community guidelines. We're unable to proceed with this specific topic. If you have any other questions or topics you'd like to explore, please edit your message, or create a new conversation.",
|
||||
"com_error_no_base_url": "No base URL found. Please provide one and try again.",
|
||||
|
|
@ -848,4 +848,4 @@
|
|||
"com_ui_zoom": "Zoom",
|
||||
"com_user_message": "You",
|
||||
"com_warning_resubmit_unsupported": "Resubmitting the AI message is not supported for this endpoint."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue