Skip to content

Commit

Permalink
feat: close ChatGPTNextWeb#2013 add switch model button to chat actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa committed Jun 24, 2023
1 parent 0e30f72 commit e9b4523
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DarkIcon from "../icons/dark.svg";
import AutoIcon from "../icons/auto.svg";
import BottomIcon from "../icons/bottom.svg";
import StopIcon from "../icons/pause.svg";
import RobotIcon from "../icons/robot.svg";

import {
ChatMessage,
Expand All @@ -38,6 +39,7 @@ import {
Theme,
useAppConfig,
DEFAULT_TOPIC,
ALL_MODELS,
} from "../store";

import {
Expand Down Expand Up @@ -385,6 +387,19 @@ export function ChatActions(props: {
const couldStop = ChatControllerPool.hasPending();
const stopAll = () => ChatControllerPool.stopAll();

// switch model
const currentModel = chatStore.currentSession().mask.modelConfig.model;
function nextModel() {
const models = ALL_MODELS.filter((m) => m.available).map((m) => m.name);
const modelIndex = models.indexOf(currentModel);
const nextIndex = (modelIndex + 1) % models.length;
const nextModel = models[nextIndex];
chatStore.updateCurrentSession((session) => {
session.mask.modelConfig.model = nextModel;
session.mask.syncGlobalConfig = false;
});
}

return (
<div className={chatStyle["chat-input-actions"]}>
{couldStop && (
Expand Down Expand Up @@ -453,6 +468,12 @@ export function ChatActions(props: {
});
}}
/>

<ChatAction
onClick={nextModel}
text={currentModel}
icon={<RobotIcon />}
/>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions app/icons/robot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e9b4523

Please sign in to comment.