| 584 | } |
| 585 | |
| 586 | void 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: |
no test coverage detected