feat: select chat model

This commit is contained in:
archer
2023-05-03 15:50:31 +08:00
parent 00a99261ae
commit e384893ae0
3 changed files with 23 additions and 4 deletions

View File

@@ -11,20 +11,31 @@ export enum OpenAiChatEnum {
export type ChatModelType = `${OpenAiChatEnum}`;
export type ChatModelItemType = {
chatModel: ChatModelType;
name: string;
contextMaxToken: number;
maxTemperature: number;
price: number;
};
export const ChatModelMap = {
[OpenAiChatEnum.GPT35]: {
chatModel: OpenAiChatEnum.GPT35,
name: 'ChatGpt',
contextMaxToken: 4096,
maxTemperature: 1.5,
price: 3
},
[OpenAiChatEnum.GPT4]: {
chatModel: OpenAiChatEnum.GPT4,
name: 'Gpt4',
contextMaxToken: 8000,
maxTemperature: 1.5,
price: 30
},
[OpenAiChatEnum.GPT432k]: {
chatModel: OpenAiChatEnum.GPT432k,
name: 'Gpt4-32k',
contextMaxToken: 32000,
maxTemperature: 1.5,
@@ -32,6 +43,8 @@ export const ChatModelMap = {
}
};
export const chatModelList: ChatModelItemType[] = [ChatModelMap[OpenAiChatEnum.GPT35]];
export enum ModelStatusEnum {
running = 'running',
training = 'training',

View File

@@ -21,7 +21,7 @@ import {
import { QuestionOutlineIcon } from '@chakra-ui/icons';
import type { ModelSchema } from '@/types/mongoSchema';
import { UseFormReturn } from 'react-hook-form';
import { ChatModelMap, ModelVectorSearchModeMap } from '@/constants/model';
import { ChatModelMap, ModelVectorSearchModeMap, chatModelList } from '@/constants/model';
import { formatPrice } from '@/utils/user';
import { useConfirm } from '@/hooks/useConfirm';
import { useSelectFile } from '@/hooks/useSelectFile';
@@ -110,14 +110,20 @@ const ModelEditForm = ({
<Box flex={'0 0 80px'} w={0}>
:
</Box>
<Box>{ChatModelMap[getValues('chat.chatModel')].name}</Box>
<Select isDisabled={!isOwner} {...register('chat.chatModel')}>
{chatModelList.map((item) => (
<option key={item.chatModel} value={item.chatModel}>
{item.name}
</option>
))}
</Select>
</Flex>
<Flex alignItems={'center'} mt={5}>
<Box flex={'0 0 80px'} w={0}>
:
</Box>
<Box>
{formatPrice(ChatModelMap[getValues('chat.chatModel')].price, 1000)}
{formatPrice(ChatModelMap[getValues('chat.chatModel')]?.price, 1000)}
/1K tokens()
</Box>
</Flex>

View File

@@ -14,6 +14,6 @@ export const clearToken = () => {
/**
* 把数据库读取到的price转化成元
*/
export const formatPrice = (val: number, multiple = 1) => {
export const formatPrice = (val = 0, multiple = 1) => {
return Number(((val / PRICE_SCALE) * multiple).toFixed(10));
};