From a095a2c01cd91b352f0ba0470a8e878d48a82974 Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 15 Oct 2025 00:59:32 +0800 Subject: [PATCH] fix: temperature limit float --- src/config/api.js | 2 +- src/hooks/ValidationInput.js | 16 +++++++++++++--- src/libs/utils.js | 2 +- src/views/Options/Apis.js | 5 +++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/config/api.js b/src/config/api.js index 79090f0..3a7de0a 100644 --- a/src/config/api.js +++ b/src/config/api.js @@ -448,7 +448,7 @@ const defaultApi = { useBatchFetch: false, // 是否启用聚合发送请求 useContext: false, // 是否启用智能上下文 contextSize: DEFAULT_CONTEXT_SIZE, // 智能上下文保留会话数 - temperature: 0, + temperature: 0.0, maxTokens: 20480, think: false, thinkIgnore: "qwen3,deepseek-r1", diff --git a/src/hooks/ValidationInput.js b/src/hooks/ValidationInput.js index 1c873f7..0cb1a38 100644 --- a/src/hooks/ValidationInput.js +++ b/src/hooks/ValidationInput.js @@ -1,8 +1,16 @@ import { useState, useEffect } from "react"; import TextField from "@mui/material/TextField"; -import { limitNumber } from "../libs/utils"; +import { limitNumber, limitFloat } from "../libs/utils"; -function ValidationInput({ value, onChange, name, min, max, ...props }) { +function ValidationInput({ + value, + onChange, + name, + min, + max, + isFloat = false, + ...props +}) { const [localValue, setLocalValue] = useState(value); useEffect(() => { @@ -21,7 +29,9 @@ function ValidationInput({ value, onChange, name, min, max, ...props }) { return; } - const validatedValue = limitNumber(numValue, min, max); + const validatedValue = isFloat + ? limitFloat(numValue, min, max) + : limitNumber(numValue, min, max); if (validatedValue !== numValue) { setLocalValue(validatedValue); diff --git a/src/libs/utils.js b/src/libs/utils.js index a66008f..95348bc 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -15,7 +15,7 @@ export const limitNumber = (num, min = 0, max = 100) => { return number; }; -export const limitFloat = (num, min = 0, max = 100) => { +export const limitFloat = (num, min = 0.0, max = 100.0) => { const number = parseFloat(num); if (Number.isNaN(number) || number < min) { return min; diff --git a/src/views/Options/Apis.js b/src/views/Options/Apis.js index f80af09..93709d8 100644 --- a/src/views/Options/Apis.js +++ b/src/views/Options/Apis.js @@ -299,8 +299,9 @@ function ApiFields({ apiSlug, isUserApi, deleteApi }) { name="temperature" value={temperature} onChange={handleChange} - min={0} - max={2} + min={0.0} + max={2.0} + isFloat={true} />