| 370 | } |
| 371 | |
| 372 | bool CodeGeeXLLM::checkValid(QString *errStr) |
| 373 | { |
| 374 | d->loadConfig(); |
| 375 | QString url = kUrlQueryUserInfo; |
| 376 | QNetworkReply *reply = d->getMessage(url, d->apiKey); |
| 377 | QEventLoop loop; |
| 378 | bool valid = false; |
| 379 | connect(reply, &QNetworkReply::finished, this, [=, &loop, &valid]() { |
| 380 | if (reply->error()) { |
| 381 | qCritical() << "Error:" << reply->errorString(); |
| 382 | loop.exit(); |
| 383 | return; |
| 384 | } |
| 385 | QString response = QString::fromUtf8(reply->readAll()); |
| 386 | QJsonDocument document = QJsonDocument::fromJson(response.toUtf8()); |
| 387 | QJsonObject jsonObject = document.object(); |
| 388 | int code = jsonObject["code"].toInt(); |
| 389 | if (code == kCode_Success) { |
| 390 | valid = true; |
| 391 | } else { |
| 392 | valid = false; |
| 393 | *errStr = "Please Login CodeGeeX first"; |
| 394 | |
| 395 | QStringList actions { "codegeex_login_default", tr("Login") }; |
| 396 | auto windowService = dpfGetService(WindowService); |
| 397 | windowService->notifyWithCallback(0, "CodeGeeX", tr("Please login to use CodeGeeX."), actions, [=](const QString &actId) { |
| 398 | if (actId == "codegeex_login_default") |
| 399 | d->login(); |
| 400 | }); |
| 401 | } |
| 402 | loop.exit(); |
| 403 | }); |
| 404 | loop.exec(); |
| 405 | |
| 406 | return valid; |
| 407 | } |
| 408 | |
| 409 | QJsonObject CodeGeeXLLM::create(const Conversation &conversation) |
| 410 | { |
no test coverage detected