Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#2312 from Yidadaa/bugfix-0709-2
Browse files Browse the repository at this point in the history
feat: close ChatGPTNextWeb#2303 add custom model name config
  • Loading branch information
Yidadaa authored Jul 9, 2023
2 parents 2f41978 + 6b58679 commit 28b32f3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 33 deletions.
14 changes: 8 additions & 6 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@ export class ChatGPTApi implements LLMApi {
const chatModels = resJson.data?.filter((m) => m.id.startsWith("gpt-"));
console.log("[Models]", chatModels);

return (
chatModels?.map((m) => ({
name: m.id,
available: true,
})) || []
);
if (!chatModels) {
return [];
}

return chatModels.map((m) => ({
name: m.id,
available: true,
}));
}
}
export { OpenaiPath };
8 changes: 6 additions & 2 deletions app/components/model-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ 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 (
<>
Expand All @@ -24,8 +28,8 @@ export function ModelConfigList(props: {
);
}}
>
{config.models.map((v) => (
<option value={v.name} key={v.name} disabled={!v.available}>
{models.map((v, i) => (
<option value={v.name} key={i} disabled={!v.available}>
{v.name}
</option>
))}
Expand Down
63 changes: 39 additions & 24 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ export function Settings() {
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const config = useAppConfig();
const updateConfig = config.update;
const chatStore = useChatStore();

const updateStore = useUpdateStore();
const [checkingUpdate, setCheckingUpdate] = useState(false);
Expand Down Expand Up @@ -579,6 +578,38 @@ export function Settings() {
</ListItem>
</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>
{showAccessCode ? (
<ListItem
Expand Down Expand Up @@ -654,38 +685,22 @@ export function Settings() {
)}
</ListItem>
) : null}
</List>

<List>
<ListItem
title={Locale.Settings.Prompt.Disable.Title}
subTitle={Locale.Settings.Prompt.Disable.SubTitle}
title={Locale.Settings.CustomModel.Title}
subTitle={Locale.Settings.CustomModel.SubTitle}
>
<input
type="checkbox"
checked={config.disablePromptHint}
type="text"
value={config.customModels}
placeholder="model1,model2,model3"
onChange={(e) =>
updateConfig(
(config) =>
(config.disablePromptHint = e.currentTarget.checked),
config.update(
(config) => (config.customModels = e.currentTarget.value),
)
}
></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>

<SyncItems />
Expand Down
4 changes: 4 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ const cn = {
Title: "接口地址",
SubTitle: "除默认地址外,必须包含 http(s)://",
},
CustomModel: {
Title: "自定义模型名",
SubTitle: "增加自定义模型可选项,使用英文逗号隔开",
},
Model: "模型 (model)",
Temperature: {
Title: "随机性 (temperature)",
Expand Down
4 changes: 4 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ const en: LocaleType = {
Title: "Endpoint",
SubTitle: "Custom endpoint must start with http(s)://",
},
CustomModel: {
Title: "Custom Models",
SubTitle: "Add extra model options, separate by comma",
},
Model: "Model",
Temperature: {
Title: "Temperature",
Expand Down
11 changes: 10 additions & 1 deletion app/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DEFAULT_CONFIG = {
dontShowMaskSplashScreen: false, // dont show splash screen when create chat
hideBuiltinMasks: false, // dont add builtin masks

customModels: "",
models: DEFAULT_MODELS as any as LLMModel[],

modelConfig: {
Expand Down Expand Up @@ -117,6 +118,10 @@ export const useAppConfig = create<ChatConfigStore>()(
},

mergeModels(newModels) {
if (!newModels || newModels.length === 0) {
return;
}

const oldModels = get().models;
const modelMap: Record<string, LLMModel> = {};

Expand All @@ -137,7 +142,7 @@ export const useAppConfig = create<ChatConfigStore>()(
}),
{
name: StoreKey.Config,
version: 3.4,
version: 3.5,
migrate(persistedState, version) {
const state = persistedState as ChatConfig;

Expand All @@ -152,6 +157,10 @@ export const useAppConfig = create<ChatConfigStore>()(
state.hideBuiltinMasks = false;
}

if (version < 3.5) {
state.customModels = "claude,claude-100k";
}

return state as any;
},
},
Expand Down

0 comments on commit 28b32f3

Please sign in to comment.