modellist: fix cloning of chat template and system message (#3262)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-12-13 12:22:32 -05:00 committed by GitHub
parent f67b370f5a
commit b7df4ebbcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View File

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Fix API server ignoring assistant messages in history after v3.5.0 ([#3256](https://github.com/nomic-ai/gpt4all/pull/3256))
- Fix API server replying with incorrect token counts and stop reason after v3.5.0 ([#3256](https://github.com/nomic-ai/gpt4all/pull/3256))
- Fix API server remembering previous, unrelated conversations after v3.5.0 ([#3256](https://github.com/nomic-ai/gpt4all/pull/3256))
- Fix mishandling of default chat template and system message of cloned models in v3.5.0 ([#3262](https://github.com/nomic-ai/gpt4all/pull/3262))
## [3.5.1] - 2024-12-10

View File

@ -1141,18 +1141,20 @@ bool ModelList::isUniqueName(const QString &name) const
QString ModelList::clone(const ModelInfo &model)
{
auto *mySettings = MySettings::globalInstance();
const QString id = Network::globalInstance()->generateUniqueId();
addModel(id);
QString chatTemplate, systemMessage;
QString tmplSetting, sysmsgSetting;
if (auto tmpl = model.chatTemplate().asModern()) {
chatTemplate = *tmpl;
tmplSetting = *tmpl;
} else {
qWarning("ModelList Warning: attempted to clone model with legacy chat template");
return {};
}
if (auto msg = model.systemMessage().asModern()) {
systemMessage = *msg;
sysmsgSetting = *msg;
} else {
qWarning("ModelList Warning: attempted to clone model with legacy system message");
return {};
@ -1177,12 +1179,22 @@ QString ModelList::clone(const ModelInfo &model)
{ ModelList::GpuLayersRole, model.gpuLayers() },
{ ModelList::RepeatPenaltyRole, model.repeatPenalty() },
{ ModelList::RepeatPenaltyTokensRole, model.repeatPenaltyTokens() },
{ ModelList::ChatTemplateRole, chatTemplate },
{ ModelList::SystemMessageRole, systemMessage },
{ ModelList::SystemMessageRole, model.m_systemMessage },
{ ModelList::ChatNamePromptRole, model.chatNamePrompt() },
{ ModelList::SuggestedFollowUpPromptRole, model.suggestedFollowUpPrompt() },
};
if (auto tmpl = model.m_chatTemplate)
data.emplace_back(ModelList::ChatTemplateRole, *tmpl); // copy default chat template, if known
updateData(id, data);
// Ensure setting overrides are copied in case the base model overrides change.
// This is necessary because setting these roles on ModelInfo above does not write to settings.
auto cloneInfo = modelInfo(id);
if (mySettings->isModelChatTemplateSet (model))
mySettings->setModelChatTemplate (cloneInfo, tmplSetting );
if (mySettings->isModelSystemMessageSet(model))
mySettings->setModelSystemMessage(cloneInfo, sysmsgSetting);
return id;
}