feat: close #2303 add custom model name config

This commit is contained in:
Yidadaa 2023-07-09 18:15:52 +08:00
parent 28c457730a
commit 98ac7ee277
5 changed files with 59 additions and 27 deletions

View File

@ -9,6 +9,10 @@ export function ModelConfigList(props: {
updateConfig: (updater: (config: ModelConfig) => void) => void; updateConfig: (updater: (config: ModelConfig) => void) => void;
}) { }) {
const config = useAppConfig(); const config = useAppConfig();
const customModels = config.customModels
.split(",")
.map((m) => ({ name: m, available: true }));
const models = config.models.concat(customModels);
return ( return (
<> <>
@ -24,8 +28,8 @@ export function ModelConfigList(props: {
); );
}} }}
> >
{config.models.map((v) => ( {models.map((v, i) => (
<option value={v.name} key={v.name} disabled={!v.available}> <option value={v.name} key={i} disabled={!v.available}>
{v.name} {v.name}
</option> </option>
))} ))}

View File

@ -315,7 +315,6 @@ export function Settings() {
const [showEmojiPicker, setShowEmojiPicker] = useState(false); const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const config = useAppConfig(); const config = useAppConfig();
const updateConfig = config.update; const updateConfig = config.update;
const chatStore = useChatStore();
const updateStore = useUpdateStore(); const updateStore = useUpdateStore();
const [checkingUpdate, setCheckingUpdate] = useState(false); const [checkingUpdate, setCheckingUpdate] = useState(false);
@ -579,6 +578,38 @@ export function Settings() {
</ListItem> </ListItem>
</List> </List>
<List>
<ListItem
title={Locale.Settings.Prompt.Disable.Title}
subTitle={Locale.Settings.Prompt.Disable.SubTitle}
>
<input
type="checkbox"
checked={config.disablePromptHint}
onChange={(e) =>
updateConfig(
(config) =>
(config.disablePromptHint = e.currentTarget.checked),
)
}
></input>
</ListItem>
<ListItem
title={Locale.Settings.Prompt.List}
subTitle={Locale.Settings.Prompt.ListCount(
builtinCount,
customCount,
)}
>
<IconButton
icon={<EditIcon />}
text={Locale.Settings.Prompt.Edit}
onClick={() => setShowPromptModal(true)}
/>
</ListItem>
</List>
<List> <List>
{showAccessCode ? ( {showAccessCode ? (
<ListItem <ListItem
@ -654,38 +685,22 @@ export function Settings() {
)} )}
</ListItem> </ListItem>
) : null} ) : null}
</List>
<List>
<ListItem <ListItem
title={Locale.Settings.Prompt.Disable.Title} title={Locale.Settings.CustomModel.Title}
subTitle={Locale.Settings.Prompt.Disable.SubTitle} subTitle={Locale.Settings.CustomModel.SubTitle}
> >
<input <input
type="checkbox" type="text"
checked={config.disablePromptHint} value={config.customModels}
placeholder="model1,model2,model3"
onChange={(e) => onChange={(e) =>
updateConfig( config.update(
(config) => (config) => (config.customModels = e.currentTarget.value),
(config.disablePromptHint = e.currentTarget.checked),
) )
} }
></input> ></input>
</ListItem> </ListItem>
<ListItem
title={Locale.Settings.Prompt.List}
subTitle={Locale.Settings.Prompt.ListCount(
builtinCount,
customCount,
)}
>
<IconButton
icon={<EditIcon />}
text={Locale.Settings.Prompt.Edit}
onClick={() => setShowPromptModal(true)}
/>
</ListItem>
</List> </List>
<SyncItems /> <SyncItems />

View File

@ -220,6 +220,10 @@ const cn = {
Title: "接口地址", Title: "接口地址",
SubTitle: "除默认地址外,必须包含 http(s)://", SubTitle: "除默认地址外,必须包含 http(s)://",
}, },
CustomModel: {
Title: "自定义模型名",
SubTitle: "增加自定义模型可选项,使用英文逗号隔开",
},
Model: "模型 (model)", Model: "模型 (model)",
Temperature: { Temperature: {
Title: "随机性 (temperature)", Title: "随机性 (temperature)",

View File

@ -222,6 +222,10 @@ const en: LocaleType = {
Title: "Endpoint", Title: "Endpoint",
SubTitle: "Custom endpoint must start with http(s)://", SubTitle: "Custom endpoint must start with http(s)://",
}, },
CustomModel: {
Title: "Custom Models",
SubTitle: "Add extra model options, separate by comma",
},
Model: "Model", Model: "Model",
Temperature: { Temperature: {
Title: "Temperature", Title: "Temperature",

View File

@ -34,6 +34,7 @@ export const DEFAULT_CONFIG = {
dontShowMaskSplashScreen: false, // dont show splash screen when create chat dontShowMaskSplashScreen: false, // dont show splash screen when create chat
hideBuiltinMasks: false, // dont add builtin masks hideBuiltinMasks: false, // dont add builtin masks
customModels: "",
models: DEFAULT_MODELS as any as LLMModel[], models: DEFAULT_MODELS as any as LLMModel[],
modelConfig: { modelConfig: {
@ -141,7 +142,7 @@ export const useAppConfig = create<ChatConfigStore>()(
}), }),
{ {
name: StoreKey.Config, name: StoreKey.Config,
version: 3.4, version: 3.5,
migrate(persistedState, version) { migrate(persistedState, version) {
const state = persistedState as ChatConfig; const state = persistedState as ChatConfig;
@ -156,6 +157,10 @@ export const useAppConfig = create<ChatConfigStore>()(
state.hideBuiltinMasks = false; state.hideBuiltinMasks = false;
} }
if (version < 3.5) {
state.customModels = "claude,claude-100k";
}
return state as any; return state as any;
}, },
}, },