Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate three word chat names #3172

Draft
wants to merge 2 commits into
base: remove-binarystate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions gpt4all-chat/src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions gpt4all-chat/src/chatllm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QMutex>
#include <QMutexLocker> // IWYU pragma: keep
#include <QSet>
#include <QTextStream>
#include <QUrl>
#include <QWaitCondition>
#include <Qt>
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gpt4all-chat/src/modellist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down