Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#3229 from Yidadaa/bugfix-1112
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa authored Nov 11, 2023
2 parents 4b44b0c + aef03f9 commit 50dafa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,27 @@ export function ChatActions(props: {

// switch model
const currentModel = chatStore.currentSession().mask.modelConfig.model;
const models = useAllModels()
.filter((m) => m.available)
.map((m) => m.name);
const allModels = useAllModels();
const models = useMemo(
() => allModels.filter((m) => m.available).map((m) => m.name),
[allModels],
);
const [showModelSelector, setShowModelSelector] = useState(false);

useEffect(() => {
// if current model is not available
// switch to first available model
const isUnavaliableModel = !models.includes(currentModel);
if (isUnavaliableModel && models.length > 0) {
const nextModel = models[0] as ModelType;
chatStore.updateCurrentSession(
(session) => (session.mask.modelConfig.model = nextModel),
);
showToast(nextModel);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentModel, models]);

return (
<div className={styles["chat-input-actions"]}>
{couldStop && (
Expand Down
2 changes: 1 addition & 1 deletion app/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function useAllModels() {
const models = useMemo(() => {
return collectModels(
configStore.models,
[accessStore.customModels, configStore.customModels].join(","),
[configStore.customModels, accessStore.customModels].join(","),
);
}, [accessStore.customModels, configStore.customModels, configStore.models]);

Expand Down

0 comments on commit 50dafa4

Please sign in to comment.