| 154 | } |
| 155 | |
| 156 | void CodeGeeXLLMPrivate::createNewSession() |
| 157 | { |
| 158 | loadConfig(); // incase sessionId has updated |
| 159 | QString url = kUrlCreateNewSession; |
| 160 | QString currentMSecsStr = QString::number(QDateTime::currentMSecsSinceEpoch()); |
| 161 | QString sessionTitle("Session_" + currentMSecsStr); |
| 162 | QString taskId(uuid()); |
| 163 | |
| 164 | QJsonObject jsonObject; |
| 165 | jsonObject.insert("prompt", sessionTitle); |
| 166 | jsonObject.insert("talkId", taskId); |
| 167 | |
| 168 | QNetworkReply *reply = postMessage(url, apiKey, QJsonDocument(jsonObject).toJson()); |
| 169 | QEventLoop loop; |
| 170 | CodeGeeXLLM::connect(reply, &QNetworkReply::finished, q, [=, &loop]() { |
| 171 | if (reply->error()) { |
| 172 | qCritical() << "CodeGeeX Session created faield \nError:" << reply->errorString(); |
| 173 | loop.exit(); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | QString response = QString::fromUtf8(reply->readAll()); |
| 178 | QJsonDocument document = QJsonDocument::fromJson(response.toUtf8()); |
| 179 | QJsonObject jsonObject = document.object(); |
| 180 | int code = jsonObject["code"].toInt(); |
| 181 | if (code == kCode_Success) |
| 182 | talkId = taskId; |
| 183 | loop.exit(); |
| 184 | }); |
| 185 | loop.exec(); |
| 186 | } |
| 187 | |
| 188 | void CodeGeeXLLMPrivate::handleReplyFinished(QNetworkReply *reply) |
| 189 | { |