后续:增加流式输出

上文中非流式输出

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的时候 需要等待一段时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值