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" });
if (!initial[model]) return null
if (value === 'chatgptCustom') {
return (
<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}
dispatch(setInitial(initial))
// 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) => {
console.error(error)
console.log('Not login!')
@ -83,6 +101,8 @@ export default function ModelMenu() {
localStorage.setItem('model', JSON.stringify(model));
}, [model]);
const filteredModels = models.filter(({model}) => initial[model])
const onChange = (value) => {
if (!value) {
return;
@ -183,10 +203,12 @@ export default function ModelMenu() {
onValueChange={onChange}
className="overflow-y-auto"
>
{filteredModels.length?
<MenuItems
models={models}
models={filteredModels}
onSelect={onChange}
/>
/>:<DropdownMenuLabel className="dark:text-gray-300">No model available.</DropdownMenuLabel>
}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>

View file

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