Skip to content

Commit

Permalink
fix chat name generation
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Van Bortel <[email protected]>
  • Loading branch information
cebtenzzre committed Nov 7, 2024
1 parent 6895a48 commit bc256ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit bc256ff

Please sign in to comment.