MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / generateRag

Method generateRag

src/plugins/chat/chatmanager.cpp:586–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586void ChatManager::generateRag(const QString &projectPath)
587{
588 mutex.lock();
589 if (indexingProject.contains(projectPath)) {
590 mutex.unlock();
591 return;
592 }
593 indexingProject.append(projectPath);
594 mutex.unlock();
595 QProcess *process = new QProcess;
596 QObject::connect(QApplication::instance(), &QApplication::aboutToQuit, process, [process]() {
597 process->kill();
598 },
599 Qt::DirectConnection);
600
601 QObject::connect(process, &QProcess::readyReadStandardError, process, [process]() {
602 qInfo() << "Error:" << process->readAllStandardError() << "\n";
603 });
604
605 QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
606 process, [=](int exitCode, QProcess::ExitStatus exitStatus) {
607 qInfo() << "Python script finished with exit code" << exitCode << "Exit!!!";
608 mutex.lock();
609 indexingProject.removeOne(projectPath);
610 mutex.unlock();
611 auto success = process->readAllStandardError().isEmpty();
612 emit generateDone(projectPath, !success);
613 if (!success)
614 emit notify(2, tr("The error occurred when performing rag on project %1.").arg(projectPath));
615 process->deleteLater();
616 });
617
618 qInfo() << "start rag project:" << projectPath;
619
620 QString ragPath = CustomPaths::CustomPaths::global(CustomPaths::Scripts) + "/rag";
621 process->setWorkingDirectory(ragPath);
622 auto generatePyPath = ragPath + "/generate.py";
623 auto pythonPath = condaRootPath() + "/miniforge/envs/deepin_unioncode_env/bin/python";
624 auto modelPath = CustomPaths::CustomPaths::global(CustomPaths::Models);
625 if (!QFileInfo(pythonPath).exists())
626 return;
627 process->start(pythonPath, QStringList() << generatePyPath << modelPath << projectPath);
628 if (QThread::currentThread() != qApp->thread()) // incase thread exit before process done. cause slot function can`t work
629 process->waitForFinished();
630}
631
632/*
633 JsonObject:

Callers 1

Calls 12

connectFunction · 0.85
notifyFunction · 0.85
readAllStandardErrorMethod · 0.80
lockMethod · 0.45
containsMethod · 0.45
unlockMethod · 0.45
appendMethod · 0.45
killMethod · 0.45
isEmptyMethod · 0.45
setWorkingDirectoryMethod · 0.45
existsMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected