Skip to content

Commit

Permalink
feat: embedding plugin
Browse files Browse the repository at this point in the history
add embdding plugin item.
  • Loading branch information
Clauszy authored and deepin-bot[bot] committed Dec 19, 2024
1 parent 97da4a6 commit aedde9d
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 134 deletions.
Binary file modified 3rdparty/antlr4.tar.gz
Binary file not shown.
6 changes: 4 additions & 2 deletions src/grand-search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips"
OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw"
OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64"
)
message(${CMAKE_SYSTEM_PROCESSOR} ": disable ai search")
message("${CMAKE_SYSTEM_PROCESSOR} : disable ai search")
else()
message(${CMAKE_SYSTEM_PROCESSOR} ": enable ai search")
message("${CMAKE_SYSTEM_PROCESSOR} : enable ai search")
ADD_DEFINITIONS(-DENABLE_AI_SEARCH)
endif()

Expand Down Expand Up @@ -152,6 +152,8 @@ set(GUISRC
gui/searchconfig/llmwidget/modelmanagebutton.h
gui/searchconfig/llmwidget/downloader.h
gui/searchconfig/llmwidget/downloader.cpp
gui/searchconfig/llmwidget/embeddingpluginwidget.cpp
gui/searchconfig/llmwidget/embeddingpluginwidget.h
gui/searchconfig/hyperlinklabel/hyperlinklabel.cpp
gui/searchconfig/hyperlinklabel/hyperlinklabel.h
gui/searchconfig/comboboxwidget/comboboxwidget.h
Expand Down
4 changes: 1 addition & 3 deletions src/grand-search/gui/searchconfig/indexwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ IndexWidget::IndexWidget(QWidget *parent)
m_mainLayout->addWidget(m_groupLabel);

#ifdef ENABLE_AI_SEARCH
// 目前非amd64架构,用不了AI搜索
m_intelligent = new IntelligentRetrievalWidget(this);
m_mainLayout->addWidget(m_intelligent);
#endif

m_mainLayout->addSpacing(10);
#endif
m_mainLayout->addWidget(m_blackListWidget);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "autoindexstatus.h"
#include "gui/searchconfig/switchwidget/switchwidget.h"
#include "gui/searchconfig/llmwidget/llmwidget.h"
#include "gui/searchconfig/llmwidget/embeddingpluginwidget.h"
#include "business/config/searchconfig.h"
#include "global/searchconfigdefine.h"
#include "global/builtinsearch.h"
Expand Down Expand Up @@ -105,24 +106,6 @@ IntelligentRetrievalWidget::IntelligentRetrievalWidget(QWidget *parent)
m_indexLayout->addWidget(bkg);
}

// model
{
RoundedBackground *bkg = new RoundedBackground(m_indexWidget);
bkg->setMinimumSize(CHECKBOXITEMWIDTH, SWITCHWIDGETHEIGHT);
bkg->setTopRound(true);
bkg->setBottomRound(true);

QVBoxLayout *vl = new QVBoxLayout(bkg);
bkg->setLayout(vl);
vl->setContentsMargins(0, 2, 0, 5);
m_llmWidget = new LLMWidget(bkg);
m_llmWidget->setText(tr("UOS AI LLM"),tr("After installing the UOS AI large model, you can use the AI intelligent search function without an internet connection."));
m_llmWidget->checkInstallStatus();
vl->addWidget(m_llmWidget);
m_indexLayout->addSpacing(10);
m_indexLayout->addWidget(bkg);
}

// full text
{
m_indexLayout->addSpacing(10);
Expand Down Expand Up @@ -151,6 +134,42 @@ IntelligentRetrievalWidget::IntelligentRetrievalWidget(QWidget *parent)
m_indexLayout->addWidget(m_fullTextLabel);
}

// plugin
{
RoundedBackground *bkg = new RoundedBackground(m_indexWidget);
bkg->setMinimumSize(CHECKBOXITEMWIDTH, SWITCHWIDGETHEIGHT);
bkg->setTopRound(true);
bkg->setBottomRound(true);

QVBoxLayout *vl = new QVBoxLayout(bkg);
bkg->setLayout(vl);
vl->setContentsMargins(0, 2, 0, 5);
m_embWidget = new EmbeddingPluginWidget(bkg);
m_embWidget->setText(tr("Embedding Plugins"),tr("After installing the model, you can use services such as AI Search and UOS AI Assistant.."));
m_embWidget->checkInstallStatus();
vl->addWidget(m_embWidget);
m_indexLayout->addSpacing(10);
m_indexLayout->addWidget(bkg);
}

