mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-11-27 00:06:09 -05:00
Fixed tons of warnings and clazy findings (#811)
This commit is contained in:
parent
d6a70ddb5f
commit
f3564ac6b9
@ -1013,7 +1013,7 @@ void GPTJ::prompt(const std::string &prompt,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if it partially matches our reverse prompts and if so, cache
|
// Check if it partially matches our reverse prompts and if so, cache
|
||||||
for (auto s : reversePrompts) {
|
for (const auto &s : reversePrompts) {
|
||||||
if (s.compare(0, completed.size(), completed) == 0) {
|
if (s.compare(0, completed.size(), completed) == 0) {
|
||||||
foundPartialReversePrompt = true;
|
foundPartialReversePrompt = true;
|
||||||
cachedResponse = completed;
|
cachedResponse = completed;
|
||||||
|
|||||||
@ -278,7 +278,7 @@ void LLamaModel::prompt(const std::string &prompt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if it partially matches our reverse prompts and if so, cache
|
// Check if it partially matches our reverse prompts and if so, cache
|
||||||
for (auto s : reversePrompts) {
|
for (const auto &s : reversePrompts) {
|
||||||
if (s.compare(0, completed.size(), completed) == 0) {
|
if (s.compare(0, completed.size(), completed) == 0) {
|
||||||
foundPartialReversePrompt = true;
|
foundPartialReversePrompt = true;
|
||||||
cachedResponse = completed;
|
cachedResponse = completed;
|
||||||
|
|||||||
@ -942,7 +942,7 @@ void MPT::prompt(const std::string &prompt,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if it partially matches our reverse prompts and if so, cache
|
// Check if it partially matches our reverse prompts and if so, cache
|
||||||
for (auto s : reversePrompts) {
|
for (const auto &s : reversePrompts) {
|
||||||
if (s.compare(0, completed.size(), completed) == 0) {
|
if (s.compare(0, completed.size(), completed) == 0) {
|
||||||
foundPartialReversePrompt = true;
|
foundPartialReversePrompt = true;
|
||||||
cachedResponse = completed;
|
cachedResponse = completed;
|
||||||
|
|||||||
@ -387,7 +387,7 @@ QList<QString> Chat::modelList() const
|
|||||||
QDir dir(exePath);
|
QDir dir(exePath);
|
||||||
dir.setNameFilters(QStringList() << "ggml-*.bin");
|
dir.setNameFilters(QStringList() << "ggml-*.bin");
|
||||||
QStringList fileNames = dir.entryList();
|
QStringList fileNames = dir.entryList();
|
||||||
for (QString f : fileNames) {
|
for (const QString& f : fileNames) {
|
||||||
QString filePath = exePath + f;
|
QString filePath = exePath + f;
|
||||||
QFileInfo info(filePath);
|
QFileInfo info(filePath);
|
||||||
QString name = info.completeBaseName().remove(0, 5);
|
QString name = info.completeBaseName().remove(0, 5);
|
||||||
@ -404,7 +404,7 @@ QList<QString> Chat::modelList() const
|
|||||||
QDir dir(localPath);
|
QDir dir(localPath);
|
||||||
dir.setNameFilters(QStringList() << "ggml-*.bin" << "chatgpt-*.txt");
|
dir.setNameFilters(QStringList() << "ggml-*.bin" << "chatgpt-*.txt");
|
||||||
QStringList fileNames = dir.entryList();
|
QStringList fileNames = dir.entryList();
|
||||||
for (QString f : fileNames) {
|
for (const QString &f : fileNames) {
|
||||||
QString filePath = localPath + f;
|
QString filePath = localPath + f;
|
||||||
QFileInfo info(filePath);
|
QFileInfo info(filePath);
|
||||||
QString basename = info.completeBaseName();
|
QString basename = info.completeBaseName();
|
||||||
|
|||||||
@ -118,7 +118,7 @@ void ChatsRestoreThread::run()
|
|||||||
QDir dir(settingsPath);
|
QDir dir(settingsPath);
|
||||||
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
|
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
|
||||||
QStringList fileNames = dir.entryList();
|
QStringList fileNames = dir.entryList();
|
||||||
for (QString f : fileNames) {
|
for (const QString &f : fileNames) {
|
||||||
QString filePath = settingsPath + "/" + f;
|
QString filePath = settingsPath + "/" + f;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
bool success = file.open(QIODevice::ReadOnly);
|
bool success = file.open(QIODevice::ReadOnly);
|
||||||
@ -140,7 +140,7 @@ void ChatsRestoreThread::run()
|
|||||||
QDir dir(savePath);
|
QDir dir(savePath);
|
||||||
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
|
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
|
||||||
QStringList fileNames = dir.entryList();
|
QStringList fileNames = dir.entryList();
|
||||||
for (QString f : fileNames) {
|
for (const QString &f : fileNames) {
|
||||||
QString filePath = savePath + "/" + f;
|
QString filePath = savePath + "/" + f;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
bool success = file.open(QIODevice::ReadOnly);
|
bool success = file.open(QIODevice::ReadOnly);
|
||||||
|
|||||||
@ -546,7 +546,6 @@ bool ChatLLM::handleNameResponse(int32_t token, const std::string &response)
|
|||||||
emit generatedNameChanged();
|
emit generatedNameChanged();
|
||||||
QString gen = QString::fromStdString(m_nameResponse).simplified();
|
QString gen = QString::fromStdString(m_nameResponse).simplified();
|
||||||
QStringList words = gen.split(' ', Qt::SkipEmptyParts);
|
QStringList words = gen.split(' ', Qt::SkipEmptyParts);
|
||||||
int wordCount = words.size();
|
|
||||||
return words.size() <= 3;
|
return words.size() <= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -240,7 +240,7 @@ public:
|
|||||||
bool serialize(QDataStream &stream, int version) const
|
bool serialize(QDataStream &stream, int version) const
|
||||||
{
|
{
|
||||||
stream << count();
|
stream << count();
|
||||||
for (auto c : m_chatItems) {
|
for (const auto &c : m_chatItems) {
|
||||||
stream << c.id;
|
stream << c.id;
|
||||||
stream << c.name;
|
stream << c.name;
|
||||||
stream << c.value;
|
stream << c.value;
|
||||||
|
|||||||
@ -125,12 +125,13 @@ bool removeChunksByDocumentId(QSqlQuery &q, int document_id)
|
|||||||
QStringList generateGrams(const QString &input, int N)
|
QStringList generateGrams(const QString &input, int N)
|
||||||
{
|
{
|
||||||
// Remove common English punctuation using QRegularExpression
|
// Remove common English punctuation using QRegularExpression
|
||||||
QRegularExpression punctuation(R"([.,;:!?'"()\-])");
|
static QRegularExpression punctuation(R"([.,;:!?'"()\-])");
|
||||||
QString cleanedInput = input;
|
QString cleanedInput = input;
|
||||||
cleanedInput = cleanedInput.remove(punctuation);
|
cleanedInput = cleanedInput.remove(punctuation);
|
||||||
|
|
||||||
// Split the cleaned input into words using whitespace
|
// Split the cleaned input into words using whitespace
|
||||||
QStringList words = cleanedInput.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
static QRegularExpression spaces("\\s+");
|
||||||
|
QStringList words = cleanedInput.split(spaces, Qt::SkipEmptyParts);
|
||||||
N = qMin(words.size(), N);
|
N = qMin(words.size(), N);
|
||||||
|
|
||||||
// Generate all possible N-grams
|
// Generate all possible N-grams
|
||||||
@ -147,7 +148,8 @@ QStringList generateGrams(const QString &input, int N)
|
|||||||
|
|
||||||
bool selectChunk(QSqlQuery &q, const QList<QString> &collection_names, const QString &chunk_text, int retrievalSize)
|
bool selectChunk(QSqlQuery &q, const QList<QString> &collection_names, const QString &chunk_text, int retrievalSize)
|
||||||
{
|
{
|
||||||
const int N_WORDS = chunk_text.split(QRegularExpression("\\s+")).size();
|
static QRegularExpression spaces("\\s+");
|
||||||
|
const int N_WORDS = chunk_text.split(spaces).size();
|
||||||
for (int N = N_WORDS; N > 2; N--) {
|
for (int N = N_WORDS; N > 2; N--) {
|
||||||
// first try trigrams
|
// first try trigrams
|
||||||
QList<QString> text = generateGrams(chunk_text, N);
|
QList<QString> text = generateGrams(chunk_text, N);
|
||||||
@ -730,7 +732,7 @@ void Database::addCurrentFolders()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : collections)
|
for (const auto &i : collections)
|
||||||
addFolder(i.collection, i.folder_path);
|
addFolder(i.collection, i.folder_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,7 +841,7 @@ void Database::removeFolderInternal(const QString &collection, int folder_id, co
|
|||||||
|
|
||||||
// First remove all upcoming jobs associated with this folder by performing an opt-in filter
|
// First remove all upcoming jobs associated with this folder by performing an opt-in filter
|
||||||
QQueue<DocumentInfo> docsToScan;
|
QQueue<DocumentInfo> docsToScan;
|
||||||
for (DocumentInfo info : m_docsToScan) {
|
for (const DocumentInfo &info : m_docsToScan) {
|
||||||
if (info.folder == folder_id)
|
if (info.folder == folder_id)
|
||||||
continue;
|
continue;
|
||||||
docsToScan.append(info);
|
docsToScan.append(info);
|
||||||
@ -906,9 +908,11 @@ void Database::retrieveFromDB(const QList<QString> &collections, const QString &
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
|
#if defined(DEBUG)
|
||||||
const int rowid = q.value(0).toInt();
|
const int rowid = q.value(0).toInt();
|
||||||
const QString date = QDateTime::fromMSecsSinceEpoch(q.value(1).toLongLong()).toString("yyyy, MMMM dd");
|
#endif
|
||||||
const QString chunk_text = q.value(2).toString();
|
const QString chunk_text = q.value(2).toString();
|
||||||
|
const QString date = QDateTime::fromMSecsSinceEpoch(q.value(1).toLongLong()).toString("yyyy, MMMM dd");
|
||||||
const QString file = q.value(3).toString();
|
const QString file = q.value(3).toString();
|
||||||
const QString title = q.value(4).toString();
|
const QString title = q.value(4).toString();
|
||||||
const QString author = q.value(5).toString();
|
const QString author = q.value(5).toString();
|
||||||
@ -946,7 +950,7 @@ void Database::cleanDB()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : collections) {
|
for (const auto &i : collections) {
|
||||||
// Find the path for the folder
|
// Find the path for the folder
|
||||||
QFileInfo info(i.folder_path);
|
QFileInfo info(i.folder_path);
|
||||||
if (!info.exists() || !info.isReadable()) {
|
if (!info.exists() || !info.isReadable()) {
|
||||||
@ -1017,7 +1021,6 @@ void Database::changeChunkSize(int chunkSize)
|
|||||||
|
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
int document_id = q.value(0).toInt();
|
int document_id = q.value(0).toInt();
|
||||||
QString document_path = q.value(1).toString();
|
|
||||||
// Remove all chunks and documents to change the chunk size
|
// Remove all chunks and documents to change the chunk size
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
if (!removeChunksByDocumentId(query, document_id)) {
|
if (!removeChunksByDocumentId(query, document_id)) {
|
||||||
|
|||||||
@ -74,7 +74,7 @@ QList<ModelInfo> Download::modelList() const
|
|||||||
ModelInfo bestLlamaInfo;
|
ModelInfo bestLlamaInfo;
|
||||||
ModelInfo bestMPTInfo;
|
ModelInfo bestMPTInfo;
|
||||||
QList<ModelInfo> filtered;
|
QList<ModelInfo> filtered;
|
||||||
for (ModelInfo v : values) {
|
for (const ModelInfo &v : values) {
|
||||||
if (v.isDefault)
|
if (v.isDefault)
|
||||||
defaultInfo = v;
|
defaultInfo = v;
|
||||||
if (v.bestGPTJ)
|
if (v.bestGPTJ)
|
||||||
@ -310,7 +310,7 @@ void Download::removeModel(const QString &modelFile)
|
|||||||
void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
||||||
{
|
{
|
||||||
QUrl url = reply->request().url();
|
QUrl url = reply->request().url();
|
||||||
for (auto e : errors)
|
for (const auto &e : errors)
|
||||||
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
|
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,7 +658,6 @@ void Download::handleReadyRead()
|
|||||||
if (!modelReply)
|
if (!modelReply)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString modelFilename = modelReply->url().fileName();
|
|
||||||
QFile *tempFile = m_activeDownloads.value(modelReply);
|
QFile *tempFile = m_activeDownloads.value(modelReply);
|
||||||
QByteArray buffer;
|
QByteArray buffer;
|
||||||
while (!modelReply->atEnd()) {
|
while (!modelReply->atEnd()) {
|
||||||
|
|||||||
@ -153,15 +153,16 @@ void Network::handleJsonUploadFinished()
|
|||||||
sendHealth();
|
sendHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(DEBUG)
|
||||||
QByteArray jsonData = jsonReply->readAll();
|
QByteArray jsonData = jsonReply->readAll();
|
||||||
QJsonParseError err;
|
QJsonParseError err;
|
||||||
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(jsonData, &err);
|
QJsonDocument document = QJsonDocument::fromJson(jsonData, &err);
|
||||||
if (err.error != QJsonParseError::NoError) {
|
if (err.error != QJsonParseError::NoError) {
|
||||||
qDebug() << "ERROR: Couldn't parse: " << jsonData << err.errorString();
|
qDebug() << "ERROR: Couldn't parse: " << jsonData << err.errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
|
||||||
printf("%s\n", qPrintable(document.toJson(QJsonDocument::Indented)));
|
printf("%s\n", qPrintable(document.toJson(QJsonDocument::Indented)));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
@ -172,7 +173,7 @@ void Network::handleJsonUploadFinished()
|
|||||||
void Network::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
void Network::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
||||||
{
|
{
|
||||||
QUrl url = reply->request().url();
|
QUrl url = reply->request().url();
|
||||||
for (auto e : errors)
|
for (const auto &e : errors)
|
||||||
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
|
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +422,7 @@ void Network::sendMixpanelEvent(const QString &ev, const QVector<KeyValue> &valu
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto p : values)
|
for (const auto& p : values)
|
||||||
properties.insert(p.key, p.value);
|
properties.insert(p.key, p.value);
|
||||||
|
|
||||||
QJsonObject event;
|
QJsonObject event;
|
||||||
|
|||||||
@ -192,7 +192,7 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
|
|||||||
prompts.append(promptValue.toString());
|
prompts.append(promptValue.toString());
|
||||||
else {
|
else {
|
||||||
QJsonArray array = promptValue.toArray();
|
QJsonArray array = promptValue.toArray();
|
||||||
for (QJsonValue v : array)
|
for (const QJsonValue &v : array)
|
||||||
prompts.append(v.toString());
|
prompts.append(v.toString());
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
|||||||
@ -24,7 +24,8 @@ QString getSystemTotalRAM()
|
|||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
while (!line.isNull()) {
|
while (!line.isNull()) {
|
||||||
if (line.startsWith("MemTotal")) {
|
if (line.startsWith("MemTotal")) {
|
||||||
QStringList parts = line.split(QRegularExpression("\\s+"));
|
static QRegularExpression spaces("\\s+");
|
||||||
|
QStringList parts = line.split(spaces);
|
||||||
totalRAM = parts[1].toLongLong() * 1024; // Convert from KB to bytes
|
totalRAM = parts[1].toLongLong() * 1024; // Convert from KB to bytes
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user