feat(playground): enhance max_tokens handling and input sanitization
- Introduced `sanitizePlaygroundInputs` to normalize `max_tokens` input values. - Updated `loadConfig` to utilize the new sanitization function. - Replaced `Input` with `InputNumber` for `max_tokens` in `ParameterControl` for better user experience. - Modified API payload building logic to handle `max_tokens` more robustly. - Added tests for new helper functions in `playgroundMaxTokens.js` to ensure correct behavior.
This commit is contained in:
@@ -18,7 +18,14 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Input, Slider, Typography, Button, Tag } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
Input,
|
||||
InputNumber,
|
||||
Slider,
|
||||
Typography,
|
||||
Button,
|
||||
Tag,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Hash,
|
||||
@@ -241,15 +248,14 @@ const ParameterControl = ({
|
||||
disabled={disabled}
|
||||
/>
|
||||
</div>
|
||||
<Input
|
||||
<InputNumber
|
||||
placeholder='MaxTokens'
|
||||
name='max_tokens'
|
||||
required
|
||||
autoComplete='new-password'
|
||||
defaultValue={0}
|
||||
value={inputs.max_tokens}
|
||||
onChange={(value) => onInputChange('max_tokens', value)}
|
||||
className='!rounded-lg'
|
||||
onNumberChange={(value) => onInputChange('max_tokens', value)}
|
||||
min={0}
|
||||
precision={0}
|
||||
style={{ width: '100%' }}
|
||||
disabled={!parameterEnabled.max_tokens || disabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
STORAGE_KEYS,
|
||||
DEFAULT_CONFIG,
|
||||
} from '../../constants/playground.constants';
|
||||
import { sanitizePlaygroundInputs } from '../../helpers/playgroundMaxTokens';
|
||||
|
||||
const MESSAGES_STORAGE_KEY = 'playground_messages';
|
||||
|
||||
@@ -67,10 +68,10 @@ export const loadConfig = () => {
|
||||
const parsedConfig = JSON.parse(savedConfig);
|
||||
|
||||
const mergedConfig = {
|
||||
inputs: {
|
||||
inputs: sanitizePlaygroundInputs({
|
||||
...DEFAULT_CONFIG.inputs,
|
||||
...parsedConfig.inputs,
|
||||
},
|
||||
}),
|
||||
parameterEnabled: {
|
||||
...DEFAULT_CONFIG.parameterEnabled,
|
||||
...parsedConfig.parameterEnabled,
|
||||
|
||||
Reference in New Issue
Block a user