mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 06:46:56 +08:00
feat: Support a way to define default model by adding DEFAULT_MODEL env.
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { LLMModel } from "../client/api";
|
||||
|
||||
const customProvider = (modelName: string) => ({
|
||||
id: modelName,
|
||||
providerName: "",
|
||||
providerType: "custom",
|
||||
});
|
||||
|
||||
export function collectModelTable(
|
||||
models: readonly LLMModel[],
|
||||
customModels: string,
|
||||
@@ -11,6 +17,7 @@ export function collectModelTable(
|
||||
name: string;
|
||||
displayName: string;
|
||||
provider?: LLMModel["provider"]; // Marked as optional
|
||||
isDefault?: boolean;
|
||||
}
|
||||
> = {};
|
||||
|
||||
@@ -22,12 +29,6 @@ export function collectModelTable(
|
||||
};
|
||||
});
|
||||
|
||||
const customProvider = (modelName: string) => ({
|
||||
id: modelName,
|
||||
providerName: "",
|
||||
providerType: "custom",
|
||||
});
|
||||
|
||||
// server custom models
|
||||
customModels
|
||||
.split(",")
|
||||
@@ -52,6 +53,27 @@ export function collectModelTable(
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return modelTable;
|
||||
}
|
||||
|
||||
export function collectModelTableWithDefaultModel(
|
||||
models: readonly LLMModel[],
|
||||
customModels: string,
|
||||
defaultModel: string,
|
||||
) {
|
||||
let modelTable = collectModelTable(models, customModels);
|
||||
if (defaultModel && defaultModel !== "") {
|
||||
delete modelTable[defaultModel];
|
||||
modelTable[defaultModel] = {
|
||||
name: defaultModel,
|
||||
displayName: defaultModel,
|
||||
available: true,
|
||||
provider:
|
||||
modelTable[defaultModel]?.provider ?? customProvider(defaultModel),
|
||||
isDefault: true,
|
||||
};
|
||||
}
|
||||
return modelTable;
|
||||
}
|
||||
|
||||
@@ -67,3 +89,17 @@ export function collectModels(
|
||||
|
||||
return allModels;
|
||||
}
|
||||
|
||||
export function collectModelsWithDefaultModel(
|
||||
models: readonly LLMModel[],
|
||||
customModels: string,
|
||||
defaultModel: string,
|
||||
) {
|
||||
const modelTable = collectModelTableWithDefaultModel(
|
||||
models,
|
||||
customModels,
|
||||
defaultModel,
|
||||
);
|
||||
const allModels = Object.values(modelTable);
|
||||
return allModels;
|
||||
}
|
||||
|
Reference in New Issue
Block a user