Fixed tons of warnings and clazy findings (#811)

pull/913/head
niansa/tuxifan 1 year ago committed by GitHub
parent 1832a887b5
commit 8203d65445

@ -1013,7 +1013,7 @@ void GPTJ::prompt(const std::string &prompt,
return;
// 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) {
foundPartialReversePrompt = true;
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
for (auto s : reversePrompts) {
for (const auto &s : reversePrompts) {
if (s.compare(0, completed.size(), completed) == 0) {
foundPartialReversePrompt = true;
cachedResponse = completed;

@ -942,7 +942,7 @@ void MPT::prompt(const std::string &prompt,
return;
// 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) {
foundPartialReversePrompt = true;
cachedResponse = completed;

@ -387,7 +387,7 @@ QList<QString> Chat::modelList() const
QDir dir(exePath);
dir.setNameFilters(QStringList() << "ggml-*.bin");
QStringList fileNames = dir.entryList();
for (QString f : fileNames) {
for (const QString& f : fileNames) {
QString filePath = exePath + f;
QFileInfo info(filePath);
QString name = info.completeBaseName().remove(0, 5);
@ -404,7 +404,7 @@ QList<QString> Chat::modelList() const
QDir dir(localPath);
dir.setNameFilters(QStringList() << "ggml-*.bin" << "chatgpt-*.txt");
QStringList fileNames = dir.entryList();
for (QString f : fileNames) {
for (const QString &f : fileNames) {
QString filePath = localPath + f;
QFileInfo info(filePath);
QString basename = info.completeBaseName();

@ -118,7 +118,7 @@ void ChatsRestoreThread::run()
QDir dir(settingsPath);
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
QStringList fileNames = dir.entryList();
for (QString f : fileNames) {
for (const QString &f : fileNames) {
QString filePath = settingsPath + "/" + f;
QFile file(filePath);
bool success = file.open(QIODevice::ReadOnly);
@ -140,7 +140,7 @@ void ChatsRestoreThread::run()
QDir dir(savePath);
dir.setNameFilters(QStringList() << "gpt4all-*.chat");
QStringList fileNames = dir.entryList();
for (QString f : fileNames) {
for (const QString &f : fileNames) {
QString filePath = savePath + "/" + f;
QFile file(filePath);
bool success = file.open(QIODevice::ReadOnly);

@ -546,7 +546,6 @@ bool ChatLLM::handleNameResponse(int32_t token, const std::string &response)
emit generatedNameChanged();
QString gen = QString::fromStdString(m_nameResponse).simplified();
QStringList words = gen.split(' ', Qt::SkipEmptyParts);
int wordCount = words.size();
return words.size() <= 3;
}

@ -240,7 +240,7 @@ public:
bool serialize(QDataStream &stream, int version) const
{
stream << count();
for (auto c : m_chatItems) {
for (const auto &c : m_chatItems) {
stream << c.id;
stream << c.name;
stream << c.value;

@ -125,12 +125,13 @@ bool removeChunksByDocumentId(QSqlQuery &q, int document_id)
QStringList generateGrams(const QString &input, int N)
{
// Remove common English punctuation using QRegularExpression
QRegularExpression punctuation(R"([.,;:!?'"()\-])");
static QRegularExpression punctuation(R"([.,;:!?'"()\-])");
QString cleanedInput = input;
cleanedInput = cleanedInput.remove(punctuation);
// 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);
// 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)
{
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--) {
// first try trigrams
QList<QString> text = generateGrams(chunk_text, N);
@ -730,7 +732,7 @@ void Database::addCurrentFolders()
return;
}
for (auto i : collections)
for (const auto &i : collections)
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
QQueue<DocumentInfo> docsToScan;
for (DocumentInfo info : m_docsToScan) {
for (const DocumentInfo &info : m_docsToScan) {
if (info.folder == folder_id)
continue;
docsToScan.append(info);
@ -906,9 +908,11 @@ void Database::retrieveFromDB(const QList<QString> &collections, const QString &
}
while (q.next()) {
#if defined(DEBUG)
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 date = QDateTime::fromMSecsSinceEpoch(q.value(1).toLongLong()).toString("yyyy, MMMM dd");
const QString file = q.value(3).toString();
const QString title = q.value(4).toString();
const QString author = q.value(5).toString();
@ -946,7 +950,7 @@ void Database::cleanDB()
return;
}
for (auto i : collections) {
for (const auto &i : collections) {
// Find the path for the folder
QFileInfo info(i.folder_path);
if (!info.exists() || !info.isReadable()) {
@ -1017,7 +1021,6 @@ void Database::changeChunkSize(int chunkSize)
while (q.next()) {
int document_id = q.value(0).toInt();
QString document_path = q.value(1).toString();
// Remove all chunks and documents to change the chunk size
QSqlQuery query;
if (!removeChunksByDocumentId(query, document_id)) {

@ -74,7 +74,7 @@ QList<ModelInfo> Download::modelList() const
ModelInfo bestLlamaInfo;
ModelInfo bestMPTInfo;
QList<ModelInfo> filtered;
for (ModelInfo v : values) {
for (const ModelInfo &v : values) {
if (v.isDefault)
defaultInfo = v;
if (v.bestGPTJ)
@ -310,7 +310,7 @@ void Download::removeModel(const QString &modelFile)
void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
QUrl url = reply->request().url();
for (auto e : errors)
for (const auto &e : errors)
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
}
@ -658,7 +658,6 @@ void Download::handleReadyRead()
if (!modelReply)
return;
QString modelFilename = modelReply->url().fileName();
QFile *tempFile = m_activeDownloads.value(modelReply);
QByteArray buffer;
while (!modelReply->atEnd()) {

@ -153,15 +153,16 @@ void Network::handleJsonUploadFinished()
sendHealth();
}
#if defined(DEBUG)
QByteArray jsonData = jsonReply->readAll();
QJsonParseError err;
QJsonDocument document = QJsonDocument::fromJson(jsonData, &err);
if (err.error != QJsonParseError::NoError) {
qDebug() << "ERROR: Couldn't parse: " << jsonData << err.errorString();
return;
}
#if defined(DEBUG)
printf("%s\n", qPrintable(document.toJson(QJsonDocument::Indented)));
fflush(stdout);
#endif
@ -172,7 +173,7 @@ void Network::handleJsonUploadFinished()
void Network::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
QUrl url = reply->request().url();
for (auto e : errors)
for (const auto &e : errors)
qWarning() << "ERROR: Received ssl error:" << e.errorString() << "for" << url;
}
@ -421,7 +422,7 @@ void Network::sendMixpanelEvent(const QString &ev, const QVector<KeyValue> &valu
#endif
}
for (auto p : values)
for (const auto& p : values)
properties.insert(p.key, p.value);
QJsonObject event;

@ -192,7 +192,7 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
prompts.append(promptValue.toString());
else {
QJsonArray array = promptValue.toArray();
for (QJsonValue v : array)
for (const QJsonValue &v : array)
prompts.append(v.toString());
}
} else

@ -24,7 +24,8 @@ QString getSystemTotalRAM()
QString line = in.readLine();
while (!line.isNull()) {
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
break;
}

Loading…
Cancel
Save