mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: Fixed the chat model setting echo issue (#9521)
### What problem does this PR solve? Feat: Fixed the chat model setting echo issue ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -54,6 +54,8 @@ export function useAgentToolInitialValues() {
|
||||
return pick(initialValues, 'top_n');
|
||||
case Operator.WenCai:
|
||||
return pick(initialValues, 'top_n', 'query_type');
|
||||
case Operator.Code:
|
||||
return {};
|
||||
|
||||
default:
|
||||
return initialValues;
|
||||
|
||||
@ -3,6 +3,10 @@ import { Form } from '@/components/ui/form';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { useFetchDialog, useSetDialog } from '@/hooks/use-chat-request';
|
||||
import { transformBase64ToFile, transformFile2Base64 } from '@/utils/file-util';
|
||||
import {
|
||||
removeUselessFieldsFromValues,
|
||||
setLLMSettingEnabledValues,
|
||||
} from '@/utils/form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { X } from 'lucide-react';
|
||||
import { useEffect } from 'react';
|
||||
@ -26,6 +30,7 @@ export function ChatSettings({ switchSettingVisible }: ChatSettingsProps) {
|
||||
|
||||
const form = useForm<FormSchemaType>({
|
||||
resolver: zodResolver(formSchema),
|
||||
shouldUnregister: true,
|
||||
defaultValues: {
|
||||
name: '',
|
||||
language: 'English',
|
||||
@ -47,14 +52,18 @@ export function ChatSettings({ switchSettingVisible }: ChatSettingsProps) {
|
||||
});
|
||||
|
||||
async function onSubmit(values: FormSchemaType) {
|
||||
const icon = values.icon;
|
||||
const nextValues: Record<string, any> = removeUselessFieldsFromValues(
|
||||
values,
|
||||
'llm_setting.',
|
||||
);
|
||||
const icon = nextValues.icon;
|
||||
const avatar =
|
||||
Array.isArray(icon) && icon.length > 0
|
||||
? await transformFile2Base64(icon[0])
|
||||
: '';
|
||||
setDialog({
|
||||
...data,
|
||||
...values,
|
||||
...nextValues,
|
||||
icon: avatar,
|
||||
dialog_id: id,
|
||||
});
|
||||
@ -65,9 +74,14 @@ export function ChatSettings({ switchSettingVisible }: ChatSettingsProps) {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const llmSettingEnabledValues = setLLMSettingEnabledValues(
|
||||
data.llm_setting,
|
||||
);
|
||||
|
||||
const nextData = {
|
||||
...data,
|
||||
icon: data.icon ? [transformBase64ToFile(data.icon)] : [],
|
||||
...llmSettingEnabledValues,
|
||||
};
|
||||
form.reset(nextData as FormSchemaType);
|
||||
}, [data, form]);
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { LlmSettingSchema } from '@/components/llm-setting-items/next';
|
||||
import {
|
||||
LlmSettingEnabledSchema,
|
||||
LlmSettingFieldSchema,
|
||||
} from '@/components/llm-setting-items/next';
|
||||
import { rerankFormSchema } from '@/components/rerank';
|
||||
import { vectorSimilarityWeightSchema } from '@/components/similarity-slider';
|
||||
import { topnSchema } from '@/components/top-n-item';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { omit } from 'lodash';
|
||||
import { z } from 'zod';
|
||||
|
||||
export function useChatSettingSchema() {
|
||||
@ -39,20 +41,23 @@ export function useChatSettingSchema() {
|
||||
}),
|
||||
prompt_config: promptConfigSchema,
|
||||
...rerankFormSchema,
|
||||
llm_setting: z.object(omit(LlmSettingSchema, 'llm_id')),
|
||||
llm_setting: z.object(LlmSettingFieldSchema),
|
||||
...LlmSettingEnabledSchema,
|
||||
llm_id: z.string().optional(),
|
||||
...vectorSimilarityWeightSchema,
|
||||
...topnSchema,
|
||||
meta_data_filter: z
|
||||
.object({
|
||||
method: z.string().optional(),
|
||||
manual: z.array(
|
||||
z.object({
|
||||
key: z.string(),
|
||||
op: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
),
|
||||
manual: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string(),
|
||||
op: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user