diff --git a/gpt4all-chat/src/chat.cpp b/gpt4all-chat/src/chat.cpp index feb3c61d3d4b..aca9574b51a0 100644 --- a/gpt4all-chat/src/chat.cpp +++ b/gpt4all-chat/src/chat.cpp @@ -308,11 +308,8 @@ void Chat::trySwitchContextOfLoadedModel() void Chat::generatedNameChanged(const QString &name) { - // Only use the first three words maximum and remove newlines and extra spaces - m_generatedName = name.simplified(); - QStringList words = m_generatedName.split(' ', Qt::SkipEmptyParts); - int wordCount = qMin(7, words.size()); - m_name = words.mid(0, wordCount).join(' '); + m_generatedName = name; + m_name = name; emit nameChanged(); m_needsSave = true; } diff --git a/gpt4all-chat/src/chatllm.cpp b/gpt4all-chat/src/chatllm.cpp index 0a5aebbc6e78..ffd6dfc7680f 100644 --- a/gpt4all-chat/src/chatllm.cpp +++ b/gpt4all-chat/src/chatllm.cpp @@ -27,6 +27,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include #include @@ -973,13 +974,24 @@ void ChatLLM::generateName() QByteArray response; // raw UTF-8 + static constexpr qsizetype MAX_WORDS = 3; + auto handleResponse = [this, &response](LLModel::Token token, std::string_view piece) -> bool { Q_UNUSED(token) response.append(piece.data(), piece.size()); - QStringList words = QString::fromUtf8(response).simplified().split(u' ', Qt::SkipEmptyParts); + + QTextStream stream(response); + stream.setAutoDetectUnicode(false); + QStringList words; + while (!stream.atEnd() && words.size() < MAX_WORDS) { + QString word; + stream >> word; + words << word; + } + emit generatedNameChanged(words.join(u' ')); - return words.size() <= 3; + return words.size() < MAX_WORDS || stream.atEnd(); }; try { diff --git a/gpt4all-chat/src/modellist.h b/gpt4all-chat/src/modellist.h index 259b45c76794..aac6e23e094c 100644 --- a/gpt4all-chat/src/modellist.h +++ b/gpt4all-chat/src/modellist.h @@ -218,7 +218,7 @@ struct ModelInfo { int m_repeatPenaltyTokens = 64; QString m_promptTemplate; QString m_systemPrompt; - QString m_chatNamePrompt = "Describe the above conversation in seven words or less."; + QString m_chatNamePrompt = "Describe the above conversation in three words or less."; QString m_suggestedFollowUpPrompt = "Suggest three very short factual follow-up questions that have not been answered yet or cannot be found inspired by the previous conversation and excerpts."; friend class MySettings; };