forked from XiaoMo/ChatGPT-Next-Web
fix: avoiding not operation for custom models (#4010)
This commit is contained in:
parent
462a88ae82
commit
9d5801fb5f
@ -92,14 +92,18 @@ function countMessages(msgs: ChatMessage[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
||||||
const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
|
const cutoff =
|
||||||
|
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
|
||||||
// Find the model in the DEFAULT_MODELS array that matches the modelConfig.model
|
// Find the model in the DEFAULT_MODELS array that matches the modelConfig.model
|
||||||
const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model);
|
const modelInfo = DEFAULT_MODELS.find((m) => m.name === modelConfig.model);
|
||||||
if (!modelInfo) {
|
|
||||||
throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`);
|
var serviceProvider = "OpenAI";
|
||||||
|
if (modelInfo) {
|
||||||
|
// TODO: auto detect the providerName from the modelConfig.model
|
||||||
|
|
||||||
|
// Directly use the providerName from the modelInfo
|
||||||
|
serviceProvider = modelInfo.provider.providerName;
|
||||||
}
|
}
|
||||||
// Directly use the providerName from the modelInfo
|
|
||||||
const serviceProvider = modelInfo.provider.providerName;
|
|
||||||
|
|
||||||
const vars = {
|
const vars = {
|
||||||
ServiceProvider: serviceProvider,
|
ServiceProvider: serviceProvider,
|
||||||
@ -119,7 +123,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.entries(vars).forEach(([name, value]) => {
|
Object.entries(vars).forEach(([name, value]) => {
|
||||||
const regex = new RegExp(`{{${name}}}`, 'g');
|
const regex = new RegExp(`{{${name}}}`, "g");
|
||||||
output = output.replace(regex, value.toString()); // Ensure value is a string
|
output = output.replace(regex, value.toString()); // Ensure value is a string
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user