mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	fix: #2303 should select custom models
This commit is contained in:
		@@ -414,8 +414,12 @@ export function ChatActions(props: {
 | 
				
			|||||||
  // switch model
 | 
					  // switch model
 | 
				
			||||||
  const currentModel = chatStore.currentSession().mask.modelConfig.model;
 | 
					  const currentModel = chatStore.currentSession().mask.modelConfig.model;
 | 
				
			||||||
  const models = useMemo(
 | 
					  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);
 | 
					  const [showModelSelector, setShowModelSelector] = useState(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,10 +9,6 @@ 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 (
 | 
				
			||||||
    <>
 | 
					    <>
 | 
				
			||||||
@@ -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}>
 | 
					            <option value={v.name} key={i} disabled={!v.available}>
 | 
				
			||||||
              {v.name}
 | 
					              {v.name}
 | 
				
			||||||
            </option>
 | 
					            </option>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,6 +57,7 @@ export type ChatConfigStore = ChatConfig & {
 | 
				
			|||||||
  reset: () => void;
 | 
					  reset: () => void;
 | 
				
			||||||
  update: (updater: (config: ChatConfig) => void) => void;
 | 
					  update: (updater: (config: ChatConfig) => void) => void;
 | 
				
			||||||
  mergeModels: (newModels: LLMModel[]) => void;
 | 
					  mergeModels: (newModels: LLMModel[]) => void;
 | 
				
			||||||
 | 
					  allModels: () => LLMModel[];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ModelConfig = ChatConfig["modelConfig"];
 | 
					export type ModelConfig = ChatConfig["modelConfig"];
 | 
				
			||||||
@@ -74,16 +75,9 @@ export function limitNumber(
 | 
				
			|||||||
  return Math.min(max, Math.max(min, x));
 | 
					  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 = {
 | 
					export const ModalConfigValidator = {
 | 
				
			||||||
  model(x: string) {
 | 
					  model(x: string) {
 | 
				
			||||||
    return limitModel(x) as ModelType;
 | 
					    return x as ModelType;
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  max_tokens(x: number) {
 | 
					  max_tokens(x: number) {
 | 
				
			||||||
    return limitNumber(x, 0, 32000, 2000);
 | 
					    return limitNumber(x, 0, 32000, 2000);
 | 
				
			||||||
@@ -139,6 +133,15 @@ export const useAppConfig = create<ChatConfigStore>()(
 | 
				
			|||||||
          models: Object.values(modelMap),
 | 
					          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,
 | 
					      name: StoreKey.Config,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user