Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add create session proccess #75

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions assets/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,12 @@
<context>
<name>CodeEditComponent</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="143"/>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="150"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="147"/>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="154"/>
<source>Insert</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -591,35 +591,40 @@
<context>
<name>CodeGeeXWidget</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="64"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="70"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="97"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="100"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="100"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="103"/>
<source>History</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="103"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="106"/>
<source>New</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="117"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="120"/>
<source>Ask CodeGeeX</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="118"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="121"/>
<source>Translation</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="144"/>
<source>Creating a new session...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CodeLens</name>
Expand Down Expand Up @@ -936,12 +941,6 @@ The dap port is not ready, please retry.
<source>Choose path</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/option/detailwidget.cpp" line="93"/>
<location filename="../../src/plugins/codegeex/option/detailwidget.cpp" line="100"/>
<source>Detail</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DetailsButton</name>
Expand Down Expand Up @@ -1376,38 +1375,38 @@ repos path: %0</source>
<context>
<name>MainDialog</name>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="59"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="58"/>
<source>New File or Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="61"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="60"/>
<source>Choose a template:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="73"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="72"/>
<source>Templates</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="157"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="156"/>
<source>Create</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="158"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="157"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="194"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="207"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="193"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="206"/>
<source>Tip</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="207"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="206"/>
<source>Can not find kit.</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -3593,7 +3592,7 @@ Delete anyway?</source>
<context>
<name>WindowKeeper</name>
<message>
<location filename="../../src/plugins/core/mainframe/windowkeeper.cpp" line="242"/>
<location filename="../../src/plugins/core/mainframe/windowkeeper.cpp" line="243"/>
<source>Deepin Union Code</source>
<translation type="unfinished"></translation>
</message>
Expand Down
45 changes: 22 additions & 23 deletions assets/translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@
<context>
<name>CodeEditComponent</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="143"/>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="150"/>
<source>Copy</source>
<translation>复制</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="147"/>
<location filename="../../src/plugins/codegeex/widgets/codeeditcomponent.cpp" line="154"/>
<source>Insert</source>
<translation>插入</translation>
</message>
Expand Down Expand Up @@ -603,35 +603,40 @@
<context>
<name>CodeGeeXWidget</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="64"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="70"/>
<source>Login</source>
<translation>登录</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="97"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="100"/>
<source>Delete</source>
<translation>删除</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="100"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="103"/>
<source>History</source>
<translation>历史记录</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="103"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="106"/>
<source>New</source>
<translation>新对话</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="117"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="120"/>
<source>Ask CodeGeeX</source>
<translation>询问 CodeGeeX</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="118"/>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="121"/>
<source>Translation</source>
<translation>翻译代码</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/codegeexwidget.cpp" line="144"/>
<source>Creating a new session...</source>
<translation>创建新的会话中...</translation>
</message>
</context>
<context>
<name>CodeLens</name>
Expand Down Expand Up @@ -960,12 +965,6 @@ dap端口未就绪,请重试。
<source>Choose path</source>
<translation>选择路径</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/option/detailwidget.cpp" line="93"/>
<location filename="../../src/plugins/codegeex/option/detailwidget.cpp" line="100"/>
<source>Detail</source>
<translation>细节</translation>
</message>
</context>
<context>
<name>DetailsButton</name>
Expand Down Expand Up @@ -1401,38 +1400,38 @@ repos path: %0</source>
<context>
<name>MainDialog</name>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="59"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="58"/>
<source>New File or Project</source>
<translation>新建文件或工程</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="61"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="60"/>
<source>Choose a template:</source>
<translation>选择一个模板:</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="73"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="72"/>
<source>Templates</source>
<translation>模板</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="157"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="156"/>
<source>Create</source>
<translation>创建</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="158"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="157"/>
<source>Cancel</source>
<translation>取消</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="194"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="207"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="193"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="206"/>
<source>Tip</source>
<translation>提示</translation>
</message>
<message>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="207"/>
<location filename="../../src/plugins/template/wizard/maindialog.cpp" line="206"/>
<source>Can not find kit.</source>
<translation>找不到配套工具。</translation>
</message>
Expand Down Expand Up @@ -3635,7 +3634,7 @@ Delete anyway?</source>
<context>
<name>WindowKeeper</name>
<message>
<location filename="../../src/plugins/core/mainframe/windowkeeper.cpp" line="242"/>
<location filename="../../src/plugins/core/mainframe/windowkeeper.cpp" line="243"/>
<source>Deepin Union Code</source>
<translation></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codegeex/codegeex.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/demo">
<qresource prefix="/resoures">
<file>images/navigation.png</file>
<file>images/logo-codegeex.png</file>
<file>images/photo.svg</file>
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

