Merge remote-tracking branch 'upstream/main' into dev

# Conflicts:
#	app/constant.ts
This commit is contained in:
sijinhui
2024-02-05 17:20:46 +08:00
5 changed files with 22 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import { ModelConfig, ModelType, useAppConfig } from "./config";
import { createEmptyMask, Mask } from "./mask";
import {
DEFAULT_INPUT_TEMPLATE,
DEFAULT_MODELS,
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
ModelProvider,
@@ -99,10 +100,20 @@ function countMessages(msgs: ChatMessage[]) {
}
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
let cutoff =
const cutoff =
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
// Find the model in the DEFAULT_MODELS array that matches the 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.`,
);
}
// Directly use the providerName from the modelInfo
const serviceProvider = modelInfo.provider.providerName;
const vars = {
ServiceProvider: serviceProvider,
cutoff,
model: modelConfig.model,
time: new Date().toLocaleString(),
@@ -119,7 +130,8 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
}
Object.entries(vars).forEach(([name, value]) => {
output = output.replaceAll(`{{${name}}}`, value);
const regex = new RegExp(`{{${name}}}`, "g");
output = output.replace(regex, value.toString()); // Ensure value is a string
});
return output;