// model
{
RoundedBackground *bkg = new RoundedBackground(m_indexWidget);
bkg->setMinimumSize(CHECKBOXITEMWIDTH, SWITCHWIDGETHEIGHT);
bkg->setTopRound(true);
bkg->setBottomRound(true);

QVBoxLayout *vl = new QVBoxLayout(bkg);
bkg->setLayout(vl);
vl->setContentsMargins(0, 2, 0, 5);
m_llmWidget = new LLMWidget(bkg);
m_llmWidget->setText(tr("UOS AI LLM"),tr("After installing the UOS AI large model, you can use the AI intelligent search function without an internet connection."));
m_llmWidget->checkInstallStatus();
vl->addWidget(m_llmWidget);
m_indexLayout->addSpacing(10);
m_indexLayout->addWidget(bkg);
connect(m_embWidget, &EmbeddingPluginWidget::pluginStateChanged, m_llmWidget, &LLMWidget::pluginStateChanged);
}
#ifdef VECTOR_SEARCH
// 超链接
m_vectorDetail = new QLabel;
Expand Down Expand Up @@ -184,6 +203,8 @@ void IntelligentRetrievalWidget::updateState()
this->updateIndexStatusContent(this->getIndexStatus());
}

m_embWidget->checkInstallStatus();

#ifdef VECTOR_SEARCH
if (isVectorSupported()) {
bool checked = cfg->getConfig(GRANDSEARCH_SEMANTIC_GROUP, GRANDSEARCH_CLASS_GENERALFILE_SEMANTIC_VECTOR, true).toBool();
Expand Down Expand Up @@ -300,24 +321,15 @@ void IntelligentRetrievalWidget::checkChanged()
}

// 检测是否安装大模型,未安装就提醒弹窗
if (on && !this->isQueryLangSupported()) {
DDialog *warningDlg = new DDialog();
warningDlg->setWindowFlags((warningDlg->windowFlags() | Qt::WindowType::WindowStaysOnTopHint));
warningDlg->setFixedWidth(380);
warningDlg->setIcon(QIcon(":icons/dde-grand-search-setting.svg"));
warningDlg->setMessage(QString(tr("To use AI smart search, you need to install the UOS AI large model. Please install the model.")));
warningDlg->addButton(tr("Not yet"), false, DDialog::ButtonNormal);
warningDlg->addButton(tr("Install the model"), true, DDialog::ButtonRecommend);
connect(warningDlg, &DDialog::accepted, warningDlg, [&] {
m_llmWidget->onClickedStatusBtn();
//QDBusInterface iface("com.home.appstore.client", "/com/home/appstore/client", "com.home.appstore.client");
//iface.call("openBusinessUri", "");
});
connect(warningDlg, &DDialog::finished, warningDlg, [&] {
warningDlg->deleteLater();
});
warningDlg->moveToCenter();
warningDlg->exec();
if (on && (!m_llmWidget->isInstalled() || !m_embWidget->isInstalled())) {
DDialog warningDlg;
warningDlg.setWindowFlags((warningDlg.windowFlags() | Qt::WindowType::WindowStaysOnTopHint));
warningDlg.setFixedWidth(380);
warningDlg.setIcon(QIcon(":icons/dde-grand-search-setting.svg"));
warningDlg.setMessage(QString(tr("To use AI Smart Search, you need to install the Embedding Plugins and UOS AI LLM first.")));
warningDlg.addButton(tr("OK"), true, DDialog::ButtonNormal);
warningDlg.moveToCenter();
warningDlg.exec();
}
}
#ifdef VECTOR_SEARCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace GrandSearch {
class SwitchWidget;
class LLMWidget;
class EmbeddingPluginWidget;
class DetailCheckBox;
class AutoIndexStatus;
class IntelligentRetrievalWidget : public Dtk::Widget::DWidget
Expand Down Expand Up @@ -56,6 +57,7 @@ protected slots:
SwitchWidget *m_fullTextIndex = nullptr;
QLabel *m_fullTextLabel = nullptr;
LLMWidget *m_llmWidget = nullptr;
EmbeddingPluginWidget *m_embWidget = nullptr;
AutoIndexStatus *m_indexStatus = nullptr;
QTimer m_timer;
bool m_ignoreSigal = false;
Expand Down
134 changes: 134 additions & 0 deletions src/grand-search/gui/searchconfig/llmwidget/embeddingpluginwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "embeddingpluginwidget.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QProcess>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>

#include <DFontSizeManager>
#include <DGuiApplicationHelper>

DWIDGET_USE_NAMESPACE
using namespace GrandSearch;

static constexpr char PLUGINSNAME[] = "uos-ai-rag";

EmbeddingPluginWidget::EmbeddingPluginWidget(QWidget *parent) : DWidget(parent)
{
initUI();
}

void EmbeddingPluginWidget::setText(const QString &theme, const QString &summary)
{
m_pLabelTheme->setText(theme);
m_pLabelSummary->setText(summary);
}

bool EmbeddingPluginWidget::isInstalled()
{
return m_pManageModel->property("modelStatus").toInt() != Uninstall;
}

