feat: maxToken setting

This commit is contained in:
archer
2023-06-18 21:23:36 +08:00
parent ee9afa310a
commit ff2043c0fb
7 changed files with 54 additions and 6 deletions

View File

@@ -180,6 +180,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
await modelServiceToolMap[model.chat.chatModel].chatCompletion({
apiKey: userOpenAiKey || apiKey,
temperature: +temperature,
maxToken: model.chat.maxToken,
messages: completePrompts,
stream,
res

View File

@@ -36,11 +36,6 @@ const Settings = ({ modelId }: { modelId: string }) => {
const [btnLoading, setBtnLoading] = useState(false);
const [refresh, setRefresh] = useState(false);
const isOwner = useMemo(
() => modelDetail.userId === userInfo?._id,
[modelDetail.userId, userInfo?._id]
);
const {
register,
setValue,
@@ -52,6 +47,20 @@ const Settings = ({ modelId }: { modelId: string }) => {
defaultValues: modelDetail
});
const isOwner = useMemo(
() => modelDetail.userId === userInfo?._id,
[modelDetail.userId, userInfo?._id]
);
const tokenLimit = useMemo(() => {
const max = ChatModelMap[getValues('chat.chatModel')]?.contextMaxToken || 4000;
if (max < getValues('chat.maxToken')) {
setValue('chat.maxToken', max);
}
return max;
}, [getValues, setValue, refresh]);
// 提交保存模型修改
const saveSubmitSuccess = useCallback(
async (data: ModelSchema) => {
@@ -256,6 +265,27 @@ const Settings = ({ modelId }: { modelId: string }) => {
/>
</Box>
</Flex>
<Flex alignItems={'center'} mt={12} mb={10}>
<Box w={['60px', '100px', '140px']} flexShrink={0}>
</Box>
<Box flex={1} ml={'10px'}>
<MySlider
markList={[
{ label: '100', value: 100 },
{ label: `${tokenLimit}`, value: tokenLimit }
]}
width={['100%', '260px']}
min={100}
max={tokenLimit}
activeVal={getValues('chat.maxToken')}
setVal={(val) => {
setValue('chat.maxToken', val);
setRefresh(!refresh);
}}
/>
</Box>
</Flex>
<Flex mt={10} alignItems={'flex-start'}>
<Box w={['60px', '100px', '140px']} flexShrink={0}>