2222222222222222222222222222222222222
立即下载
资源介绍:
222222222222222222222222222
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->mode->setView(new QListView());
bgistran =true;
choose_mode_index =2;
allwordcount=0;
danOrshuang=0;
answer="";
contentstart=0;
manager = new QNetworkAccessManager(this);
hintdata="以下内容由小熠为你呈现:\n";
addstrList.append(QStringLiteral("(9682)"));
addstrList.append(QStringLiteral("(3477)"));
addstrList.append(QStringLiteral("(5510)"));
modeList.append(QStringLiteral("深入分析1"));
modeList.append(QStringLiteral("深入分析2"));
modeList.append(QStringLiteral("深入分析3"));
ui->label_1->setStyleSheet("background-color: rgba(255, 255, 255, 80);border-radius:18px;color:rgba(221, 121, 180, 140)");
for(int i=0;i<3;i++)
{
ui->mode->addItem(modeList[i]);
}
themealter(0);
QTimer *mytimer=new QTimer(this);
QObject::connect(mytimer, SIGNAL(timeout()), this, SLOT(dealisrunning()));
mytimer->start(1000);
}
void MainWindow::themealter(int index)
{
QString style_music = QString("QPushButton{ background-color: rgba(255, 255, 255, 0);border-radius:24px;}"
"QPushButton:hover{background-color: rgba(245, 189, 200, 50);border-radius:24px;}"
);
ui->ICON->setStyleSheet(style_music);
ui->Btn_music->setStyleSheet(style_music);
QString styleSheet = QString("QPushButton{ background-color: rgba(255, 255, 255, 80);border-radius:24px;}"
"QPushButton:hover{background-color: rgba(245, 189, 200, 80);border-radius:24px;}"
);
ui->Btn_send->setStyleSheet(styleSheet);
ui->Btn_clear->setStyleSheet(styleSheet);
ui->Btn_word->setStyleSheet(styleSheet);
ui->Btn_pdf->setStyleSheet(styleSheet);
ui->Btn_txt->setStyleSheet(styleSheet);
ui->Btn_ppt->setStyleSheet(styleSheet);
ui->Btn_setting->setStyleSheet(styleSheet);
ui->Btn_history->setStyleSheet(styleSheet);
ui->mode->setStyleSheet("QComboBox {border-image: url(:/images/bg1.png);font: italic 13pt \"Mongolian Baiti\";}"
"QComboBox QAbstractItemView{border-image: url(:/images/bg2.png);font: italic 13pt \"Mongolian Baiti\";}"
);
}
MainWindow::~MainWindow()
{
delete ui;
}
QString MainWindow::Format(QString str)
{
QString return_data;
return_data=str.simplified();
return_data = return_data.replace("\"","\\\"");
return_data+=",";
return_data+=addstrList[choose_mode_index];
qDebug()<< return_data;
return return_data;
}
void MainWindow::httpPost_meta()
{
QUrl url("https://api.atomecho.cn/v1/chat/completions");
// QUrl url("https://cn.bing.com/search?q=qt");
QNetworkRequest request(url);
// 设置已知头信息
request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Authorization","Bearer sk-b5b60e14906899821189a325a0ad6662");
QByteArray questionstr= Format(ui->question->toPlainText()).toUtf8();
QByteArray postdata;
postdata.append("{\"model\":\"Atom-13B-Chat\",\"messages\": [{\"role\": \"user\",\"content\":\"");
postdata.append(questionstr);
postdata.append("\"}],\"stream\": true}");
reply = manager->post(request,postdata);//发起post请求
QString str =QStringLiteral("正在生成中,请稍后……");
ui->allcount->setText(QString::number(0));
ui->textEdit_2->setText(str);
QObject::connect(reply, &QNetworkReply::finished, this, &MainWindow::dealhttp);
}
void MainWindow::httpPost_doubao()
{
setlength(0);
answer="";
allwordcount=0;
contentstart=0;
QUrl url("https://ark.cn-beijing.volces.com/api/v3/bots/chat/completions");
QNetworkRequest request(url);
// 设置已知头信息
request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Authorization","Bearer 11e92871-bb77-41bd-bb99-e094c6ae6c42");
QByteArray questionstr= Format(ui->question->toPlainText()).toUtf8();
QByteArray postdata;
postdata.append("{\"model\":\"bot-20240924221914-v9ck8\",\"messages\": [{\"role\": \"user\",\"content\":[{\"type\":\"text\",\"text\":\"");
postdata.append(questionstr);
postdata.append("\"}]}],\"stream\": true}");
reply_db = manager->post(request,postdata);//发起post请求
QString str =QStringLiteral("以下内容由奴才为娘娘精心呈现");
ui->allcount->setText(QString::number(0));
ui->textEdit_2->setText(str);
// 连接信号和槽
QObject::connect(reply_db, &QNetworkReply::readyRead, this, &MainWindow::onDataReceived);
QObject::connect(reply_db, &QNetworkReply::finished, this, &MainWindow::onFinished);
//QObject::connect(reply_db, &QNetworkReply::finished, this, &MainWindow::dealhttp_doubao);
}
void MainWindow::dealhttp_doubao()
{
QByteArray data = reply_db->readAll();//读出数据
QString _data =data;
reply_db->deleteLater();
int end = _data.indexOf("role");
int start =_data.indexOf("content");
int length = end -start;
QString answerstr = _data.mid(start+10,length-13);
answerstr=answerstr.replace("\\n","\n");
allwordcount =answerstr.length();
ui->allcount->setText(QString::number(allwordcount));
ui->textEdit_2->setText(answerstr);
}
void MainWindow::httpPost_xf_s35()
{
QUrl url("https://spark-api-open.xf-yun.com/v1/chat/completions");
QNetworkRequest request(url);
// 设置已知头信息
request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Authorization","Bearer 232330e73bb6e5e3026dc56a7a430e63:2ec41f45a2e1cebded99f26e0ec5e1ca");
QByteArray questionstr= Format(ui->question->toPlainText()).toUtf8();
QByteArray postdata;
postdata.append("{\"model\":\"general\",\"messages\": [{\"role\": \"user\",\"content\":\"");
postdata.append(questionstr);
postdata.append("\"}],\"stream\": true}");
reply_xf = manager->post(request,postdata);//发起post请求
QString str =QStringLiteral("正在生成中,请稍后……");
ui->allcount->setText(QString::number(0));
ui->textEdit_2->setText(str);
QObject::connect(reply_xf, &QNetworkReply::finished, this, &MainWindow::dealhttp_xf);
}
//key:80522e23159d2497c2a72a43525b895f
//sec:NDJkYTViZTJiMTdjZjllMjNlYmNhODU2
void MainWindow::dealhttp_xf()
{
QByteArray data = reply_xf->readAll();//读出数据
QString _data =data;
reply_xf->deleteLater();
int end = _data.indexOf("index");
int start =_data.indexOf("content");
int length = end -start;
QString answerstr = _data.mid(start+10,length-15);
answerstr=answerstr.replace("\\n","\n");
allwordcount =answerstr.length();
ui->allcount->setText(QString::number(allwordcount));
ui->textEdit_2->setText(answerstr);
}
void MainWindow::dealhttp()
{
QByteArray data = reply->readAll();//读出数据
QString _data =data;
reply->deleteLater();
int end = _data.indexOf("model");
int start =_data.indexOf("content");
int length = end -start;
QString answerstr = _data.mid(start+10,length-16);
answerstr=answerstr.replace("\\n","\n");
qDebug()<< answerstr;
allwordcount =answerstr.length();
ui->allcount->setText(QString::number(allwordcount));
ui->textEdit_2->setText(answerstr);
}
void MainWindow::setlength(int length)
{
ui->allcount->setText(QString::number(length));
}
void MainWindow::setanswer(QString answer)
{
ui->textEdit_2