From 09b05cde7fef0ceea087511f1d498b3975782941 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Jul 2023 21:56:49 +0800 Subject: [PATCH 1/3] fix: #2303 should select custom models --- app/components/chat.tsx | 8 ++++++-- app/components/model-config.tsx | 6 +----- app/store/config.ts | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 1e1b5dbe..b6380add 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -414,8 +414,12 @@ export function ChatActions(props: { // switch model const currentModel = chatStore.currentSession().mask.modelConfig.model; const models = useMemo( - () => config.models.filter((m) => m.available).map((m) => m.name), - [config.models], + () => + config + .allModels() + .filter((m) => m.available) + .map((m) => m.name), + [config], ); const [showModelSelector, setShowModelSelector] = useState(false); diff --git a/app/components/model-config.tsx b/app/components/model-config.tsx index 8e353401..9603eea0 100644 --- a/app/components/model-config.tsx +++ b/app/components/model-config.tsx @@ -9,10 +9,6 @@ export function ModelConfigList(props: { updateConfig: (updater: (config: ModelConfig) => void) => void; }) { const config = useAppConfig(); - const customModels = config.customModels - .split(",") - .map((m) => ({ name: m, available: true })); - const models = config.models.concat(customModels); return ( <> @@ -28,7 +24,7 @@ export function ModelConfigList(props: { ); }} > - {models.map((v, i) => ( + {config.allModels().map((v, i) => ( diff --git a/app/store/config.ts b/app/store/config.ts index ff346871..84905b6e 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -57,6 +57,7 @@ export type ChatConfigStore = ChatConfig & { reset: () => void; update: (updater: (config: ChatConfig) => void) => void; mergeModels: (newModels: LLMModel[]) => void; + allModels: () => LLMModel[]; }; export type ModelConfig = ChatConfig["modelConfig"]; @@ -74,16 +75,9 @@ export function limitNumber( return Math.min(max, Math.max(min, x)); } -export function limitModel(name: string) { - const allModels = useAppConfig.getState().models; - return allModels.some((m) => m.name === name && m.available) - ? name - : "gpt-3.5-turbo"; -} - export const ModalConfigValidator = { model(x: string) { - return limitModel(x) as ModelType; + return x as ModelType; }, max_tokens(x: number) { return limitNumber(x, 0, 32000, 2000); @@ -139,6 +133,15 @@ export const useAppConfig = create()( models: Object.values(modelMap), })); }, + + allModels() { + const customModels = get() + .customModels.split(",") + .map((m) => ({ name: m, available: true })); + + const models = get().models.concat(customModels); + return models; + }, }), { name: StoreKey.Config, From 48a6cdd50a0c2739989ffeef94c9584650187ad7 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Jul 2023 22:01:04 +0800 Subject: [PATCH 2/3] feat: improve model selector ui --- app/components/ui-lib.module.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 67faabbe..7742e9d0 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -286,7 +286,9 @@ &-content { .list { - overflow: hidden; + max-height: 90vh; + overflow-x: hidden; + overflow-y: auto; .list-item { cursor: pointer; From a913d9728ce9cc119ca934e325cde8fc00b59b54 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Jul 2023 22:06:41 +0800 Subject: [PATCH 3/3] fixup --- app/store/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/store/config.ts b/app/store/config.ts index 84905b6e..a4ac45e7 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -137,6 +137,7 @@ export const useAppConfig = create()( allModels() { const customModels = get() .customModels.split(",") + .filter((v) => !!v && v.length > 0) .map((m) => ({ name: m, available: true })); const models = get().models.concat(customModels);