diff --git a/api/apps/restful_apis/chat_api.py b/api/apps/restful_apis/chat_api.py index 74f5114fb3..b922d68c9b 100644 --- a/api/apps/restful_apis/chat_api.py +++ b/api/apps/restful_apis/chat_api.py @@ -1161,6 +1161,9 @@ async def session_completion(chat_id_in_arg=""): return error request_messages, request_msg = normalized pass_all_history_messages = _get_bool_request_flag(req, "pass_all_history_messages", "pass_all_history", default=False) + store_history_messages = _get_bool_request_flag(req, "store_history_messages", "store_history", default=True) + if not store_history_messages and not pass_all_history_messages: + return get_data_error_result(message="`pass_all_history_messages` must be true when `store_history_messages` is false.") msg = request_msg message_id = request_msg[-1].get("id") chat_id = req.pop("chat_id", "") or "" @@ -1299,7 +1302,7 @@ async def session_completion(chat_id_in_arg=""): ans = _format_answer(ans) payload = _sanitize_json_floats({"code": 0, "message": "", "data": ans}) yield "data:" + json.dumps(payload, ensure_ascii=False) + "\n\n" - if conv is not None: + if conv is not None and store_history_messages: await thread_pool_exec(ConversationService.update_by_id, conv.id, conv.to_dict()) except Exception as ex: logging.exception(ex) @@ -1317,7 +1320,7 @@ async def session_completion(chat_id_in_arg=""): answer = None async for ans in rag_agent(dia, msg, False, session_id=session_id, **req): answer = _format_answer(ans) - if conv is not None: + if conv is not None and store_history_messages: await thread_pool_exec(ConversationService.update_by_id, conv.id, conv.to_dict()) break return get_json_result(data=_sanitize_json_floats(answer)) diff --git a/web/src/components/message-input/next.tsx b/web/src/components/message-input/next.tsx index 3c37e6b72f..2ae5e873ad 100644 --- a/web/src/components/message-input/next.tsx +++ b/web/src/components/message-input/next.tsx @@ -26,6 +26,7 @@ import { AudioButton } from '../ui/audio-button'; export type NextMessageInputOnPressEnterParameter = { enableThinking?: string; enableInternet?: boolean; + store_history_messages?: boolean; }; interface NextMessageInputProps { diff --git a/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx index 083897008f..fa20ab5739 100644 --- a/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx +++ b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx @@ -139,7 +139,7 @@ const ChatCard = forwardRef(function ChatCard( // resend with the card's model settings (llm_id, temperature, ...). const sendCardMessage = useCallback( ({ message, messages }: { message: IMessage; messages?: IMessage[] }) => - sendMessage({ message, messages, ...form.getValues() }), + sendMessage({ message, messages, ...form.getValues(), store_history_messages: false }), [sendMessage, form], ); @@ -182,7 +182,7 @@ const ChatCard = forwardRef(function ChatCard( useImperativeHandle( ref, (): HandlePressEnterType => (params) => - handlePressEnter({ ...params, ...form.getValues() }), + handlePressEnter({ ...params, ...form.getValues(), store_history_messages: false }), ); useEffect(() => {