Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: Click "Apply" to sync the parameters from the multi-model comparison page to the chat page. (#21564)

balibabu1dd7ead7b5ca
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 7b0dea0f20..ea47099a3e 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -1075,7 +1075,8 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s
messagePlaceholder: 'Type your message here...',
exit: 'Exit',
multipleModels: 'Multiple models',
- applyModelConfigs: 'Apply model configs',
+ applyModelConfigs:
+ 'Use this model and its settings in single-model Chat.',
conversations: 'Conversations',
chatApps: 'Chat apps',
newConversation: 'New conversation',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 9f79b7f2a5..a916fa9eb3 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -972,7 +972,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
messagePlaceholder: '请输入消息...',
exit: '退出',
multipleModels: '多模型',
- applyModelConfigs: '应用模型配置',
+ applyModelConfigs: '在单模型对话中使用此模型及其设置',
conversations: '会话',
chatApps: '聊天',
createChat: '创建聊天',
diff --git a/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.test.tsx b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.test.tsx
new file mode 100644
index 0000000000..345ff430a9
--- /dev/null
+++ b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.test.tsx
@@ -0,0 +1,222 @@
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { TooltipProvider } from '@/components/ui/tooltip';
+import { useCallback, useEffect } from 'react';
+import { useFormContext } from 'react-hook-form';
+import { MultipleChatBox } from './next-multiple-chat-box';
+
+const mockUpdateChat = jest.fn();
+const mockHandlePressEnter = jest.fn();
+const mockFindLlmByUuid = jest.fn();
+let mockModelFormValues: Record<string, unknown> = {};
+
+function MockLargeModelFormFieldWithoutFilter() {
+ const form = useFormContext();
+
+ useEffect(() => {
+ Object.entries(mockModelFormValues).forEach(([name, value]) => {
+ form.setValue(name, value);
+ });
+ }, [form]);
+
+ return null;
+}
+
+type MockNextMessageInputProps = {
+ onPressEnter(params: {
+ enableInternet: boolean;
+ enableThinking: boolean;
+ }): void;
+};
+
+function MockNextMessageInput({ onPressEnter }: MockNextMessageInputProps) {
+ const handleClick = useCallback(() => {
+ onPressEnter({ enableInternet: false, enableThinking: false });
+ }, [onPressEnter]);
+
+ return <button data-testid="mock-send-message" onClick={handleClick} />;
+}
+
+jest.mock('@/components/large-model-form-field', () => ({
+ LargeModelFormFieldWithoutFilter: () =>
+ MockLargeModelFormFieldWithoutFilter(),
+}));
+jest.mock('@/components/message-input/next', () => ({
+ NextMessageInput: (props: MockNextMessageInputProps) =>
+ MockNextMessageInput(props),
+}));
+jest.mock('@/components/message-item', () => () => null);
+jest.mock('@/components/pdf-drawer', () => () => null);
+jest.mock('@/components/pdf-drawer/hooks', () => ({
+ useClickDrawer: () => ({
+ visible: false,
+ hideModal: jest.fn(),
+ documentId: '',
+ selectedChunk: undefined,
+ clickDocumentButton: jest.fn(),
+ }),
+}));
+jest.mock('@/hooks/logic-hooks', () => ({
+ useHandleMessageInputChange: () => ({
+ handleInputChange: jest.fn(),
+ value: 'Question',
+ setValue: jest.fn(),
+ }),
+ useScrollToBottom: () => ({ scrollRef: { current: null } }),
+}));
+jest.mock('@/hooks/use-chat-request', () => ({
+ useFetchChat: () => ({
+ data: {
+ icon: '',
+ llm_id: 'previous-model',
+ llm_setting: {
+ frequency_penalty: 0.8,
+ max_tokens: 8192,
+ },
+ tenant_id: 'tenant-1',
+ },
+ }),
+ useGetChatSearchParams: () => ({ conversationId: 'conversation-1' }),
+ useUpdateChat: () => ({ updateChat: mockUpdateChat }),
+}));
+jest.mock('@/hooks/use-llm-request', () => ({
+ useFindLlmByUuid: () => mockFindLlmByUuid,
+}));
+jest.mock('@/hooks/use-user-setting-request', () => ({
+ useFetchUserInfo: () => ({ data: { nickname: '', avatar: '' } }),
+}));
+jest.mock('../../hooks/use-button-disabled', () => ({
+ useGetSendButtonDisabled: () => false,
+ useSendButtonDisabled: () => false,
+}));
+jest.mock('../../hooks/use-create-conversation', () => ({
+ useCreateConversationBeforeUploadDocument: () => ({
+ createConversationBeforeUploadDocument: jest.fn(),
+ }),
+}));
+jest.mock('../../hooks/use-send-single-message', () => ({
+ useSendSingleMessage: () => ({
+ derivedMessages: [],
+ handlePressEnter: mockHandlePressEnter,
+ sendLoading: false,
+ }),
+}));
+jest.mock('../../hooks/use-upload-file', () => ({
+ useUploadFile: () => ({
+ handleUploadFile: jest.fn(),
+ isUploading: false,
+ files: [],
+ clearFiles: jest.fn(),
+ removeFile: jest.fn(),
+ }),
+}));
+jest.mock('../../hooks/use-message-references', () => ({
+ useMessageReferences: () => new Map(),
+}));
+jest.mock('../../utils', () => ({ EmptyReference: {} }));
+jest.mock('../use-show-internet', () => ({
+ useShowInternet: () => false,
+}));
+jest.mock('react-router', () => ({
+ useParams: () => ({ id: 'dialog-1' }),
+}));
+
+function renderMultipleChatBox() {
+ return render(
+ <TooltipProvider>
+ <MultipleChatBox
+ controller={new AbortController()}
+ chatBoxIds={['card-1']}
+ removeChatBox={jest.fn()}
+ addChatBox={jest.fn()}
+ stopOutputMessage={jest.fn()}
+ conversation={{} as never}
+ />
+ </TooltipProvider>,
+ );
+}
+
+describe('MultipleChatBox model settings', () => {
+ beforeEach(() => {
+ mockUpdateChat.mockReset();
+ mockHandlePressEnter.mockReset();
+ mockFindLlmByUuid.mockReset();
+ mockFindLlmByUuid.mockReturnValue({ model_type: 'chat' });
+ mockModelFormValues = {
+ llm_id: 'model-1',
+ parameter: 'Custom',
+ temperature: 0.2,
+ top_p: 0.75,
+ presence_penalty: 0.5,
+ frequency_penalty: 0.5,
+ max_tokens: 4096,
+ temperatureEnabled: true,
+ topPEnabled: true,
+ presencePenaltyEnabled: true,
+ frequencyPenaltyEnabled: false,
+ maxTokensEnabled: false,
+ thinking: 'default',
+ };
+ });
+
+ it('replaces the saved settings without disabled parameters or UI flags', async () => {
+ renderMultipleChatBox();
+
+ const applyButton = screen.getByTestId('chat-detail-multimodel-card-apply');
+ await waitFor(() => expect(applyButton).toBeEnabled());
+ fireEvent.click(applyButton);
+
+ expect(mockUpdateChat).toHaveBeenCalledWith({
+ chatId: 'dialog-1',
+ params: {
+ llm_id: 'model-1',
+ tenant_llm_id: 'model-1',
+ llm_setting: {
+ temperature: 0.2,
+ top_p: 0.75,
+ presence_penalty: 0.5,
+ thinking: 'default',
+ model_type: 'chat',
+ },
+ },
+ });
+ });
+
+ it('keeps an enabled preset frequency penalty but omits disabled max tokens', async () => {
+ mockModelFormValues.parameter = 'Precise';
+ mockModelFormValues.frequencyPenaltyEnabled = true;
+ renderMultipleChatBox();
+
+ const applyButton = screen.getByTestId('chat-detail-multimodel-card-apply');
+ await waitFor(() => expect(applyButton).toBeEnabled());
+ fireEvent.click(applyButton);
+
+ const request = mockUpdateChat.mock.calls[0][0];
+ expect(request.params.llm_setting).toMatchObject({
+ frequency_penalty: 0.5,
+ });
+ expect(request.params.llm_setting).not.toHaveProperty('max_tokens');
+ expect(request.params.llm_setting).not.toHaveProperty(
+ 'frequencyPenaltyEnabled',
+ );
+ expect(request.params.llm_setting).not.toHaveProperty('maxTokensEnabled');
+ expect(request.params.llm_setting).not.toHaveProperty('parameter');
+ });
+
+ it('omits disabled parameters and UI flags from multi-model messages', () => {
+ renderMultipleChatBox();
+
+ fireEvent.click(screen.getByTestId('mock-send-message'));
+
+ expect(mockHandlePressEnter).toHaveBeenCalledWith({
+ enableInternet: false,
+ enableThinking: false,
+ llm_id: 'model-1',
+ temperature: 0.2,
+ top_p: 0.75,
+ presence_penalty: 0.5,
+ thinking: 'default',
+ storeHistoryMessages: false,
+ omitSessionId: true,
+ });
+ });
+});
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 0d9ac85b51..4338dbae32 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
@@ -23,12 +23,13 @@ import {
import {
useFetchChat,
useGetChatSearchParams,
- usePatchChat,
+ useUpdateChat,
} from '@/hooks/use-chat-request';
import { useFindLlmByUuid } from '@/hooks/use-llm-request';
import { useFetchUserInfo } from '@/hooks/use-user-setting-request';
import { IClientConversation } from '@/interfaces/database/chat';
import { buildMessageUuidWithRole } from '@/utils/chat';
+import { removeUselessFieldsFromValues } from '@/utils/form';
import { zodResolver } from '@hookform/resolvers/zod';
import { t } from 'i18next';
import { isEmpty, omit, trim } from 'lodash';
@@ -104,7 +105,7 @@ const ChatCard = forwardRef(function ChatCard(
ref,
) {
const { id: dialogId } = useParams();
- const { patchChat } = usePatchChat();
+ const { updateChat } = useUpdateChat();
const { derivedMessages, handlePressEnter, sendLoading } =
useSendSingleMessage({
@@ -140,7 +141,7 @@ const ChatCard = forwardRef(function ChatCard(
const findLlmByUuid = useFindLlmByUuid();
// Each card must keep its own independently selected model after the initial
- // sync. Without this guard, clicking "Apply" in one card patches the dialog
+ // sync. Without this guard, clicking "Apply" in one card updates the dialog
// (which invalidates [FetchChat] and refetches currentDialog), and the
// changed currentDialog.llm_id would then overwrite every other card's
// llm_id via this effect. Sync only when dialogId changes (initial load or
@@ -162,31 +163,30 @@ const ChatCard = forwardRef(function ChatCard(
const handleApplyConfig = useCallback(() => {
const values = form.getValues();
const llmId = values.llm_id;
- patchChat({
+ const llmSetting = removeUselessFieldsFromValues(values, '');
+ // Replace the full settings object so disabled fields are removed instead
+ // of surviving a PATCH merge with the previously saved values.
+ updateChat({
chatId: dialogId!,
params: {
- ...currentDialog,
llm_id: llmId,
tenant_llm_id: llmId,
llm_setting: {
- ...omit(values, 'llm_id'),
+ ...omit(llmSetting, 'llm_id'),
model_type: findLlmByUuid(llmId)?.model_type || 'chat',
},
},
});
- }, [currentDialog, dialogId, form, patchChat, findLlmByUuid]);
+ }, [dialogId, form, updateChat, findLlmByUuid]);
- useImperativeHandle(
- ref,
- (): HandlePressEnterType => (params) => {
- return handlePressEnter({
- ...params,
- ...form.getValues(),
- storeHistoryMessages: false,
- omitSessionId: true,
- });
- },
- );
+ useImperativeHandle(ref, (): HandlePressEnterType => (params) => {
+ return handlePressEnter({
+ ...params,
+ ...removeUselessFieldsFromValues(form.getValues(), ''),
+ storeHistoryMessages: false,
+ omitSessionId: true,
+ });
+ });
useEffect(() => {
setLoading(id, sendLoading);