void EmbeddingPluginWidget::checkInstallStatus()
{
QProcess m_pProcess;
m_pProcess.start("dpkg-query", QStringList() << "-W" << QString("-f='${db:Status-Status}\n'") << PLUGINSNAME);
m_pProcess.waitForFinished();
QByteArray reply = m_pProcess.readAllStandardOutput();
bool installStatus = (reply == "'installed\n'" ? true : false);
m_pManageModel->setProperty("modelStatus", installStatus ? Install : Uninstall);
m_pManageModel->setVisible(!installStatus);

m_pLabelStatus->setText(installStatus ? tr("Installed") : tr("Not Installed"));

emit pluginStateChanged(installStatus);
}

void EmbeddingPluginWidget::paintEvent(QPaintEvent *e)
{
DPalette pl = m_pLabelSummary->palette();
QColor color = DGuiApplicationHelper::instance()->applicationPalette().color(DPalette::BrightText);
if (!isActiveWindow())
color.setAlphaF(0.4);
else
color.setAlphaF(0.6);
pl.setColor(QPalette::Text, color);
m_pLabelSummary->setPalette(pl);

pl = m_pLabelStatus->palette();
if (m_pManageModel->property("modelStatus").toInt() == Install) {
color = QColor(21, 190, 76);
color.setAlphaF(1);
} else
color.setAlphaF(0.6);

if (!isActiveWindow())
color.setAlphaF(0.4);

pl.setColor(QPalette::Text, color);
m_pLabelStatus->setPalette(pl);

DWidget::paintEvent(e);
}

void EmbeddingPluginWidget::initUI()
{
m_pLabelTheme = new DLabel;
DFontSizeManager::instance()->bind(m_pLabelTheme, DFontSizeManager::T6, QFont::Medium);
m_pLabelTheme->setElideMode(Qt::ElideRight);

m_pLabelStatus = new DLabel(tr("Not Installed"));
m_pLabelStatus->setForegroundRole(QPalette::Text);
DFontSizeManager::instance()->bind(m_pLabelStatus, DFontSizeManager::T8, QFont::Medium);

auto topLayout = new QHBoxLayout();
topLayout->setContentsMargins(0, 0, 0, 0);
topLayout->addWidget(m_pLabelTheme, 0, Qt::AlignLeft);
topLayout->addStretch();
topLayout->addWidget(m_pLabelStatus, 0, Qt::AlignRight);

m_pLabelSummary = new DLabel;
m_pLabelSummary->setForegroundRole(QPalette::Text);
DFontSizeManager::instance()->bind(m_pLabelSummary, DFontSizeManager::T8, QFont::Normal);
m_pLabelSummary->setElideMode(Qt::ElideRight);

m_pManageModel = new ModelManageButton(tr("Install"), this);
QPixmap pixmap = QApplication::style()->standardIcon(QStyle::SP_ArrowDown).pixmap(QSize(10, 10));
QPainter painter(&pixmap);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(pixmap.rect(), DGuiApplicationHelper::instance()->applicationPalette().textTips());
m_pManageModel->setIcon(pixmap);
m_pManageModel->setProperty("modelStatus", Uninstall);
DFontSizeManager::instance()->bind(m_pManageModel, DFontSizeManager::T8, QFont::Medium);
m_pManageModel->updateRectSize();

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setContentsMargins(10, 8, 10, 6);
mainLayout->setSpacing(5);
mainLayout->addLayout(topLayout);
mainLayout->addWidget(m_pLabelSummary, 0, Qt::AlignLeft);
mainLayout->addWidget(m_pManageModel, 0, Qt::AlignLeft);

setLayout(mainLayout);

connect(m_pManageModel, &ModelManageButton::clicked, this, &EmbeddingPluginWidget::openAppStore);
}

void EmbeddingPluginWidget::openAppStore()
{
qInfo() << "open app store" << PLUGINSNAME;
QDBusMessage msg = QDBusMessage::createMethodCall("com.home.appstore.client", "/com/home/appstore/client",
"com.home.appstore.client", "openBusinessUri");
QVariantList list;
list.append(QString("app_detail_info/%0").arg(PLUGINSNAME));
msg.setArguments(list);

QDBusConnection::sessionBus().asyncCall(msg, 100);
return;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef EMBEDDINGPLUGINWIDGET_H
#define EMBEDDINGPLUGINWIDGET_H

#include "modelmanagebutton.h"

#include <DLabel>
#include <DWidget>

namespace GrandSearch {
class EmbeddingPluginWidget : public Dtk::Widget::DWidget
{
Q_OBJECT
public:
explicit EmbeddingPluginWidget(QWidget *parent = nullptr);
void setText(const QString &theme, const QString &summary);
bool isInstalled();
void checkInstallStatus();
public slots:
void openAppStore();
protected:
void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE;
private:
void initUI();
signals:
void pluginStateChanged(bool);

private:
Dtk::Widget::DLabel *m_pLabelTheme = nullptr;
Dtk::Widget::DLabel *m_pLabelSummary = nullptr;
Dtk::Widget::DLabel *m_pLabelStatus = nullptr;
ModelManageButton *m_pManageModel = nullptr;
};

}
#endif // EMBEDDINGPLUGINWIDGET_H
Loading

0 comments on commit aedde9d

Please sign in to comment.