1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * SPDX-FileCopyrightText: 2026 by Srirupa Datta <srirupa dot sps at gmail dot com>
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "searchnlmodelmanager.h"

// Qt includes

#include <QFileInfo>

// KDE includes

#include <klocalizedstring.h>

// Local includes

#include "digikam_debug.h"
#include "dnnmodelmanager.h"
#include "dnnmodelbase.h"
#include "dnnmodeldefinitions.h"

namespace Digikam
{

namespace
{
    // DNNModelManager::getModel() lower-cases the lookup internally.
    const QLatin1String s_nlModelName("Qwen2.5-1.5B-Instruct");
}

SearchNlModelManager::SearchNlModelManager(QObject* const parent)
    : QObject(parent)
{
}

SearchNlModelManager::~SearchNlModelManager() = default;

QString SearchNlModelManager::defaultModelPath()
{
    DNNModelBase* const model = DNNModelManager::instance()->getModel(<--- Variable 'model' can be declared as pointer to const
        s_nlModelName, DNNModelUsage::DNNUsageNaturalLanguageSearch);

    return (model ? model->getModelPath() : QString());
}

bool SearchNlModelManager::isModelAvailable()
{
    const QString path = defaultModelPath();

    return (!path.isEmpty() && QFileInfo::exists(path));
}

QString SearchNlModelManager::currentModelPath() const
{
    return (m_currentModelPath.isEmpty() ? defaultModelPath()
                                         : m_currentModelPath);
}

QString SearchNlModelManager::currentModelVersion() const
{
    return m_currentVersion;
}

void SearchNlModelManager::ensureModelAvailable()
{
    if (isModelAvailable())
    {
        m_currentModelPath = defaultModelPath();

        Q_EMIT signalModelReady(m_currentModelPath);

        qCInfo(DIGIKAM_NLSEARCH_LOG) << "isModelAvailable:" << isModelAvailable()
                             << "path:" << defaultModelPath();

        return;
    }

    qCInfo(DIGIKAM_NLSEARCH_LOG) << "NL search model not present; download required via FilesDownloader:"
                                 << defaultModelPath();

    Q_EMIT signalModelError(i18nc("@info",
                                  "The natural-language search model is not installed. "
                                  "Please download it from the digiKam setup downloader."));
}

void SearchNlModelManager::cleanupObsoleteModels()
{
    // No-op: obsolete model files are cleaned up centrally by
    // FilesDownloader::deleteUnusedFiles(). Kept for interface stability.
}

} // namespace Digikam

#include "moc_searchnlmodelmanager.cpp"