feat: set default model once model list read.

This commit is contained in:
Wentao Lyu 2023-03-16 21:12:33 +08:00
parent 131af50034
commit b6f7f95709
3 changed files with 27 additions and 7 deletions

View file

@ -30,8 +30,6 @@ export default function ModelItem({ modelName, value, model, onSelect, id, chatG
const icon = getIconOfModel({ size: 16, sender: modelName, isCreatedByUser: false, model, chatGptLabel, promptPrefix, error: false, className: "mr-2" }); const icon = getIconOfModel({ size: 16, sender: modelName, isCreatedByUser: false, model, chatGptLabel, promptPrefix, error: false, className: "mr-2" });
if (!initial[model]) return null
if (value === 'chatgptCustom') { if (value === 'chatgptCustom') {
return ( return (
<DialogTrigger className="w-full"> <DialogTrigger className="w-full">

View file

@ -72,6 +72,24 @@ export default function ModelMenu() {
const initial = {chatgpt: data?.hasOpenAI, chatgptCustom: data?.hasOpenAI, bingai: data?.hasBing, sydney: data?.hasBing, chatgptBrowser: data?.hasChatGpt} const initial = {chatgpt: data?.hasOpenAI, chatgptCustom: data?.hasOpenAI, bingai: data?.hasBing, sydney: data?.hasBing, chatgptBrowser: data?.hasChatGpt}
dispatch(setInitial(initial)) dispatch(setInitial(initial))
// TODO, auto reset default model // TODO, auto reset default model
if (data?.hasOpenAI) {
dispatch(setModel('chatgpt'));
dispatch(setDisabled(false));
dispatch(setCustomModel(null));
dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
} else if (data?.hasBing) {
dispatch(setModel('bingai'));
dispatch(setDisabled(false));
dispatch(setCustomModel(null));
dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
} else if (data?.hasChatGpt) {
dispatch(setModel('chatgptBrowser'));
dispatch(setDisabled(false));
dispatch(setCustomModel(null));
dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
} else {
dispatch(setDisabled(true));
}
}).catch((error) => { }).catch((error) => {
console.error(error) console.error(error)
console.log('Not login!') console.log('Not login!')
@ -83,6 +101,8 @@ export default function ModelMenu() {
localStorage.setItem('model', JSON.stringify(model)); localStorage.setItem('model', JSON.stringify(model));
}, [model]); }, [model]);
const filteredModels = models.filter(({model}) => initial[model])
const onChange = (value) => { const onChange = (value) => {
if (!value) { if (!value) {
return; return;
@ -183,10 +203,12 @@ export default function ModelMenu() {
onValueChange={onChange} onValueChange={onChange}
className="overflow-y-auto" className="overflow-y-auto"
> >
<MenuItems {filteredModels.length?
models={models} <MenuItems
onSelect={onChange} models={filteredModels}
/> onSelect={onChange}
/>:<DropdownMenuLabel className="dark:text-gray-300">No model available.</DropdownMenuLabel>
}
</DropdownMenuRadioGroup> </DropdownMenuRadioGroup>
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>

View file

@ -4,7 +4,7 @@ const initialState = {
isSubmitting: false, isSubmitting: false,
submission: {}, submission: {},
stopStream: false, stopStream: false,
disabled: false, disabled: true,
model: 'chatgpt', model: 'chatgpt',
promptPrefix: null, promptPrefix: null,
chatGptLabel: null, chatGptLabel: null,