feat: the temperature and maxTokens of the openai can be configured

This commit is contained in:
Gabe Yuan
2024-05-21 23:15:46 +08:00
parent 0198963584
commit 5d1d65c2d3
4 changed files with 55 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ import { useApi } from "../../hooks/Api";
import { apiTranslate } from "../../apis";
import Box from "@mui/material/Box";
import Link from "@mui/material/Link";
import { limitNumber } from "../../libs/utils";
import { limitNumber, limitFloat } from "../../libs/utils";
function TestButton({ translator, api }) {
const i18n = useI18n();
@@ -121,6 +121,8 @@ function ApiFields({ translator }) {
memoryNo = "",
reqHook = "",
resHook = "",
temperature = 0,
maxTokens = 256,
} = api;
const handleChange = (e) => {
@@ -132,6 +134,12 @@ function ApiFields({ translator }) {
case "fetchInterval":
value = limitNumber(value, 0, 5000);
break;
case "temperature":
value = limitFloat(value, 0, 2);
break;
case "maxTokens":
value = limitNumber(value, 0, 2 ** 15);
break;
default:
}
updateApi({
@@ -225,6 +233,27 @@ function ApiFields({ translator }) {
</>
)}
{translator.startsWith(OPT_TRANS_OPENAI) && (
<>
<TextField
size="small"
label={"Temperature"}
type="number"
name="temperature"
value={temperature}
onChange={handleChange}
/>
<TextField
size="small"
label={"Max Tokens"}
type="number"
name="maxTokens"
value={maxTokens}
onChange={handleChange}
/>
</>
)}
{translator === OPT_TRANS_NIUTRANS && (
<>
<TextField