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:
HynoR
2026-04-06 00:40:08 +08:00
parent 677d02f2ab
commit 4cd0e3651d
7 changed files with 139 additions and 13 deletions
+12 -3
View File
@@ -32,7 +32,11 @@ import {
loadMessages,
saveMessages,
} from '../../components/playground/configStorage';
import { processIncompleteThinkTags } from '../../helpers';
import {
processIncompleteThinkTags,
normalizePlaygroundInputValue,
sanitizePlaygroundInputs,
} from '../../helpers';
export const usePlaygroundState = () => {
const { t } = useTranslation();
@@ -121,7 +125,10 @@ export const usePlaygroundState = () => {
// 配置更新函数
const handleInputChange = useCallback((name, value) => {
setInputs((prev) => ({ ...prev, [name]: value }));
setInputs((prev) => ({
...prev,
[name]: normalizePlaygroundInputValue(name, value),
}));
}, []);
const handleParameterToggle = useCallback((paramName) => {
@@ -167,7 +174,9 @@ export const usePlaygroundState = () => {
// 配置导入/重置
const handleConfigImport = useCallback((importedConfig) => {
if (importedConfig.inputs) {
setInputs((prev) => ({ ...prev, ...importedConfig.inputs }));
setInputs((prev) =>
sanitizePlaygroundInputs({ ...prev, ...importedConfig.inputs }),
);
}
if (importedConfig.parameterEnabled) {
setParameterEnabled((prev) => ({