mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-23 15:06:50 +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:
@ -28,20 +28,32 @@ interface LlmSettingFieldItemsProps {
|
||||
options?: any[];
|
||||
}
|
||||
|
||||
export const LlmSettingSchema = {
|
||||
export const LLMIdFormField = {
|
||||
llm_id: z.string(),
|
||||
temperature: z.coerce.number().optional(),
|
||||
top_p: z.number().optional(),
|
||||
presence_penalty: z.coerce.number().optional(),
|
||||
frequency_penalty: z.coerce.number().optional(),
|
||||
};
|
||||
|
||||
export const LlmSettingEnabledSchema = {
|
||||
temperatureEnabled: z.boolean().optional(),
|
||||
topPEnabled: z.boolean().optional(),
|
||||
presencePenaltyEnabled: z.boolean().optional(),
|
||||
frequencyPenaltyEnabled: z.boolean().optional(),
|
||||
maxTokensEnabled: z.boolean().optional(),
|
||||
};
|
||||
|
||||
export const LlmSettingFieldSchema = {
|
||||
temperature: z.coerce.number().optional(),
|
||||
top_p: z.number().optional(),
|
||||
presence_penalty: z.coerce.number().optional(),
|
||||
frequency_penalty: z.coerce.number().optional(),
|
||||
max_tokens: z.number().optional(),
|
||||
};
|
||||
|
||||
export const LlmSettingSchema = {
|
||||
...LLMIdFormField,
|
||||
...LlmSettingFieldSchema,
|
||||
...LlmSettingEnabledSchema,
|
||||
};
|
||||
|
||||
export function LlmSettingFieldItems({
|
||||
prefix,
|
||||
options,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { settledModelVariableMap } from '@/constants/knowledge';
|
||||
import { AgentFormContext } from '@/pages/agent/context';
|
||||
import useGraphStore from '@/pages/agent/store';
|
||||
import { setChatVariableEnabledFieldValuePage } from '@/utils/chat';
|
||||
import { useCallback, useContext } from 'react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
|
||||
@ -11,6 +12,20 @@ export function useHandleFreedomChange(
|
||||
const node = useContext(AgentFormContext);
|
||||
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
|
||||
|
||||
const setLLMParameters = useCallback(
|
||||
(values: Record<string, any>, withPrefix: boolean) => {
|
||||
for (const key in values) {
|
||||
if (Object.prototype.hasOwnProperty.call(values, key)) {
|
||||
const realKey = getFieldWithPrefix(key);
|
||||
const element = values[key as keyof typeof values];
|
||||
|
||||
form.setValue(withPrefix ? realKey : key, element);
|
||||
}
|
||||
}
|
||||
},
|
||||
[form, getFieldWithPrefix],
|
||||
);
|
||||
|
||||
const handleChange = useCallback(
|
||||
(parameter: string) => {
|
||||
const currentValues = { ...form.getValues() };
|
||||
@ -25,16 +40,12 @@ export function useHandleFreedomChange(
|
||||
updateNodeForm(node?.id, nextValues);
|
||||
}
|
||||
|
||||
for (const key in values) {
|
||||
if (Object.prototype.hasOwnProperty.call(values, key)) {
|
||||
const realKey = getFieldWithPrefix(key);
|
||||
const element = values[key as keyof typeof values];
|
||||
const variableCheckBoxFieldMap = setChatVariableEnabledFieldValuePage();
|
||||
|
||||
form.setValue(realKey, element);
|
||||
}
|
||||
}
|
||||
setLLMParameters(values, true);
|
||||
setLLMParameters(variableCheckBoxFieldMap, false);
|
||||
},
|
||||
[form, getFieldWithPrefix, node?.id, updateNodeForm],
|
||||
[form, node?.id, setLLMParameters, updateNodeForm],
|
||||
);
|
||||
|
||||
return handleChange;
|
||||
|
||||
Reference in New Issue
Block a user