Skip to content

Commit 9d5801f

Browse files
authoredFeb 7, 2024
fix: avoiding not operation for custom models (ChatGPTNextWeb#4010)
1 parent 462a88a commit 9d5801f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
 

‎app/store/chat.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ function countMessages(msgs: ChatMessage[]) {
9292
}
9393

9494
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
95-
const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
95+
const cutoff =
96+
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
9697
// Find the model in the DEFAULT_MODELS array that matches the modelConfig.model
97-
const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model);
98-
if (!modelInfo) {
99-
throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`);
98+
const modelInfo = DEFAULT_MODELS.find((m) => m.name === modelConfig.model);
99+
100+
var serviceProvider = "OpenAI";
101+
if (modelInfo) {
102+
// TODO: auto detect the providerName from the modelConfig.model
103+
104+
// Directly use the providerName from the modelInfo
105+
serviceProvider = modelInfo.provider.providerName;
100106
}
101-
// Directly use the providerName from the modelInfo
102-
const serviceProvider = modelInfo.provider.providerName;
103107

104108
const vars = {
105109
ServiceProvider: serviceProvider,
@@ -119,7 +123,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
119123
}
120124

121125
Object.entries(vars).forEach(([name, value]) => {
122-
const regex = new RegExp(`{{${name}}}`, 'g');
126+
const regex = new RegExp(`{{${name}}}`, "g");
123127
output = output.replace(regex, value.toString()); // Ensure value is a string
124128
});
125129

0 commit comments

Comments
 (0)
Please sign in to comment.