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 InputMessage = observer((props: any) => {
|
||||||
const { chatPanelWidth } = props;
|
const { chatPanelWidth } = props;
|
||||||
const { input, chat } = useMst();
|
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 { generating } = chat;
|
||||||
|
|
||||||
const [drawerOpened, { open: openDrawer, close: closeDrawer }] = useDisclosure(false);
|
const [drawerOpened, { open: openDrawer, close: closeDrawer }] = useDisclosure(false);
|
||||||
@ -120,6 +120,7 @@ const InputMessage = observer((props: any) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
input.fetchContextMenus().then();
|
input.fetchContextMenus().then();
|
||||||
input.fetchCommandMenus().then();
|
input.fetchCommandMenus().then();
|
||||||
|
input.fetchModelMenus().then();
|
||||||
messageUtil.registerHandler('regCommandList', (message: { result: object[]}) => {
|
messageUtil.registerHandler('regCommandList', (message: { result: object[]}) => {
|
||||||
input.updateCommands(message.result);
|
input.updateCommands(message.result);
|
||||||
});
|
});
|
||||||
@ -159,6 +160,22 @@ const InputMessage = observer((props: any) => {
|
|||||||
inputRef.current.focus();
|
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(() => {
|
useEffect(() => {
|
||||||
let filtered;
|
let filtered;
|
||||||
if (input.value) {
|
if (input.value) {
|
||||||
@ -226,8 +243,8 @@ const InputMessage = observer((props: any) => {
|
|||||||
chat.changeChatModel(value);
|
chat.changeChatModel(value);
|
||||||
messageUtil.sendMessage({
|
messageUtil.sendMessage({
|
||||||
command: "updateSetting",
|
command: "updateSetting",
|
||||||
key1: "DevChat",
|
key1: "devchat",
|
||||||
key2: "OpenAI.model",
|
key2: "defaultModel",
|
||||||
value: value,
|
value: value,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -305,13 +322,15 @@ const InputMessage = observer((props: any) => {
|
|||||||
radius="xl"
|
radius="xl"
|
||||||
leftIcon={<IconRobot size="1rem" />}
|
leftIcon={<IconRobot size="1rem" />}
|
||||||
>
|
>
|
||||||
GPT-3.5
|
{getModelShowName(chat.chatModel)}
|
||||||
</Button>
|
</Button>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
<Menu.Item onClick={() => changeModel("gpt-3.5-turbo")}>GPT-3.5</Menu.Item>
|
{modelMenus.map((modelName) => {
|
||||||
<Menu.Item onClick={() => changeModel("gpt-3.5-turbo-16k")}>GPT-3.5-16K</Menu.Item>
|
return <Menu.Item onClick={() => changeModel(modelName)}>
|
||||||
<Menu.Item onClick={() => changeModel("gpt-4")}>GPT-4</Menu.Item>
|
{getModelShowName(modelName)}
|
||||||
|
</Menu.Item>;
|
||||||
|
})}
|
||||||
</Menu.Dropdown>
|
</Menu.Dropdown>
|
||||||
</Menu>
|
</Menu>
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -75,7 +75,7 @@ export const ChatStore = types.model('Chat', {
|
|||||||
isBottom: true,
|
isBottom: true,
|
||||||
isTop: false,
|
isTop: false,
|
||||||
scrollBottom: 0,
|
scrollBottom: 0,
|
||||||
chatModel: 'gpt-4',
|
chatModel: 'GPT-3.5',
|
||||||
rechargeSite: 'https://devchat.ai/pricing/',
|
rechargeSite: 'https://devchat.ai/pricing/',
|
||||||
features: types.optional(types.frozen(), {})
|
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({
|
export const ChatContext = types.model({
|
||||||
file: types.maybe(types.string),
|
file: types.maybe(types.string),
|
||||||
@ -44,6 +56,7 @@ export const InputStore = types
|
|||||||
currentMenuIndex: 0,
|
currentMenuIndex: 0,
|
||||||
commandMenus: types.array(MenuItem),
|
commandMenus: types.array(MenuItem),
|
||||||
contextMenus: types.array(MenuItem),
|
contextMenus: types.array(MenuItem),
|
||||||
|
modelMenus: types.array(types.string)
|
||||||
}).
|
}).
|
||||||
actions(self => ({
|
actions(self => ({
|
||||||
setValue(value: string) {
|
setValue(value: string) {
|
||||||
@ -88,7 +101,14 @@ export const InputStore = types
|
|||||||
console.error("Failed to fetch context menus", error);
|
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* () {
|
fetchCommandMenus: flow(function* () {
|
||||||
const regCommandMenus = async () => {
|
const regCommandMenus = async () => {
|
||||||
return new Promise<Item[]>((resolve, reject) => {
|
return new Promise<Item[]>((resolve, reject) => {
|
||||||
@ -105,7 +125,7 @@ export const InputStore = types
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch command menus", error);
|
console.error("Failed to fetch command menus", error);
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user