Skip to content

Commit

Permalink
feat: [ut] New plugin for unit test
Browse files Browse the repository at this point in the history
as title

Log: unit test plugin
  • Loading branch information
Kakueeen committed Jan 10, 2025
1 parent 99ada33 commit 5fefbcb
Show file tree
Hide file tree
Showing 56 changed files with 4,118 additions and 106 deletions.
16 changes: 15 additions & 1 deletion src/base/ai/abstractllm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@
#include "abstractllm.h"

AbstractLLM::AbstractLLM(QObject *parent)
: QObject(parent)
: QObject(parent)
{
qRegisterMetaType<ResponseState>("ResponseState");
}

void AbstractLLM::setModelState(ModelState st)
{
if (state.loadAcquire() == st)
return;

state.storeRelease(st);
Q_EMIT modelStateChanged();
}

AbstractLLM::ModelState AbstractLLM::modelState() const

Check warning on line 22 in src/base/ai/abstractllm.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'modelState' is never used.

Check warning on line 22 in src/base/ai/abstractllm.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'modelState' is never used.
{
return static_cast<ModelState>(state.loadAcquire());
}
18 changes: 15 additions & 3 deletions src/base/ai/abstractllm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class AbstractLLM : public QObject
Canceled
};

enum ModelState {
Idle = 0,
Busy
};

using ResponseHandler = std::function<void(const QString &data, ResponseState state)>;

explicit AbstractLLM(QObject *parent = nullptr);
virtual ~AbstractLLM() {}

Expand All @@ -30,18 +37,23 @@ class AbstractLLM : public QObject
virtual bool checkValid(QString *errStr) = 0;
virtual QJsonObject create(const Conversation &conversation) = 0;
virtual void request(const QJsonObject &data) = 0;
virtual void request(const QString &prompt) = 0;
virtual void request(const QString &prompt, ResponseHandler handler = nullptr) = 0;
virtual void generate(const QString &prompt, const QString &suffix) = 0;
virtual void setTemperature(double temperature) = 0;
virtual void setStream(bool isStream) = 0;
virtual void processResponse(QNetworkReply *reply) = 0;
virtual void cancel() = 0;
virtual void setMaxTokens(int maxToken) = 0;
virtual Conversation *getCurrentConversation() = 0;
virtual bool isIdle() = 0;

void setModelState(ModelState st);
ModelState modelState() const;

signals:
void dataReceived(const QString &data, ResponseState statu);
void modelStateChanged();

private:
QAtomicInt state { Idle };
};

#endif
85 changes: 85 additions & 0 deletions src/common/util/spinnerpainter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "spinnerpainter.h"

#include <QtMath>

Check warning on line 7 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtMath> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 7 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QtMath> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPainterPath>

Check warning on line 8 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainterPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QPainterPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.

SpinnerPainter::SpinnerPainter()
{
refreshTimer.setInterval(30);
QObject::connect(&refreshTimer, &QTimer::timeout, &refreshTimer,
[=]() {
currentDegree += 14;
callback();
});
}

void SpinnerPainter::paint(QPainter &painter, const QColor &color, const QRect &rect)
{
painter.save();
if (currentColor != color) {
currentColor = color;
indicatorColors.clear();
}

if (indicatorColors.isEmpty()) {
for (int i = 0; i < 3; ++i)
indicatorColors << createDefaultIndicatorColorList(color);
}

painter.setRenderHints(QPainter::Antialiasing);
auto center = QRectF(rect).center();
auto radius = qMin(rect.width(), rect.height()) / 2.0;
auto indicatorRadius = radius / 2 / 2 * 1.1;
auto indicatorDegreeDelta = 360 / indicatorColors.count();

for (int i = 0; i < indicatorColors.count(); ++i) {
auto colors = indicatorColors.value(i);
for (int j = 0; j < colors.count(); ++j) {
double degreeCurrent = currentDegree - j * indicatorShadowOffset + indicatorDegreeDelta * i;
auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent));
auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent));

x = center.x() + x;
y = center.y() + y;
auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius);
QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2);

QPainterPath path;
path.addEllipse(rf);

painter.fillPath(path, colors.value(j));
}
}
painter.restore();
}

void SpinnerPainter::setUpdateCallback(const UpdateCallback &cb)
{
callback = cb;
}

void SpinnerPainter::startAnimation()
{
refreshTimer.start();
}

void SpinnerPainter::stopAnimation()

Check warning on line 70 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'stopAnimation' is never used.

Check warning on line 70 in src/common/util/spinnerpainter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'stopAnimation' is never used.
{
refreshTimer.stop();
}

QList<QColor> SpinnerPainter::createDefaultIndicatorColorList(QColor color)
{
QList<QColor> colors;
QList<int> opacitys;
opacitys << 100 << 30 << 15 << 10 << 5 << 4 << 3 << 2 << 1;
for (int i = 0; i < opacitys.count(); ++i) {
color.setAlpha(255 * opacitys.value(i) / 100);
colors << color;
}
return colors;
}
40 changes: 40 additions & 0 deletions src/common/util/spinnerpainter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef SPINNERPAINTER_H
#define SPINNERPAINTER_H

#include <QPainter>

Check warning on line 8 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 9 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <functional>

Check warning on line 11 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <functional> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/common/util/spinnerpainter.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <functional> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class SpinnerPainter
{
public:
SpinnerPainter();

void paint(QPainter &painter, const QColor &color, const QRect &rect);

using UpdateCallback = std::function<void()>;
void setUpdateCallback(const UpdateCallback &cb);

void startAnimation();
void stopAnimation();

protected:
QList<QColor> createDefaultIndicatorColorList(QColor color);

private:
QTimer refreshTimer;

double indicatorShadowOffset = 10;
double currentDegree = 0.0;

QList<QList<QColor>> indicatorColors;
QColor currentColor;
UpdateCallback callback;
};

#endif // SPINNERPAINTER_H
1 change: 1 addition & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ add_subdirectory(codegeex)
add_subdirectory(git)
add_subdirectory(linglong)
add_subdirectory(aimanager)
add_subdirectory(smartut)
4 changes: 2 additions & 2 deletions src/plugins/aimanager/aiplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ bool AiPlugin::start()

auto optionService = dpfGetService(dpfservice::OptionService);
if (optionService) {
// TODO:uncomment the code when everything is ok
// optionService->implGenerator<OptionCustomModelsGenerator>(option::GROUP_AI, OptionCustomModelsGenerator::kitName());
// TODO:uncomment the code when everything is ok
optionService->implGenerator<OptionCustomModelsGenerator>(option::GROUP_AI, OptionCustomModelsGenerator::kitName());
}

return true;
Expand Down
Loading

0 comments on commit 5fefbcb

Please sign in to comment.