From b282dfead8552e89066a0839887a287350d6e422 Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Wed, 18 Dec 2024 16:31:00 +0800 Subject: [PATCH] fix: Display the directory without selecting the file Log: as title --- .../aimanager/option/addmodeldialog.cpp | 27 +++++-------------- src/plugins/codeeditor/gui/tabbar.cpp | 5 ++-- src/plugins/codegeex/codegeex.cpp | 2 ++ .../cxx/cmake/project/cmakeasynparse.cpp | 3 +++ src/plugins/project/mainframe/projecttree.cpp | 11 +++++--- src/services/ai/aiservice.h | 18 +++++++++++++ 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/plugins/aimanager/option/addmodeldialog.cpp b/src/plugins/aimanager/option/addmodeldialog.cpp index 62e4bd280..8daaa2831 100644 --- a/src/plugins/aimanager/option/addmodeldialog.cpp +++ b/src/plugins/aimanager/option/addmodeldialog.cpp @@ -6,6 +6,7 @@ #include "services/ai/aiservice.h" #include "aimanager.h" +#include #include #include #include @@ -36,8 +37,7 @@ private slots: DLineEdit *leLLMName { nullptr }; DComboBox *cbLLMType { nullptr }; DLineEdit *leApiUrl { nullptr }; - DLineEdit *leApiKey { nullptr }; - DPushButton *passwordBtn { nullptr }; + DPasswordEdit *leApiKey { nullptr }; DSuggestButton *okButton { nullptr }; DPushButton *cancelButton { nullptr }; @@ -69,13 +69,8 @@ void AddModelDialogPrivate::initUi() QLabel *lbApiKey = new QLabel(AddModelDialog::tr("Api Key")); lbApiKey->setAlignment(Qt::AlignRight | Qt::AlignVCenter); - leApiKey = new DLineEdit(q); - leApiKey->setEchoMode(QLineEdit::Password); + leApiKey = new DPasswordEdit(q); leApiKey->setPlaceholderText(AddModelDialog::tr("Optional, please enter.")); - passwordBtn = new DPushButton(q); - passwordBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::SP_HidePassword)); - passwordBtn->setCheckable(true); - passwordBtn->setChecked(true); q->setWindowTitle(AddModelDialog::tr("Add Model")); @@ -87,17 +82,16 @@ void AddModelDialogPrivate::initUi() gridLayout->setSpacing(10); gridLayout->addWidget(lbModelName, 0, 0); - gridLayout->addWidget(leLLMName, 0, 1, 1, 2); + gridLayout->addWidget(leLLMName, 0, 1); gridLayout->addWidget(lbLLMType, 1, 0); - gridLayout->addWidget(cbLLMType, 1, 1, 1, 2); + gridLayout->addWidget(cbLLMType, 1, 1); gridLayout->addWidget(lbApiUrl, 2, 0); - gridLayout->addWidget(leApiUrl, 2, 1, 1, 2); + gridLayout->addWidget(leApiUrl, 2, 1); gridLayout->addWidget(lbApiKey, 3, 0); gridLayout->addWidget(leApiKey, 3, 1); - gridLayout->addWidget(passwordBtn, 3, 2); okButton = new DSuggestButton(q); okButton->setText(AddModelDialog::tr("Confirm")); @@ -142,15 +136,6 @@ void AddModelDialogPrivate::initConnection() slotAddModel(); }); AddModelDialog::connect(cancelButton, &DSuggestButton::clicked, q, &AddModelDialog::reject); - AddModelDialog::connect(passwordBtn, &DPushButton::clicked, q, [=](){ - if (passwordBtn->isChecked()) { - passwordBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::SP_ShowPassword)); - leApiKey->setEchoMode(QLineEdit::Password); - } else { - passwordBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::SP_HidePassword)); - leApiKey->setEchoMode(QLineEdit::Normal); - } - }); } void AddModelDialogPrivate::slotAddModel() diff --git a/src/plugins/codeeditor/gui/tabbar.cpp b/src/plugins/codeeditor/gui/tabbar.cpp index f2874effe..7344b8e23 100644 --- a/src/plugins/codeeditor/gui/tabbar.cpp +++ b/src/plugins/codeeditor/gui/tabbar.cpp @@ -10,13 +10,13 @@ #include #include #include +#include #include #include #include #include #include -#include DWIDGET_USE_NAMESPACE @@ -137,8 +137,7 @@ void TabBarPrivate::showMenu(QPoint pos) menu.addSeparator(); menu.addAction(tr("Show Containing Folder"), [=]() { auto file = tabBar->tabToolTip(curIndex); - QFileInfo info(file); - QDesktopServices::openUrl(QUrl::fromLocalFile(info.absolutePath())); + DDesktopServices::showFileItem(file); }); menu.exec(QCursor::pos()); diff --git a/src/plugins/codegeex/codegeex.cpp b/src/plugins/codegeex/codegeex.cpp index c07662b4e..c732ca452 100644 --- a/src/plugins/codegeex/codegeex.cpp +++ b/src/plugins/codegeex/codegeex.cpp @@ -74,6 +74,8 @@ bool CodeGeex::start() aiService->available = std::bind(&CodeGeeXManager::isLoggedIn, CodeGeeXManager::instance()); aiService->askQuestion = std::bind(&CodeGeeXManager::independentAsking, CodeGeeXManager::instance(), _1, QMultiMap(), _2); aiService->askQuestionWithHistory = std::bind(&CodeGeeXManager::independentAsking, CodeGeeXManager::instance(), _1, _2, _3); + aiService->generateRag = std::bind(&CodeGeeXManager::generateRag, CodeGeeXManager::instance(), _1); + aiService->query = std::bind(&CodeGeeXManager::query, CodeGeeXManager::instance(), _1, _2, _3); return true; } diff --git a/src/plugins/cxx/cmake/project/cmakeasynparse.cpp b/src/plugins/cxx/cmake/project/cmakeasynparse.cpp index 3d4e6335b..a13011652 100644 --- a/src/plugins/cxx/cmake/project/cmakeasynparse.cpp +++ b/src/plugins/cxx/cmake/project/cmakeasynparse.cpp @@ -187,6 +187,7 @@ void CmakeAsynParse::parseProject(QStandardItem *rootItem, const dpfservice::Pro cmakeFileItem->setToolTip(cmakeFileInfo.filePath()); cmakeParentItem->appendRow(cmakeFileItem); cmakeFileItem->setData(cmakeFileInfo.absoluteFilePath(), Project::FileIconRole); + cmakeFileItem->setData(cmakeFileInfo.absoluteFilePath(), Project::FilePathRole); // monitor cmake file change to refresh project tree. if (cmakeParentItem == rootItem) { @@ -260,6 +261,7 @@ void CmakeAsynParse::parseProject(QStandardItem *rootItem, const dpfservice::Pro srcItem->setText(srcFileInfo.fileName()); srcItem->setToolTip(srcFileInfo.filePath()); srcItem->setData(srcFileInfo.absoluteFilePath(), Project::FileIconRole); + srcItem->setData(srcFileInfo.absoluteFilePath(), Project::FilePathRole); if (srcFileInfo.isDir()) emit directoryCreated(rootItem, srcFileInfo.filePath()); @@ -346,6 +348,7 @@ QStandardItem *CmakeAsynParse::createParentItem(QStandardItem *rootItem, const Q item->setText(nameItem); item->setToolTip(basePath + relative); item->setData(basePath + relative, Project::FileIconRole); + item->setData(basePath + relative, Project::FilePathRole); // append to parent. QStandardItem *parentItem = findParentItem(rootItem, relative); emit directoryCreated(rootItem, basePath + relative); diff --git a/src/plugins/project/mainframe/projecttree.cpp b/src/plugins/project/mainframe/projecttree.cpp index e83f8981e..2349e74e8 100644 --- a/src/plugins/project/mainframe/projecttree.cpp +++ b/src/plugins/project/mainframe/projecttree.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -26,9 +27,8 @@ #include #include #include -#include #include - +DCORE_USE_NAMESPACE DWIDGET_USE_NAMESPACE using namespace dpfservice; @@ -259,9 +259,12 @@ void ProjectTree::doItemMenuRequest(QStandardItem *item, QContextMenuEvent *even menu->addSeparator(); QAction *showContainFolder = new QAction(tr("Show Containing Folder"), this); connect(showContainFolder, &QAction::triggered, [=]() { - QString filePath = item->toolTip(); + QString filePath = item->data(Project::ProjectItemRole::FilePathRole).toString(); QFileInfo info(filePath); - QDesktopServices::openUrl(QUrl::fromLocalFile(info.absolutePath())); + if (info.isFile()) + DDesktopServices::showFileItem(filePath); + else + DDesktopServices::showFolder(filePath); }); menu->addAction(showContainFolder); diff --git a/src/services/ai/aiservice.h b/src/services/ai/aiservice.h index ad77be1ce..dbf8f0fff 100644 --- a/src/services/ai/aiservice.h +++ b/src/services/ai/aiservice.h @@ -89,6 +89,24 @@ class SERVICE_EXPORT AiService final : public dpf::PluginService, dpf::AutoServi // custom model DPF_INTERFACE(AbstractLLM *, getLLM, const LLMInfo &info); DPF_INTERFACE(QList, getAllModel); + + // rag + DPF_INTERFACE(void, generateRag, const QString &projectPath); + + /*! + * \brief + Could be empty or not completed. see obj.isEmpty or obj["Completed"].toBool + May block, recommended to run in a separate thread + * \param query . Find similar chunks based on this text as accurately as possible + * \param topItems . count of chunks + * \return + JsonObject: + Query: str + Chunks: Arr[fileName:str, content:str, similarity:float] + Completed: Bool + Instructions: obj{name:str, description:str, content:str} + */ + DPF_INTERFACE(QJsonObject, query, const QString &projectPath, const QString &query, int topItems); }; } // namespace dpfservice