mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-01 13:33:48 +08:00
Fix: multiple model chat pass-in session_id, and do not save session. (#17581)
This commit is contained in:
@@ -182,7 +182,7 @@ def _build_default_completion_dialog():
|
||||
)
|
||||
|
||||
|
||||
async def _create_session_for_completion(chat_id, dialog, user_id):
|
||||
async def _create_session_for_completion(chat_id, dialog, user_id, save_session=True):
|
||||
conv = {
|
||||
"id": get_uuid(),
|
||||
"dialog_id": chat_id,
|
||||
@@ -191,6 +191,9 @@ async def _create_session_for_completion(chat_id, dialog, user_id):
|
||||
"user_id": user_id,
|
||||
"reference": [],
|
||||
}
|
||||
if not save_session:
|
||||
conv["id"] = None
|
||||
return SimpleNamespace(**conv)
|
||||
await thread_pool_exec(ConversationService.save, **conv)
|
||||
ok, conv_obj = await thread_pool_exec(ConversationService.get_by_id, conv["id"])
|
||||
if not ok:
|
||||
@@ -1224,7 +1227,7 @@ async def session_completion(chat_id_in_arg=""):
|
||||
if conv.dialog_id != chat_id:
|
||||
return get_data_error_result(message="Session does not belong to this chat!")
|
||||
else:
|
||||
conv = await _create_session_for_completion(chat_id, dia, current_user.id)
|
||||
conv = await _create_session_for_completion(chat_id, dia, current_user.id, save_session=store_history_messages)
|
||||
session_id = conv.id
|
||||
|
||||
if pass_all_history_messages:
|
||||
|
||||
@@ -26,7 +26,8 @@ import { AudioButton } from '../ui/audio-button';
|
||||
export type NextMessageInputOnPressEnterParameter = {
|
||||
enableThinking?: string;
|
||||
enableInternet?: boolean;
|
||||
store_history_messages?: boolean;
|
||||
storeHistoryMessages?: boolean;
|
||||
omitSessionId?: boolean;
|
||||
};
|
||||
|
||||
interface NextMessageInputProps {
|
||||
|
||||
@@ -50,7 +50,6 @@ import {
|
||||
useGetSendButtonDisabled,
|
||||
useSendButtonDisabled,
|
||||
} from '../../hooks/use-button-disabled';
|
||||
import { useCreateConversationBeforeSendMessage } from '../../hooks/use-chat-url';
|
||||
import { useCreateConversationBeforeUploadDocument } from '../../hooks/use-create-conversation';
|
||||
import {
|
||||
HandlePressEnterType,
|
||||
@@ -139,7 +138,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(), store_history_messages: false }),
|
||||
sendMessage({ message, messages, ...form.getValues(), storeHistoryMessages: false, omitSessionId: true }),
|
||||
[sendMessage, form],
|
||||
);
|
||||
|
||||
@@ -182,7 +181,7 @@ const ChatCard = forwardRef(function ChatCard(
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
(): HandlePressEnterType => (params) =>
|
||||
handlePressEnter({ ...params, ...form.getValues(), store_history_messages: false }),
|
||||
handlePressEnter({ ...params, ...form.getValues(), storeHistoryMessages: false, omitSessionId: true }),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -279,6 +278,7 @@ const ChatCard = forwardRef(function ChatCard(
|
||||
regenerateMessage={regenerateMessage}
|
||||
sendLoading={sendLoading}
|
||||
clickDocumentButton={clickDocumentButton}
|
||||
showLikeButton={false}
|
||||
></MessageItem>
|
||||
);
|
||||
})}
|
||||
@@ -298,9 +298,6 @@ export function MultipleChatBox({
|
||||
stopOutputMessage,
|
||||
conversation,
|
||||
}: MultipleChatBoxProps) {
|
||||
const { createConversationBeforeSendMessage } =
|
||||
useCreateConversationBeforeSendMessage();
|
||||
|
||||
const { createConversationBeforeUploadDocument } =
|
||||
useCreateConversationBeforeUploadDocument();
|
||||
const { conversationId } = useGetChatSearchParams();
|
||||
@@ -342,21 +339,14 @@ export function MultipleChatBox({
|
||||
}: NextMessageInputOnPressEnterParameter) => {
|
||||
if (trim(value) === '') return;
|
||||
|
||||
const data = await createConversationBeforeSendMessage(value);
|
||||
|
||||
if (data === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.values(boxesRef.current).forEach((box) => {
|
||||
box?.({
|
||||
enableInternet,
|
||||
enableThinking,
|
||||
...data,
|
||||
});
|
||||
});
|
||||
},
|
||||
[createConversationBeforeSendMessage, value],
|
||||
[value],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -60,6 +60,8 @@ export function useSendSingleMessage({
|
||||
messages,
|
||||
enableInternet,
|
||||
enableThinking,
|
||||
storeHistoryMessages,
|
||||
omitSessionId,
|
||||
...params
|
||||
}: {
|
||||
message: IMessage;
|
||||
@@ -71,7 +73,7 @@ export function useSendSingleMessage({
|
||||
api.completionUrl,
|
||||
{
|
||||
chat_id: chatId,
|
||||
session_id: sessionId,
|
||||
...(omitSessionId ? {} : { session_id: sessionId }),
|
||||
messages: [
|
||||
...(Array.isArray(messages) && messages?.length > 0
|
||||
? messages
|
||||
@@ -81,6 +83,9 @@ export function useSendSingleMessage({
|
||||
reasoning: Number(enableThinking),
|
||||
internet: enableInternet,
|
||||
...params,
|
||||
...(storeHistoryMessages === undefined
|
||||
? {}
|
||||
: { store_history_messages: storeHistoryMessages }),
|
||||
pass_all_history_messages: true,
|
||||
},
|
||||
controller,
|
||||
@@ -112,7 +117,7 @@ export function useSendSingleMessage({
|
||||
targetConversationId,
|
||||
...params
|
||||
}: NextMessageInputOnPressEnterParameter &
|
||||
CreateConversationBeforeSendMessageReturnType) => {
|
||||
Partial<NonNullable<CreateConversationBeforeSendMessageReturnType>>) => {
|
||||
if (trim(value) === '' || !done) return;
|
||||
const id = uuid();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user