void Network::onReadyRead()
{
if(_reply != nullptr && _reply->error() == QNetworkReply::NoError){
//得到返回的数据
QByteArray read_data = (_reply->readAll());
//qDebug() << read_data;
QList<QByteArray> read_list = read_data.split('\n');
for (int i = 0; i < read_list.size(); ++i) {
if(read_list.at(i).size() != 0)
{
//qDebug() << read_list.at(i).mid(6);
//对返回的json数据进行解析
QJsonObject obj = QJsonDocument::fromJson(read_list.at(i).mid(6)).object();
qDebug() << "Response:" << obj << "\n";
QJsonArray choicesarray = obj.value("choices").toArray();
if (!choicesarray.isEmpty())
{
QJsonObject choiceobj = choicesarray[0].toObject();
if (choiceobj.contains("delta") && choiceobj["delta"].isObject())
{
QJsonObject messageobj = choiceobj["delta"].toObject();
if (messageobj.contains("reasoning_content") && messageobj["reasoning_content"].isString())
{
this->setReadText(messageobj["reasoning_content"].toString());
}
if (messageobj.contains("content") && messageobj["content"].isString())
{
this->setReadText(messageobj["content"].toString());
}
}
}
}
}
} else {
qDebug() << "https request error:" << _reply->errorString();
}
}
后续还发现有时候能回答上来 有时候回答不上来 不知道什么原因
特别是切换模型r1再切换回v3的时候 需要等待一段时间