Update InputMessage component and ChatStore
- Update InputMessage component to include modelMenus in the input object - Add fetchModelMenus action to InputStore to fetch model menus - Update ChatStore to set the default chatModel to 'GPT-3.5'
This commit is contained in:
parent
4004f83fbe
commit
b5a0cb60f9
@ -13,7 +13,7 @@ import { Message } from "@/views/stores/ChatStore";
|
||||
const InputMessage = observer((props: any) => {
|
||||
const { chatPanelWidth } = props;
|
||||
const { input, chat } = useMst();
|
||||
const { contexts, menuOpend, menuType, currentMenuIndex, contextMenus, commandMenus } = input;
|
||||
const { contexts, menuOpend, menuType, currentMenuIndex, contextMenus, commandMenus,modelMenus } = input;
|
||||
const { generating } = chat;
|
||||
|
||||
const [drawerOpened, { open: openDrawer, close: closeDrawer }] = useDisclosure(false);
|
||||
@ -120,6 +120,7 @@ const InputMessage = observer((props: any) => {
|
||||
useEffect(() => {
|
||||
input.fetchContextMenus().then();
|
||||
input.fetchCommandMenus().then();
|
||||
input.fetchModelMenus().then();
|
||||
messageUtil.registerHandler('regCommandList', (message: { result: object[]}) => {
|
||||
input.updateCommands(message.result);
|
||||
});
|
||||
@ -159,6 +160,22 @@ const InputMessage = observer((props: any) => {
|
||||
inputRef.current.focus();
|
||||
}, []);
|
||||
|
||||
const getModelShowName = (modelName:string)=>{
|
||||
const nameMap = {
|
||||
"gpt-3.5-turbo": "GPT-3.5",
|
||||
"gpt-3.5-turbo-16k": "GPT-3.5-16K",
|
||||
"gpt-4": "GPT-4",
|
||||
"claude-2": "CLAUDE-2"
|
||||
};
|
||||
if (modelName in nameMap){
|
||||
return nameMap[modelName];
|
||||
} else if(modelName.lastIndexOf('/') > -1){
|
||||
return modelName.substring(modelName.lastIndexOf('/')+1).toLocaleUpperCase();
|
||||
} else {
|
||||
return modelName.toUpperCase();
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let filtered;
|
||||
if (input.value) {
|
||||
@ -226,8 +243,8 @@ const InputMessage = observer((props: any) => {
|
||||
chat.changeChatModel(value);
|
||||
messageUtil.sendMessage({
|
||||
command: "updateSetting",
|
||||
key1: "DevChat",
|
||||
key2: "OpenAI.model",
|
||||
key1: "devchat",
|
||||
key2: "defaultModel",
|
||||
value: value,
|
||||
});
|
||||
};
|
||||
@ -305,13 +322,15 @@ const InputMessage = observer((props: any) => {
|
||||
radius="xl"
|
||||
leftIcon={<IconRobot size="1rem" />}
|
||||
>
|
||||
GPT-3.5
|
||||
{getModelShowName(chat.chatModel)}
|
||||
</Button>
|
||||
</Menu.Target>
|
||||
<Menu.Dropdown>
|
||||
<Menu.Item onClick={() => changeModel("gpt-3.5-turbo")}>GPT-3.5</Menu.Item>
|
||||
<Menu.Item onClick={() => changeModel("gpt-3.5-turbo-16k")}>GPT-3.5-16K</Menu.Item>
|
||||
<Menu.Item onClick={() => changeModel("gpt-4")}>GPT-4</Menu.Item>
|
||||
{modelMenus.map((modelName) => {
|
||||
return <Menu.Item onClick={() => changeModel(modelName)}>
|
||||
{getModelShowName(modelName)}
|
||||
</Menu.Item>;
|
||||
})}
|
||||
</Menu.Dropdown>
|
||||
</Menu>
|
||||
</Group>
|
||||
|
@ -75,7 +75,7 @@ export const ChatStore = types.model('Chat', {
|
||||
isBottom: true,
|
||||
isTop: false,
|
||||
scrollBottom: 0,
|
||||
chatModel: 'gpt-4',
|
||||
chatModel: 'GPT-3.5',
|
||||
rechargeSite: 'https://devchat.ai/pricing/',
|
||||
features: types.optional(types.frozen(), {})
|
||||
})
|
||||
|
@ -20,6 +20,18 @@ const regContextMenus = async () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
const regModelMenus = async () => {
|
||||
return new Promise<String[]>((resolve, reject) => {
|
||||
try {
|
||||
messageUtil.sendMessage({ command: 'regModelList' });
|
||||
messageUtil.registerHandler('regModelList', (message: {result: String[]} ) => {
|
||||
resolve(message.result);
|
||||
});
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const ChatContext = types.model({
|
||||
file: types.maybe(types.string),
|
||||
@ -44,6 +56,7 @@ export const InputStore = types
|
||||
currentMenuIndex: 0,
|
||||
commandMenus: types.array(MenuItem),
|
||||
contextMenus: types.array(MenuItem),
|
||||
modelMenus: types.array(types.string)
|
||||
}).
|
||||
actions(self => ({
|
||||
setValue(value: string) {
|
||||
@ -88,7 +101,14 @@ export const InputStore = types
|
||||
console.error("Failed to fetch context menus", error);
|
||||
}
|
||||
}),
|
||||
|
||||
fetchModelMenus: flow(function* () {
|
||||
try {
|
||||
const models = yield regModelMenus();
|
||||
self.modelMenus.push(...models);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch context menus", error);
|
||||
}
|
||||
}),
|
||||
fetchCommandMenus: flow(function* () {
|
||||
const regCommandMenus = async () => {
|
||||
return new Promise<Item[]>((resolve, reject) => {
|
||||
@ -105,7 +125,7 @@ export const InputStore = types
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch command menus", error);
|
||||
}
|
||||
})
|
||||
}),
|
||||
}));
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user