mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-22 21:48:23 +00:00
Clean up settings properly for removed models and also when user manually deletes.
Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
parent
0cc5a80656
commit
f36a2874eb
@ -203,6 +203,7 @@ void Download::removeModel(const QString &modelFile)
|
|||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
|
const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);
|
||||||
|
MySettings::globalInstance()->eraseModel(info);
|
||||||
shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == "" /*indicates sideloaded*/);
|
shouldRemoveInstalled = info.installed && !info.isClone() && (info.isDiscovered() || info.description() == "" /*indicates sideloaded*/);
|
||||||
if (shouldRemoveInstalled)
|
if (shouldRemoveInstalled)
|
||||||
ModelList::globalInstance()->removeInstalled(info);
|
ModelList::globalInstance()->removeInstalled(info);
|
||||||
|
@ -1137,27 +1137,18 @@ QString ModelList::uniqueModelName(const ModelInfo &model) const
|
|||||||
return baseName;
|
return baseName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ModelList::modelDirPath(const QString &modelName, bool isOnline)
|
bool ModelList::modelExists(const QString &modelFilename) const
|
||||||
{
|
{
|
||||||
QVector<QString> possibleFilePaths;
|
QString appPath = QCoreApplication::applicationDirPath() + modelFilename;
|
||||||
if (isOnline)
|
QFileInfo infoAppPath(appPath);
|
||||||
possibleFilePaths << "/" + modelName + ".txt";
|
if (infoAppPath.exists())
|
||||||
else {
|
return true;
|
||||||
possibleFilePaths << "/ggml-" + modelName + ".bin";
|
|
||||||
possibleFilePaths << "/" + modelName + ".bin";
|
|
||||||
}
|
|
||||||
for (const QString &modelFilename : possibleFilePaths) {
|
|
||||||
QString appPath = QCoreApplication::applicationDirPath() + modelFilename;
|
|
||||||
QFileInfo infoAppPath(appPath);
|
|
||||||
if (infoAppPath.exists())
|
|
||||||
return QCoreApplication::applicationDirPath();
|
|
||||||
|
|
||||||
QString downloadPath = MySettings::globalInstance()->modelPath() + modelFilename;
|
QString downloadPath = MySettings::globalInstance()->modelPath() + modelFilename;
|
||||||
QFileInfo infoLocalPath(downloadPath);
|
QFileInfo infoLocalPath(downloadPath);
|
||||||
if (infoLocalPath.exists())
|
if (infoLocalPath.exists())
|
||||||
return MySettings::globalInstance()->modelPath();
|
return true;
|
||||||
}
|
return false;
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelList::updateModelsFromDirectory()
|
void ModelList::updateModelsFromDirectory()
|
||||||
@ -1569,6 +1560,14 @@ void ModelList::updateModelsFromSettings()
|
|||||||
if (contains(id))
|
if (contains(id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// If we can't find the corresponding file, then delete it from settings as this reflects a
|
||||||
|
// stale model. The file could have been deleted manually by the user for instance.
|
||||||
|
if (!settings.contains(g + "/filename") || !modelExists(settings.value(g + "/filename").toString())) {
|
||||||
|
settings.remove(g);
|
||||||
|
settings.sync();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
addModel(id);
|
addModel(id);
|
||||||
|
|
||||||
QVector<QPair<int, QVariant>> data;
|
QVector<QPair<int, QVariant>> data;
|
||||||
|
@ -462,7 +462,7 @@ private Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
void removeInternal(const ModelInfo &model);
|
void removeInternal(const ModelInfo &model);
|
||||||
void clearDiscoveredModels();
|
void clearDiscoveredModels();
|
||||||
QString modelDirPath(const QString &modelName, bool isOnline);
|
bool modelExists(const QString &fileName) const;
|
||||||
int indexForModel(ModelInfo *model);
|
int indexForModel(ModelInfo *model);
|
||||||
QVariant dataInternal(const ModelInfo *info, int role) const;
|
QVariant dataInternal(const ModelInfo *info, int role) const;
|
||||||
static bool lessThan(const ModelInfo* a, const ModelInfo* b, DiscoverSort s, int d);
|
static bool lessThan(const ModelInfo* a, const ModelInfo* b, DiscoverSort s, int d);
|
||||||
|
Loading…
Reference in New Issue
Block a user