Merge remote-tracking branch 'origin/upstream/main'

This commit is contained in:
Laisky.Cai
2024-01-28 13:44:16 +00:00
113 changed files with 3608 additions and 3013 deletions

View File

@@ -6,6 +6,10 @@ const useRegister = () => {
const navigate = useNavigate();
const register = async (input, turnstile) => {
try {
let affCode = localStorage.getItem('aff');
if (affCode) {
input = { ...input, aff_code: affCode };
}
const res = await API.post(`/api/user/register?turnstile=${turnstile}`, input);
const { success, message } = res.data;
if (success) {

View File

@@ -26,7 +26,7 @@ const MinimalLayout = () => {
<Header />
</Toolbar>
</AppBar>
<Box sx={{ flex: '1 1 auto', overflow: 'auto' }} paddingTop={'64px'}>
<Box sx={{ flex: '1 1 auto', overflow: 'auto' }} marginTop={'80px'}>
<Outlet />
</Box>
<Box sx={{ flex: 'none' }}>

View File

@@ -15,7 +15,7 @@ import { useSelector } from 'react-redux';
const Logo = () => {
const siteInfo = useSelector((state) => state.siteInfo);
return <img src={siteInfo.logo || logo} alt={siteInfo.system_name} width="80" />;
return <img src={siteInfo.logo || logo} alt={siteInfo.system_name} height="50" />;
};
export default Logo;

View File

@@ -21,12 +21,18 @@ import {
Container,
Autocomplete,
FormHelperText,
Checkbox
} from "@mui/material";
import { Formik } from "formik";
import * as Yup from "yup";
import { defaultConfig, typeConfig } from "../type/Config"; //typeConfig
import { createFilterOptions } from "@mui/material/Autocomplete";
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';
const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
const checkedIcon = <CheckBoxIcon fontSize="small" />;
const filter = createFilterOptions();
const validationSchema = Yup.object().shape({
@@ -41,7 +47,7 @@ const validationSchema = Yup.object().shape({
models: Yup.array().min(1, "模型 不能为空"),
groups: Yup.array().min(1, "用户组 不能为空"),
base_url: Yup.string().when("type", {
is: (value) => [3, 24, 8].includes(value),
is: (value) => [3, 8].includes(value),
then: Yup.string().required("渠道API地址 不能为空"), // base_url 是必需的
otherwise: Yup.string(), // 在其他情况下base_url 可以是任意字符串
}),
@@ -144,8 +150,23 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
const fetchModels = async () => {
try {
let res = await API.get(`/api/channel/models`);
const { data } = res.data;
data.forEach(item => {
if (!item.owned_by) {
item.owned_by = "未知";
}
});
// 先对data排序
data.sort((a, b) => {
const ownedByComparison = a.owned_by.localeCompare(b.owned_by);
if (ownedByComparison === 0) {
return a.id.localeCompare(b.id);
}
return ownedByComparison;
});
setModelOptions(
res.data.data.map((model) => {
data.map((model) => {
return {
id: model.id,
group: model.owned_by,
@@ -237,6 +258,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
2
);
}
data.base_url = data.base_url ?? '';
data.is_edit = true;
initChannel(data.type);
setInitialInput(data);
@@ -248,12 +270,16 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
useEffect(() => {
fetchGroups().then();
fetchModels().then();
}, []);
useEffect(() => {
if (channelId) {
loadChannel().then();
} else {
initChannel(1);
setInitialInput({ ...defaultConfig.input, is_edit: false });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channelId]);
return (
@@ -489,7 +515,8 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
handleChange(event);
}}
onBlur={handleBlur}
filterSelectedOptions
// filterSelectedOptions
disableCloseOnSelect
renderInput={(params) => (
<TextField
{...params}
@@ -522,6 +549,12 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
}
return filtered;
}}
renderOption={(props, option, { selected }) => (
<li {...props}>
<Checkbox icon={icon} checkedIcon={checkedIcon} style={{ marginRight: 8 }} checked={selected} />
{option.id}
</li>
)}
/>
{errors.models ? (
<FormHelperText error id="helper-tex-channel-models-label">

View File

@@ -27,6 +27,7 @@ const OperationSetting = () => {
QuotaRemindThreshold: 0,
PreConsumedQuota: 0,
ModelRatio: "",
CompletionRatio: "",
GroupRatio: "",
TopUpLink: "",
ChatLink: "",
@@ -52,9 +53,12 @@ const OperationSetting = () => {
if (success) {
let newInputs = {};
data.forEach((item) => {
if (item.key === "ModelRatio" || item.key === "GroupRatio") {
if (item.key === "ModelRatio" || item.key === "GroupRatio" || item.key === "CompletionRatio") {
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
}
if (item.value === '{}') {
item.value = '';
}
newInputs[item.key] = item.value;
});
setInputs(newInputs);
@@ -133,6 +137,13 @@ const OperationSetting = () => {
}
await updateOption("GroupRatio", inputs.GroupRatio);
}
if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) {
if (!verifyJSON(inputs.CompletionRatio)) {
showError('补全倍率不是合法的 JSON 字符串');
return;
}
await updateOption('CompletionRatio', inputs.CompletionRatio);
}
break;
case "quota":
if (originInputs["QuotaForNewUser"] !== inputs.QuotaForNewUser) {
@@ -500,7 +511,20 @@ const OperationSetting = () => {
placeholder="为一个 JSON 文本,键为模型名称,值为倍率"
/>
</FormControl>
<FormControl fullWidth>
<TextField
multiline
maxRows={15}
id="channel-CompletionRatio-label"
label="补全倍率"
value={inputs.CompletionRatio}
name="CompletionRatio"
onChange={handleInputChange}
aria-describedby="helper-text-channel-CompletionRatio-label"
minRows={5}
placeholder="为一个 JSON 文本,键为模型名称,值为倍率,此处的倍率设置是模型补全倍率相较于提示倍率的比例,使用该设置可强制覆盖 One API 的内部比例"
/>
</FormControl>
<FormControl fullWidth>
<TextField
multiline

View File

@@ -192,7 +192,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
id={`switch-${item.id}`}
checked={statusSwitch === 1}
onChange={handleStatus}
disabled={statusSwitch !== 1 && statusSwitch !== 2}
// disabled={statusSwitch !== 1 && statusSwitch !== 2}
/>
</Tooltip>
</TableCell>
@@ -222,7 +222,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
</Button>
</ButtonGroup>
<ButtonGroup size="small" aria-label="split button">
<Button color="primary">聊天</Button>
<Button color="primary" onClick={(e) => handleCopy(COPY_OPTIONS[0], 'link')}>聊天</Button>
<Button size="small" onClick={(e) => handleOpenMenu(e, 'link')}>
<IconCaretDownFilled size={'16px'} />
</Button>

View File

@@ -11,6 +11,7 @@ const OperationSetting = () => {
QuotaRemindThreshold: 0,
PreConsumedQuota: 0,
ModelRatio: '',
CompletionRatio: '',
GroupRatio: '',
TopUpLink: '',
ChatLink: '',
@@ -34,9 +35,12 @@ const OperationSetting = () => {
if (success) {
let newInputs = {};
data.forEach((item) => {
if (item.key === 'ModelRatio' || item.key === 'GroupRatio') {
if (item.key === 'ModelRatio' || item.key === 'GroupRatio' || item.key === 'CompletionRatio') {
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
}
if (item.value === '{}') {
item.value = '';
}
newInputs[item.key] = item.value;
});
setInputs(newInputs);
@@ -101,6 +105,13 @@ const OperationSetting = () => {
}
await updateOption('GroupRatio', inputs.GroupRatio);
}
if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) {
if (!verifyJSON(inputs.CompletionRatio)) {
showError('补全倍率不是合法的 JSON 字符串');
return;
}
await updateOption('CompletionRatio', inputs.CompletionRatio);
}
break;
case 'quota':
if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) {
@@ -271,10 +282,10 @@ const OperationSetting = () => {
onChange={handleInputChange}
/>
<Form.Checkbox
checked={inputs.AutomaticEnableChannelEnabled === 'true'}
label='成功时自动启用通道'
name='AutomaticEnableChannelEnabled'
onChange={handleInputChange}
checked={inputs.AutomaticEnableChannelEnabled === 'true'}
label='成功时自动启用通道'
name='AutomaticEnableChannelEnabled'
onChange={handleInputChange}
/>
</Form.Group>
<Form.Button onClick={() => {
@@ -344,6 +355,17 @@ const OperationSetting = () => {
placeholder='为一个 JSON 文本,键为模型名称,值为倍率'
/>
</Form.Group>
<Form.Group widths='equal'>
<Form.TextArea
label='补全倍率'
name='CompletionRatio'
onChange={handleInputChange}
style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
autoComplete='new-password'
value={inputs.CompletionRatio}
placeholder='为一个 JSON 文本,键为模型名称,值为倍率,此处的倍率设置是模型补全倍率相较于提示倍率的比例,使用该设置可强制覆盖 One API 的内部比例'
/>
</Form.Group>
<Form.Group widths='equal'>
<Form.TextArea
label='分组倍率'