Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#2317 from Yidadaa/bugfix-0709-2
Browse files Browse the repository at this point in the history
fix: ChatGPTNextWeb#2303 should be able to select custom models
  • Loading branch information
Yidadaa authored Jul 9, 2023
2 parents 15862d3 + a913d97 commit e668e17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
8 changes: 6 additions & 2 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 1 addition & 5 deletions app/components/model-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -28,7 +24,7 @@ export function ModelConfigList(props: {
);
}}
>
{models.map((v, i) => (
{config.allModels().map((v, i) => (
<option value={v.name} key={i} disabled={!v.available}>
{v.name}
</option>
Expand Down
4 changes: 3 additions & 1 deletion app/components/ui-lib.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@

&-content {
.list {
overflow: hidden;
max-height: 90vh;
overflow-x: hidden;
overflow-y: auto;

.list-item {
cursor: pointer;
Expand Down
20 changes: 12 additions & 8 deletions app/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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);
Expand Down Expand Up @@ -139,6 +133,16 @@ export const useAppConfig = create<ChatConfigStore>()(
models: Object.values(modelMap),
}));
},

allModels() {
const customModels = get()
.customModels.split(",")
.filter((v) => !!v && v.length > 0)
.map((m) => ({ name: m, available: true }));

const models = get().models.concat(customModels);
return models;
},
}),
{
name: StoreKey.Config,
Expand Down

0 comments on commit e668e17

Please sign in to comment.