Merge pull request #4106 from HynoR/feat/fix
Some checks failed
Publish Docker image (Multi Registries, native amd64+arm64) / Build & push (amd64) [native] (push) Has been cancelled
Publish Docker image (Multi Registries, native amd64+arm64) / Build & push (arm64) [native] (push) Has been cancelled
Publish Docker image (Multi Registries, native amd64+arm64) / Create multi-arch manifests (Docker Hub) (push) Has been cancelled
Build Electron App / build (windows-latest) (push) Has been cancelled
Build Electron App / release (push) Has been cancelled
Release (Linux, macOS, Windows) / Linux Release (push) Has been cancelled
Release (Linux, macOS, Windows) / macOS Release (push) Has been cancelled
Release (Linux, macOS, Windows) / Windows Release (push) Has been cancelled
Some checks failed
Publish Docker image (Multi Registries, native amd64+arm64) / Build & push (amd64) [native] (push) Has been cancelled
Publish Docker image (Multi Registries, native amd64+arm64) / Build & push (arm64) [native] (push) Has been cancelled
Publish Docker image (Multi Registries, native amd64+arm64) / Create multi-arch manifests (Docker Hub) (push) Has been cancelled
Build Electron App / build (windows-latest) (push) Has been cancelled
Build Electron App / release (push) Has been cancelled
Release (Linux, macOS, Windows) / Linux Release (push) Has been cancelled
Release (Linux, macOS, Windows) / macOS Release (push) Has been cancelled
Release (Linux, macOS, Windows) / Windows Release (push) Has been cancelled
feat(playground): enhance max_tokens handling and input sanitization
This commit is contained in:
commit
eacc245bad
@ -18,7 +18,14 @@ For commercial licensing, please contact support@quantumnous.com
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
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 { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
Hash,
|
Hash,
|
||||||
@ -241,15 +248,14 @@ const ParameterControl = ({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<InputNumber
|
||||||
placeholder='MaxTokens'
|
placeholder='MaxTokens'
|
||||||
name='max_tokens'
|
name='max_tokens'
|
||||||
required
|
|
||||||
autoComplete='new-password'
|
|
||||||
defaultValue={0}
|
|
||||||
value={inputs.max_tokens}
|
value={inputs.max_tokens}
|
||||||
onChange={(value) => onInputChange('max_tokens', value)}
|
onNumberChange={(value) => onInputChange('max_tokens', value)}
|
||||||
className='!rounded-lg'
|
min={0}
|
||||||
|
precision={0}
|
||||||
|
style={{ width: '100%' }}
|
||||||
disabled={!parameterEnabled.max_tokens || disabled}
|
disabled={!parameterEnabled.max_tokens || disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -65,11 +65,15 @@ export const loadConfig = () => {
|
|||||||
const savedConfig = localStorage.getItem(STORAGE_KEYS.CONFIG);
|
const savedConfig = localStorage.getItem(STORAGE_KEYS.CONFIG);
|
||||||
if (savedConfig) {
|
if (savedConfig) {
|
||||||
const parsedConfig = JSON.parse(savedConfig);
|
const parsedConfig = JSON.parse(savedConfig);
|
||||||
|
const parsedMaxTokens = parseInt(parsedConfig?.inputs?.max_tokens, 10);
|
||||||
|
|
||||||
const mergedConfig = {
|
const mergedConfig = {
|
||||||
inputs: {
|
inputs: {
|
||||||
...DEFAULT_CONFIG.inputs,
|
...DEFAULT_CONFIG.inputs,
|
||||||
...parsedConfig.inputs,
|
...parsedConfig.inputs,
|
||||||
|
max_tokens: Number.isNaN(parsedMaxTokens)
|
||||||
|
? parsedConfig?.inputs?.max_tokens
|
||||||
|
: parsedMaxTokens,
|
||||||
},
|
},
|
||||||
parameterEnabled: {
|
parameterEnabled: {
|
||||||
...DEFAULT_CONFIG.parameterEnabled,
|
...DEFAULT_CONFIG.parameterEnabled,
|
||||||
|
|||||||
13
web/src/helpers/api.js
vendored
13
web/src/helpers/api.js
vendored
@ -150,7 +150,18 @@ export const buildApiPayload = (
|
|||||||
const value = inputs[param];
|
const value = inputs[param];
|
||||||
const hasValue = value !== undefined && value !== null;
|
const hasValue = value !== undefined && value !== null;
|
||||||
|
|
||||||
if (enabled && hasValue) {
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param === 'max_tokens') {
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
payload[param] = value;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasValue) {
|
||||||
payload[param] = value;
|
payload[param] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -167,7 +167,14 @@ export const usePlaygroundState = () => {
|
|||||||
// 配置导入/重置
|
// 配置导入/重置
|
||||||
const handleConfigImport = useCallback((importedConfig) => {
|
const handleConfigImport = useCallback((importedConfig) => {
|
||||||
if (importedConfig.inputs) {
|
if (importedConfig.inputs) {
|
||||||
setInputs((prev) => ({ ...prev, ...importedConfig.inputs }));
|
const parsedMaxTokens = parseInt(importedConfig.inputs.max_tokens, 10);
|
||||||
|
setInputs((prev) => ({
|
||||||
|
...prev,
|
||||||
|
...importedConfig.inputs,
|
||||||
|
max_tokens: Number.isNaN(parsedMaxTokens)
|
||||||
|
? importedConfig.inputs.max_tokens
|
||||||
|
: parsedMaxTokens,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
if (importedConfig.parameterEnabled) {
|
if (importedConfig.parameterEnabled) {
|
||||||
setParameterEnabled((prev) => ({
|
setParameterEnabled((prev) => ({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user