static const char *kUrlSSEChat = "https://codegeex.cn/prod/code/chatGlmSse/chat";
static const char *kUrlNewSession = "https://codegeex.cn/prod/code/chatGlmTalk/insert";
static const char *kUrlDeleteSession = "https://codegeex.cn/prod/code/chatGlmTalk/delete";

using namespace CodeGeeX;

Expand Down Expand Up @@ -71,6 +72,23 @@ void CodeGeeXManager::loadConfig()
}
}

void CodeGeeXManager::createNewSession()
{
QString currentMSecsStr = QString::number(QDateTime::currentMSecsSinceEpoch());
QString sessionTitle("Session_" + currentMSecsStr);
QString taskId(uuid());
askApi.postNewSession(kUrlNewSession, sessionId, sessionTitle, taskId);
}

void CodeGeeXManager::deleteCurrentSession()
{
if (currentTalkID.isEmpty())
return;

askApi.deleteSessions(kUrlDeleteSession, sessionId, { currentTalkID });
createNewSession();
}

void CodeGeeXManager::sendMessage(const QString &prompt)
{
QString askId = "User" + QString::number(QDateTime::currentMSecsSinceEpoch());
Expand All @@ -86,6 +104,16 @@ void CodeGeeXManager::sendMessage(const QString &prompt)
askApi.postSSEChat(kUrlSSEChat, sessionId, prompt, machineId, history);
}

void CodeGeeXManager::onSessionCreated(const QString &talkId, bool isSuccessful)
{
if (isSuccessful) {
currentTalkID = talkId;
Q_EMIT createdNewSession();
} else {
qWarning() << "Create session failed!";
}
}

void CodeGeeXManager::onResponse(const QString &msgID, const QString &data, const QString &event)
{
if (msgID.isEmpty())
Expand Down Expand Up @@ -129,6 +157,7 @@ void CodeGeeXManager::initConnections()
{
connect(&askApi, &AskApi::response, this, &CodeGeeXManager::onResponse);
connect(&askApi, &AskApi::loginState, this, &CodeGeeXManager::recevieLoginState);
connect(&askApi, &AskApi::sessionCreated, this, &CodeGeeXManager::onSessionCreated);
}

void CodeGeeXManager::queryLoginState()
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/codegeex/codegeexmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ class CodeGeeXManager : public QObject
void saveConfig(const QString &sessionId, const QString &userId);
void loadConfig();

void createNewSession();
void deleteCurrentSession();

void sendMessage(const QString &prompt);
void queryLoginState();

void cleanHistoryMessage();

Q_SIGNALS:
void loginSuccessed();
void createdNewSession();
void requestMessageUpdate(const MessageData &msg);

public Q_SLOTS:
void onSessionCreated(const QString &talkId, bool isSuccessful);
void onResponse(const QString &msgID, const QString &data, const QString &event);
void recevieLoginState(CodeGeeX::AskApi::LoginState loginState);

Expand All @@ -48,8 +53,9 @@ public Q_SLOTS:
QString uuid();

CodeGeeX::AskApi askApi;
QString sessionId;
QString userId;
QString sessionId {};
QString userId {};
QString currentTalkID {};

QMap<QString, MessageData> curSessionMsg {};

Expand Down
7 changes: 7 additions & 0 deletions src/plugins/codegeex/widgets/codeeditcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <QPlainTextEdit>
#include <QLabel>
#include <QDebug>
#include <QApplication>
#include <QClipboard>
#include <QMimeData>

CodeEditComponent::CodeEditComponent(QWidget *parent)
: QWidget (parent)
Expand Down Expand Up @@ -116,6 +119,10 @@ void CodeEditComponent::onCopyBtnClicked()

if (codeEdit->toPlainText().isEmpty())
return;

QClipboard *clipboard = QApplication::clipboard();
clipboard->setMimeData(new QMimeData);
clipboard->setText(codeEdit->toPlainText());
}

void CodeEditComponent::initUI()
Expand Down
Loading