balibabu
commited on
Commit
·
be5bfb7
1
Parent(s):
22390c0
fix: fixed the issue that ModelSetting could not be saved #614 (#617)
Browse files### What problem does this PR solve?
fix: fixed the issue that ModelSetting could not be saved #614
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
web/src/interfaces/database/chat.ts
CHANGED
|
@@ -21,11 +21,11 @@ export interface LlmSetting {
|
|
| 21 |
}
|
| 22 |
|
| 23 |
export interface Variable {
|
| 24 |
-
frequency_penalty
|
| 25 |
-
max_tokens
|
| 26 |
-
presence_penalty
|
| 27 |
-
temperature
|
| 28 |
-
top_p
|
| 29 |
}
|
| 30 |
|
| 31 |
export interface IDialog {
|
|
@@ -38,7 +38,7 @@ export interface IDialog {
|
|
| 38 |
kb_names: string[];
|
| 39 |
language: string;
|
| 40 |
llm_id: string;
|
| 41 |
-
llm_setting:
|
| 42 |
llm_setting_type: string;
|
| 43 |
name: string;
|
| 44 |
prompt_config: PromptConfig;
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
export interface Variable {
|
| 24 |
+
frequency_penalty?: number;
|
| 25 |
+
max_tokens?: number;
|
| 26 |
+
presence_penalty?: number;
|
| 27 |
+
temperature?: number;
|
| 28 |
+
top_p?: number;
|
| 29 |
}
|
| 30 |
|
| 31 |
export interface IDialog {
|
|
|
|
| 38 |
kb_names: string[];
|
| 39 |
language: string;
|
| 40 |
llm_id: string;
|
| 41 |
+
llm_setting: Variable;
|
| 42 |
llm_setting_type: string;
|
| 43 |
name: string;
|
| 44 |
prompt_config: PromptConfig;
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
|
@@ -181,6 +181,9 @@ const ChatConfigurationModal = ({
|
|
| 181 |
key={key}
|
| 182 |
show={key === value}
|
| 183 |
form={form}
|
|
|
|
|
|
|
|
|
|
| 184 |
{...(key === ConfigurationSegmented.PromptEngine
|
| 185 |
? { ref: promptEngineRef }
|
| 186 |
: {})}
|
|
|
|
| 181 |
key={key}
|
| 182 |
show={key === value}
|
| 183 |
form={form}
|
| 184 |
+
{...(key === ConfigurationSegmented.ModelSetting
|
| 185 |
+
? { initialLlmSetting: initialDialog.llm_setting, visible }
|
| 186 |
+
: {})}
|
| 187 |
{...(key === ConfigurationSegmented.PromptEngine
|
| 188 |
? { ref: promptEngineRef }
|
| 189 |
: {})}
|
web/src/pages/chat/chat-configuration-modal/model-setting.tsx
CHANGED
|
@@ -11,10 +11,19 @@ import { ISegmentedContentProps } from '../interface';
|
|
| 11 |
|
| 12 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 13 |
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llmHooks';
|
|
|
|
| 14 |
import { variableEnabledFieldMap } from '../constants';
|
| 15 |
import styles from './index.less';
|
| 16 |
|
| 17 |
-
const ModelSetting = ({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const { t } = useTranslate('chat');
|
| 19 |
const parameterOptions = Object.values(ModelVariableType).map((x) => ({
|
| 20 |
label: t(camelCase(x)),
|
|
@@ -29,14 +38,23 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 29 |
};
|
| 30 |
|
| 31 |
useEffect(() => {
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
pre
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
useFetchLlmList(LlmModelType.Chat);
|
| 42 |
|
|
@@ -60,7 +78,6 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 60 |
name="parameters"
|
| 61 |
tooltip={t('freedomTip')}
|
| 62 |
initialValue={ModelVariableType.Precise}
|
| 63 |
-
// rules={[{ required: true, message: 'Please input!' }]}
|
| 64 |
>
|
| 65 |
<Select<ModelVariableType>
|
| 66 |
options={parameterOptions}
|
|
@@ -76,26 +93,33 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 76 |
>
|
| 77 |
<Switch size="small" />
|
| 78 |
</Form.Item>
|
| 79 |
-
<
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
</Form.Item>
|
| 100 |
</Flex>
|
| 101 |
</Form.Item>
|
|
@@ -104,26 +128,33 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 104 |
<Form.Item name={'topPEnabled'} valuePropName="checked" noStyle>
|
| 105 |
<Switch size="small" />
|
| 106 |
</Form.Item>
|
| 107 |
-
<
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
</Form.Item>
|
| 128 |
</Flex>
|
| 129 |
</Form.Item>
|
|
@@ -136,26 +167,36 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 136 |
>
|
| 137 |
<Switch size="small" />
|
| 138 |
</Form.Item>
|
| 139 |
-
<
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
</Form.Item>
|
| 160 |
</Flex>
|
| 161 |
</Form.Item>
|
|
@@ -171,28 +212,39 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 171 |
>
|
| 172 |
<Switch size="small" />
|
| 173 |
</Form.Item>
|
| 174 |
-
<
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
</Form.Item>
|
| 197 |
</Flex>
|
| 198 |
</Form.Item>
|
|
@@ -201,25 +253,32 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => {
|
|
| 201 |
<Form.Item name={'maxTokensEnabled'} valuePropName="checked" noStyle>
|
| 202 |
<Switch size="small" />
|
| 203 |
</Form.Item>
|
| 204 |
-
<
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
</Form.Item>
|
| 224 |
</Flex>
|
| 225 |
</Form.Item>
|
|
|
|
| 11 |
|
| 12 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 13 |
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llmHooks';
|
| 14 |
+
import { Variable } from '@/interfaces/database/chat';
|
| 15 |
import { variableEnabledFieldMap } from '../constants';
|
| 16 |
import styles from './index.less';
|
| 17 |
|
| 18 |
+
const ModelSetting = ({
|
| 19 |
+
show,
|
| 20 |
+
form,
|
| 21 |
+
initialLlmSetting,
|
| 22 |
+
visible,
|
| 23 |
+
}: ISegmentedContentProps & {
|
| 24 |
+
initialLlmSetting?: Variable;
|
| 25 |
+
visible?: boolean;
|
| 26 |
+
}) => {
|
| 27 |
const { t } = useTranslate('chat');
|
| 28 |
const parameterOptions = Object.values(ModelVariableType).map((x) => ({
|
| 29 |
label: t(camelCase(x)),
|
|
|
|
| 38 |
};
|
| 39 |
|
| 40 |
useEffect(() => {
|
| 41 |
+
if (visible) {
|
| 42 |
+
const values = Object.keys(variableEnabledFieldMap).reduce<
|
| 43 |
+
Record<string, boolean>
|
| 44 |
+
>((pre, field) => {
|
| 45 |
+
pre[field] =
|
| 46 |
+
initialLlmSetting === undefined
|
| 47 |
+
? true
|
| 48 |
+
: !!initialLlmSetting[
|
| 49 |
+
variableEnabledFieldMap[
|
| 50 |
+
field as keyof typeof variableEnabledFieldMap
|
| 51 |
+
] as keyof Variable
|
| 52 |
+
];
|
| 53 |
+
return pre;
|
| 54 |
+
}, {});
|
| 55 |
+
form.setFieldsValue(values);
|
| 56 |
+
}
|
| 57 |
+
}, [form, initialLlmSetting, visible]);
|
| 58 |
|
| 59 |
useFetchLlmList(LlmModelType.Chat);
|
| 60 |
|
|
|
|
| 78 |
name="parameters"
|
| 79 |
tooltip={t('freedomTip')}
|
| 80 |
initialValue={ModelVariableType.Precise}
|
|
|
|
| 81 |
>
|
| 82 |
<Select<ModelVariableType>
|
| 83 |
options={parameterOptions}
|
|
|
|
| 93 |
>
|
| 94 |
<Switch size="small" />
|
| 95 |
</Form.Item>
|
| 96 |
+
<Form.Item noStyle dependencies={['temperatureEnabled']}>
|
| 97 |
+
{({ getFieldValue }) => {
|
| 98 |
+
const disabled = !getFieldValue('temperatureEnabled');
|
| 99 |
+
return (
|
| 100 |
+
<>
|
| 101 |
+
<Flex flex={1}>
|
| 102 |
+
<Form.Item name={['llm_setting', 'temperature']} noStyle>
|
| 103 |
+
<Slider
|
| 104 |
+
className={styles.variableSlider}
|
| 105 |
+
max={1}
|
| 106 |
+
step={0.01}
|
| 107 |
+
disabled={disabled}
|
| 108 |
+
/>
|
| 109 |
+
</Form.Item>
|
| 110 |
+
</Flex>
|
| 111 |
+
<Form.Item name={['llm_setting', 'temperature']} noStyle>
|
| 112 |
+
<InputNumber
|
| 113 |
+
className={styles.sliderInputNumber}
|
| 114 |
+
max={1}
|
| 115 |
+
min={0}
|
| 116 |
+
step={0.01}
|
| 117 |
+
disabled={disabled}
|
| 118 |
+
/>
|
| 119 |
+
</Form.Item>
|
| 120 |
+
</>
|
| 121 |
+
);
|
| 122 |
+
}}
|
| 123 |
</Form.Item>
|
| 124 |
</Flex>
|
| 125 |
</Form.Item>
|
|
|
|
| 128 |
<Form.Item name={'topPEnabled'} valuePropName="checked" noStyle>
|
| 129 |
<Switch size="small" />
|
| 130 |
</Form.Item>
|
| 131 |
+
<Form.Item noStyle dependencies={['topPEnabled']}>
|
| 132 |
+
{({ getFieldValue }) => {
|
| 133 |
+
const disabled = !getFieldValue('topPEnabled');
|
| 134 |
+
return (
|
| 135 |
+
<>
|
| 136 |
+
<Flex flex={1}>
|
| 137 |
+
<Form.Item name={['llm_setting', 'top_p']} noStyle>
|
| 138 |
+
<Slider
|
| 139 |
+
className={styles.variableSlider}
|
| 140 |
+
max={1}
|
| 141 |
+
step={0.01}
|
| 142 |
+
disabled={disabled}
|
| 143 |
+
/>
|
| 144 |
+
</Form.Item>
|
| 145 |
+
</Flex>
|
| 146 |
+
<Form.Item name={['llm_setting', 'top_p']} noStyle>
|
| 147 |
+
<InputNumber
|
| 148 |
+
className={styles.sliderInputNumber}
|
| 149 |
+
max={1}
|
| 150 |
+
min={0}
|
| 151 |
+
step={0.01}
|
| 152 |
+
disabled={disabled}
|
| 153 |
+
/>
|
| 154 |
+
</Form.Item>
|
| 155 |
+
</>
|
| 156 |
+
);
|
| 157 |
+
}}
|
| 158 |
</Form.Item>
|
| 159 |
</Flex>
|
| 160 |
</Form.Item>
|
|
|
|
| 167 |
>
|
| 168 |
<Switch size="small" />
|
| 169 |
</Form.Item>
|
| 170 |
+
<Form.Item noStyle dependencies={['presencePenaltyEnabled']}>
|
| 171 |
+
{({ getFieldValue }) => {
|
| 172 |
+
const disabled = !getFieldValue('presencePenaltyEnabled');
|
| 173 |
+
return (
|
| 174 |
+
<>
|
| 175 |
+
<Flex flex={1}>
|
| 176 |
+
<Form.Item
|
| 177 |
+
name={['llm_setting', 'presence_penalty']}
|
| 178 |
+
noStyle
|
| 179 |
+
>
|
| 180 |
+
<Slider
|
| 181 |
+
className={styles.variableSlider}
|
| 182 |
+
max={1}
|
| 183 |
+
step={0.01}
|
| 184 |
+
disabled={disabled}
|
| 185 |
+
/>
|
| 186 |
+
</Form.Item>
|
| 187 |
+
</Flex>
|
| 188 |
+
<Form.Item name={['llm_setting', 'presence_penalty']} noStyle>
|
| 189 |
+
<InputNumber
|
| 190 |
+
className={styles.sliderInputNumber}
|
| 191 |
+
max={1}
|
| 192 |
+
min={0}
|
| 193 |
+
step={0.01}
|
| 194 |
+
disabled={disabled}
|
| 195 |
+
/>
|
| 196 |
+
</Form.Item>
|
| 197 |
+
</>
|
| 198 |
+
);
|
| 199 |
+
}}
|
| 200 |
</Form.Item>
|
| 201 |
</Flex>
|
| 202 |
</Form.Item>
|
|
|
|
| 212 |
>
|
| 213 |
<Switch size="small" />
|
| 214 |
</Form.Item>
|
| 215 |
+
<Form.Item noStyle dependencies={['frequencyPenaltyEnabled']}>
|
| 216 |
+
{({ getFieldValue }) => {
|
| 217 |
+
const disabled = !getFieldValue('frequencyPenaltyEnabled');
|
| 218 |
+
return (
|
| 219 |
+
<>
|
| 220 |
+
<Flex flex={1}>
|
| 221 |
+
<Form.Item
|
| 222 |
+
name={['llm_setting', 'frequency_penalty']}
|
| 223 |
+
noStyle
|
| 224 |
+
>
|
| 225 |
+
<Slider
|
| 226 |
+
className={styles.variableSlider}
|
| 227 |
+
max={1}
|
| 228 |
+
step={0.01}
|
| 229 |
+
disabled={disabled}
|
| 230 |
+
/>
|
| 231 |
+
</Form.Item>
|
| 232 |
+
</Flex>
|
| 233 |
+
<Form.Item
|
| 234 |
+
name={['llm_setting', 'frequency_penalty']}
|
| 235 |
+
noStyle
|
| 236 |
+
>
|
| 237 |
+
<InputNumber
|
| 238 |
+
className={styles.sliderInputNumber}
|
| 239 |
+
max={1}
|
| 240 |
+
min={0}
|
| 241 |
+
step={0.01}
|
| 242 |
+
disabled={disabled}
|
| 243 |
+
/>
|
| 244 |
+
</Form.Item>
|
| 245 |
+
</>
|
| 246 |
+
);
|
| 247 |
+
}}
|
| 248 |
</Form.Item>
|
| 249 |
</Flex>
|
| 250 |
</Form.Item>
|
|
|
|
| 253 |
<Form.Item name={'maxTokensEnabled'} valuePropName="checked" noStyle>
|
| 254 |
<Switch size="small" />
|
| 255 |
</Form.Item>
|
| 256 |
+
<Form.Item noStyle dependencies={['maxTokensEnabled']}>
|
| 257 |
+
{({ getFieldValue }) => {
|
| 258 |
+
const disabled = !getFieldValue('maxTokensEnabled');
|
| 259 |
+
|
| 260 |
+
return (
|
| 261 |
+
<>
|
| 262 |
+
<Flex flex={1}>
|
| 263 |
+
<Form.Item name={['llm_setting', 'max_tokens']} noStyle>
|
| 264 |
+
<Slider
|
| 265 |
+
className={styles.variableSlider}
|
| 266 |
+
max={2048}
|
| 267 |
+
disabled={disabled}
|
| 268 |
+
/>
|
| 269 |
+
</Form.Item>
|
| 270 |
+
</Flex>
|
| 271 |
+
<Form.Item name={['llm_setting', 'max_tokens']} noStyle>
|
| 272 |
+
<InputNumber
|
| 273 |
+
disabled={disabled}
|
| 274 |
+
className={styles.sliderInputNumber}
|
| 275 |
+
max={2048}
|
| 276 |
+
min={0}
|
| 277 |
+
/>
|
| 278 |
+
</Form.Item>
|
| 279 |
+
</>
|
| 280 |
+
);
|
| 281 |
+
}}
|
| 282 |
</Form.Item>
|
| 283 |
</Flex>
|
| 284 |
</Form.Item>
|