From 64e9c9d50d73761fc38c9caa2c9dbb83aa66c0a9 Mon Sep 17 00:00:00 2001 From: Deng Junhai Date: Wed, 27 Mar 2024 00:07:22 +0800 Subject: [PATCH] fix: fix model market select not take effect issue (#139) fix: fix model market select not take effect issue (#139) Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com> --- app/src/components/home/ModelFinder.tsx | 5 +- .../components/home/assemblies/ChatAction.tsx | 139 ++++++++++++------ app/src/store/chat.ts | 20 ++- 3 files changed, 110 insertions(+), 54 deletions(-) diff --git a/app/src/components/home/ModelFinder.tsx b/app/src/components/home/ModelFinder.tsx index 69179ad5..31a85ff7 100644 --- a/app/src/components/home/ModelFinder.tsx +++ b/app/src/components/home/ModelFinder.tsx @@ -57,6 +57,7 @@ function ModelFinder(props: ModelSelectorProps) { const list = useSelector(selectModelList); const supportModels = useSelector(selectSupportModels); + const modelList = useSelector(selectModelList); const subscriptionData = useSelector(subscriptionDataSelector); modelEvent.bind((target: string) => { @@ -79,12 +80,12 @@ function ModelFinder(props: ModelSelectorProps) { } as Model); return raw.map((model) => formatModel(subscriptionData, model, level)); - }, [supportModels, subscriptionData, level, student]); + }, [supportModels, subscriptionData, level, student, modelList]); const current = useMemo((): SelectItemProps => { const raw = models.find((item) => item.name === model); return raw || models[0]; - }, [models, model]); + }, [models, model, supportModels, modelList]); return ( { + const content = search.trim(); + if (content === "") return supportModels; + + const raw = splitList(search.toLowerCase(), [" ", ",", ";", "-"]); + return supportModels.filter((model) => { + return raw.every((item) => { + return model.name.toLowerCase().includes(item); + }); + }); + }, [supportModels, search]); + const event = (model: Model) => { selected(model.id); setOpen(false); @@ -125,50 +148,76 @@ export function MarketAction() { {t("market.list")} - - - - {models.map((model, index) => ( -
event(model)} - className={cn( - "flex sm:flex-row flex-col items-center px-4 py-4 sm:py-2 border-b last:border-none select-none cursor-pointer transition-all hover:bg-background-container", - model.id === current && "bg-background-container", - )} + +
+ +
+ setSearch(e.target.value)} + placeholder={t("market.search")} + /> + +
+ + {models.length > 0 ? ( + models.map((model, index) => ( +
event(model)} + className={cn( + "flex sm:flex-row flex-col items-center px-4 py-4 sm:py-2 border-b last:border-none select-none cursor-pointer transition-all hover:bg-background-container", + model.id === current && "bg-background-container", + )} + > + {""} +
+ {model.name} +
+ + {model.id} + + +
+ )) + ) : ( +
- - -
- ))} -
+ {t("empty")} +
+ )} + +
diff --git a/app/src/store/chat.ts b/app/src/store/chat.ts index a58bc049..df42ddf2 100644 --- a/app/src/store/chat.ts +++ b/app/src/store/chat.ts @@ -265,7 +265,18 @@ const chatSlice = createSlice({ if (conversation) conversation.name = name; }, setModel: (state, action) => { - setMemory("model", action.payload as string); + const model = action.payload as string; + if (!model || model === "") return; + if (!inModel(state.support_models, model)) return; + + // if model is not in model list, add it + if (!state.model_list.includes(model)) { + console.log("[model] auto add model to list:", model); + state.model_list.push(model); + setArrayMemory("model_list", state.model_list); + } + + setMemory("model", model as string); state.model = action.payload as string; }, setWeb: (state, action) => { @@ -425,8 +436,6 @@ export function useConversationActions() { const current = useSelector(selectCurrent); const mask = useSelector(selectMaskItem); - const supportModels = useSelector(selectSupportModels); - return { toggle: async (id: number) => { const conversation = conversations[id]; @@ -485,10 +494,7 @@ export function useConversationActions() { } }, selected: (model?: string) => { - if (!model || model === "") return; - if (!supportModels.map((item) => item.id).includes(model)) return; - - dispatch(setModel(model)); + dispatch(setModel(model ?? "")); }, }; }