mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
chore: Run clang-format over the codebase (#82)
This commit is a result of the following commands: clang-format-19 --style=file -i $(git ls-files | fgrep .cpp) clang-format-19 --style=file -i $(git ls-files | fgrep .hpp)
This commit is contained in:
parent
102bb114a1
commit
61196cae90
@ -18,9 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ChatModel.hpp"
|
#include "ChatModel.hpp"
|
||||||
|
#include <utils/aspects.h>
|
||||||
#include <QtCore/qjsonobject.h>
|
#include <QtCore/qjsonobject.h>
|
||||||
#include <QtQml>
|
#include <QtQml>
|
||||||
#include <utils/aspects.h>
|
|
||||||
|
|
||||||
#include "ChatAssistantSettings.hpp"
|
#include "ChatAssistantSettings.hpp"
|
||||||
|
|
||||||
@ -31,10 +31,11 @@ ChatModel::ChatModel(QObject *parent)
|
|||||||
{
|
{
|
||||||
auto &settings = Settings::chatAssistantSettings();
|
auto &settings = Settings::chatAssistantSettings();
|
||||||
|
|
||||||
connect(&settings.chatTokensThreshold,
|
connect(
|
||||||
&Utils::BaseAspect::changed,
|
&settings.chatTokensThreshold,
|
||||||
this,
|
&Utils::BaseAspect::changed,
|
||||||
&ChatModel::tokensThresholdChanged);
|
this,
|
||||||
|
&ChatModel::tokensThresholdChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChatModel::rowCount(const QModelIndex &parent) const
|
int ChatModel::rowCount(const QModelIndex &parent) const
|
||||||
@ -127,7 +128,8 @@ QList<MessagePart> ChatModel::processMessageContent(const QString &content) cons
|
|||||||
while (blockMatches.hasNext()) {
|
while (blockMatches.hasNext()) {
|
||||||
auto match = blockMatches.next();
|
auto match = blockMatches.next();
|
||||||
if (match.capturedStart() > lastIndex) {
|
if (match.capturedStart() > lastIndex) {
|
||||||
QString textBetween = content.mid(lastIndex, match.capturedStart() - lastIndex).trimmed();
|
QString textBetween
|
||||||
|
= content.mid(lastIndex, match.capturedStart() - lastIndex).trimmed();
|
||||||
if (!textBetween.isEmpty()) {
|
if (!textBetween.isEmpty()) {
|
||||||
parts.append({MessagePart::Text, textBetween, ""});
|
parts.append({MessagePart::Text, textBetween, ""});
|
||||||
}
|
}
|
||||||
|
@ -24,21 +24,21 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
|
|
||||||
#include "ChatAssistantSettings.hpp"
|
#include "ChatAssistantSettings.hpp"
|
||||||
#include "ChatSerializer.hpp"
|
#include "ChatSerializer.hpp"
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
#include "ProjectSettings.hpp"
|
#include "ProjectSettings.hpp"
|
||||||
#include "context/TokenUtils.hpp"
|
|
||||||
#include "context/ContextManager.hpp"
|
#include "context/ContextManager.hpp"
|
||||||
|
#include "context/TokenUtils.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
@ -48,18 +48,16 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
, m_clientInterface(new ClientInterface(m_chatModel, this))
|
, m_clientInterface(new ClientInterface(m_chatModel, this))
|
||||||
{
|
{
|
||||||
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
||||||
connect(&Settings::chatAssistantSettings().linkOpenFiles, &Utils::BaseAspect::changed,
|
connect(
|
||||||
this,
|
&Settings::chatAssistantSettings().linkOpenFiles,
|
||||||
[this](){
|
&Utils::BaseAspect::changed,
|
||||||
setIsSyncOpenFiles(Settings::chatAssistantSettings().linkOpenFiles());
|
this,
|
||||||
});
|
[this]() { setIsSyncOpenFiles(Settings::chatAssistantSettings().linkOpenFiles()); });
|
||||||
|
|
||||||
auto &settings = Settings::generalSettings();
|
auto &settings = Settings::generalSettings();
|
||||||
|
|
||||||
connect(&settings.caModel,
|
connect(
|
||||||
&Utils::BaseAspect::changed,
|
&settings.caModel, &Utils::BaseAspect::changed, this, &ChatRootView::currentTemplateChanged);
|
||||||
this,
|
|
||||||
&ChatRootView::currentTemplateChanged);
|
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
m_clientInterface,
|
m_clientInterface,
|
||||||
@ -76,10 +74,16 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
connect(m_chatModel, &ChatModel::modelReseted, this, [this]() { setRecentFilePath(QString{}); });
|
connect(m_chatModel, &ChatModel::modelReseted, this, [this]() { setRecentFilePath(QString{}); });
|
||||||
connect(this, &ChatRootView::attachmentFilesChanged, &ChatRootView::updateInputTokensCount);
|
connect(this, &ChatRootView::attachmentFilesChanged, &ChatRootView::updateInputTokensCount);
|
||||||
connect(this, &ChatRootView::linkedFilesChanged, &ChatRootView::updateInputTokensCount);
|
connect(this, &ChatRootView::linkedFilesChanged, &ChatRootView::updateInputTokensCount);
|
||||||
connect(&Settings::chatAssistantSettings().useSystemPrompt, &Utils::BaseAspect::changed,
|
connect(
|
||||||
this, &ChatRootView::updateInputTokensCount);
|
&Settings::chatAssistantSettings().useSystemPrompt,
|
||||||
connect(&Settings::chatAssistantSettings().systemPrompt, &Utils::BaseAspect::changed,
|
&Utils::BaseAspect::changed,
|
||||||
this, &ChatRootView::updateInputTokensCount);
|
this,
|
||||||
|
&ChatRootView::updateInputTokensCount);
|
||||||
|
connect(
|
||||||
|
&Settings::chatAssistantSettings().systemPrompt,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::updateInputTokensCount);
|
||||||
|
|
||||||
auto editors = Core::EditorManager::instance();
|
auto editors = Core::EditorManager::instance();
|
||||||
|
|
||||||
@ -450,7 +454,7 @@ void ChatRootView::openChatHistoryFolder()
|
|||||||
void ChatRootView::updateInputTokensCount()
|
void ChatRootView::updateInputTokensCount()
|
||||||
{
|
{
|
||||||
int inputTokens = m_messageTokensCount;
|
int inputTokens = m_messageTokensCount;
|
||||||
auto& settings = Settings::chatAssistantSettings();
|
auto &settings = Settings::chatAssistantSettings();
|
||||||
|
|
||||||
if (settings.useSystemPrompt()) {
|
if (settings.useSystemPrompt()) {
|
||||||
inputTokens += Context::TokenUtils::estimateTokens(settings.systemPrompt());
|
inputTokens += Context::TokenUtils::estimateTokens(settings.systemPrompt());
|
||||||
@ -466,8 +470,8 @@ void ChatRootView::updateInputTokensCount()
|
|||||||
inputTokens += Context::TokenUtils::estimateFilesTokens(linkFiles);
|
inputTokens += Context::TokenUtils::estimateFilesTokens(linkFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& history = m_chatModel->getChatHistory();
|
const auto &history = m_chatModel->getChatHistory();
|
||||||
for (const auto& message : history) {
|
for (const auto &message : history) {
|
||||||
inputTokens += Context::TokenUtils::estimateTokens(message.content);
|
inputTokens += Context::TokenUtils::estimateTokens(message.content);
|
||||||
inputTokens += 4; // + role
|
inputTokens += 4; // + role
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,4 @@ void ChatWidget::scrollToBottom()
|
|||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(rootObject(), "scrollToBottom");
|
QMetaObject::invokeMethod(rootObject(), "scrollToBottom");
|
||||||
}
|
}
|
||||||
}
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -38,4 +38,4 @@ signals:
|
|||||||
void clearPressed();
|
void clearPressed();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
#include "ClientInterface.hpp"
|
#include "ClientInterface.hpp"
|
||||||
|
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <texteditor/textdocument.h>
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
@ -46,21 +46,23 @@ ClientInterface::ClientInterface(ChatModel *chatModel, QObject *parent)
|
|||||||
, m_requestHandler(new LLMCore::RequestHandler(this))
|
, m_requestHandler(new LLMCore::RequestHandler(this))
|
||||||
, m_chatModel(chatModel)
|
, m_chatModel(chatModel)
|
||||||
{
|
{
|
||||||
connect(m_requestHandler,
|
connect(
|
||||||
&LLMCore::RequestHandler::completionReceived,
|
m_requestHandler,
|
||||||
this,
|
&LLMCore::RequestHandler::completionReceived,
|
||||||
[this](const QString &completion, const QJsonObject &request, bool isComplete) {
|
this,
|
||||||
handleLLMResponse(completion, request, isComplete);
|
[this](const QString &completion, const QJsonObject &request, bool isComplete) {
|
||||||
});
|
handleLLMResponse(completion, request, isComplete);
|
||||||
|
});
|
||||||
|
|
||||||
connect(m_requestHandler,
|
connect(
|
||||||
&LLMCore::RequestHandler::requestFinished,
|
m_requestHandler,
|
||||||
this,
|
&LLMCore::RequestHandler::requestFinished,
|
||||||
[this](const QString &, bool success, const QString &errorString) {
|
this,
|
||||||
if (!success) {
|
[this](const QString &, bool success, const QString &errorString) {
|
||||||
emit errorOccurred(errorString);
|
if (!success) {
|
||||||
}
|
emit errorOccurred(errorString);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientInterface::~ClientInterface() = default;
|
ClientInterface::~ClientInterface() = default;
|
||||||
@ -149,9 +151,8 @@ void ClientInterface::cancelRequest()
|
|||||||
m_requestHandler->cancelRequest(id);
|
m_requestHandler->cancelRequest(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientInterface::handleLLMResponse(const QString &response,
|
void ClientInterface::handleLLMResponse(
|
||||||
const QJsonObject &request,
|
const QString &response, const QJsonObject &request, bool isComplete)
|
||||||
bool isComplete)
|
|
||||||
{
|
{
|
||||||
const auto message = response.trimmed();
|
const auto message = response.trimmed();
|
||||||
|
|
||||||
@ -191,7 +192,8 @@ QString ClientInterface::getCurrentFileContext() const
|
|||||||
return QString("Current file context:\n%1\nFile content:\n%2").arg(fileInfo, content);
|
return QString("Current file context:\n%1\nFile content:\n%2").arg(fileInfo, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ClientInterface::getSystemPromptWithLinkedFiles(const QString &basePrompt, const QList<QString> &linkedFiles) const
|
QString ClientInterface::getSystemPromptWithLinkedFiles(
|
||||||
|
const QString &basePrompt, const QList<QString> &linkedFiles) const
|
||||||
{
|
{
|
||||||
QString updatedPrompt = basePrompt;
|
QString updatedPrompt = basePrompt;
|
||||||
|
|
||||||
@ -200,8 +202,7 @@ QString ClientInterface::getSystemPromptWithLinkedFiles(const QString &basePromp
|
|||||||
|
|
||||||
auto contentFiles = Context::ContextManager::instance().getContentFiles(linkedFiles);
|
auto contentFiles = Context::ContextManager::instance().getContentFiles(linkedFiles);
|
||||||
for (const auto &file : contentFiles) {
|
for (const auto &file : contentFiles) {
|
||||||
updatedPrompt += QString("\nFile: %1\nContent:\n%2\n")
|
updatedPrompt += QString("\nFile: %1\nContent:\n%2\n").arg(file.filename, file.content);
|
||||||
.arg(file.filename, file.content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ private:
|
|||||||
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
||||||
QString getCurrentFileContext() const;
|
QString getCurrentFileContext() const;
|
||||||
QString getSystemPromptWithLinkedFiles(
|
QString getSystemPromptWithLinkedFiles(
|
||||||
const QString &basePrompt,
|
const QString &basePrompt, const QList<QString> &linkedFiles) const;
|
||||||
const QList<QString> &linkedFiles) const;
|
|
||||||
|
|
||||||
LLMCore::RequestHandler *m_requestHandler;
|
LLMCore::RequestHandler *m_requestHandler;
|
||||||
ChatModel *m_chatModel;
|
ChatModel *m_chatModel;
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include "ConfigurationManager.hpp"
|
#include "ConfigurationManager.hpp"
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
#include <settings/ButtonAspect.hpp>
|
#include <settings/ButtonAspect.hpp>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "QodeAssisttr.h"
|
#include "QodeAssisttr.h"
|
||||||
|
|
||||||
@ -111,10 +111,8 @@ void ConfigurationManager::selectProvider()
|
|||||||
: m_generalSettings.caProvider;
|
: m_generalSettings.caProvider;
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [this, providersList, &targetSettings] {
|
QTimer::singleShot(0, this, [this, providersList, &targetSettings] {
|
||||||
m_generalSettings.showSelectionDialog(providersList,
|
m_generalSettings.showSelectionDialog(
|
||||||
targetSettings,
|
providersList, targetSettings, Tr::tr("Select LLM Provider"), Tr::tr("Providers:"));
|
||||||
Tr::tr("Select LLM Provider"),
|
|
||||||
Tr::tr("Providers:"));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +179,8 @@ void ConfigurationManager::selectTemplate()
|
|||||||
: m_generalSettings.caTemplate;
|
: m_generalSettings.caTemplate;
|
||||||
|
|
||||||
QTimer::singleShot(0, &m_generalSettings, [this, templateList, &targetSettings]() {
|
QTimer::singleShot(0, &m_generalSettings, [this, templateList, &targetSettings]() {
|
||||||
m_generalSettings.showSelectionDialog(templateList,
|
m_generalSettings.showSelectionDialog(
|
||||||
targetSettings,
|
templateList, targetSettings, Tr::tr("Select Template"), Tr::tr("Templates:"));
|
||||||
Tr::tr("Select Template"),
|
|
||||||
Tr::tr("Templates:"));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +40,11 @@ namespace QodeAssist {
|
|||||||
LLMClientInterface::LLMClientInterface()
|
LLMClientInterface::LLMClientInterface()
|
||||||
: m_requestHandler(this)
|
: m_requestHandler(this)
|
||||||
{
|
{
|
||||||
connect(&m_requestHandler,
|
connect(
|
||||||
&LLMCore::RequestHandler::completionReceived,
|
&m_requestHandler,
|
||||||
this,
|
&LLMCore::RequestHandler::completionReceived,
|
||||||
&LLMClientInterface::sendCompletionToClient);
|
this,
|
||||||
|
&LLMClientInterface::sendCompletionToClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath LLMClientInterface::serverDeviceTemplate() const
|
Utils::FilePath LLMClientInterface::serverDeviceTemplate() const
|
||||||
@ -204,10 +205,11 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
|||||||
|
|
||||||
QString systemPrompt;
|
QString systemPrompt;
|
||||||
if (completeSettings.useSystemPrompt())
|
if (completeSettings.useSystemPrompt())
|
||||||
systemPrompt.append(completeSettings.useUserMessageTemplateForCC()
|
systemPrompt.append(
|
||||||
&& promptTemplate->type() == LLMCore::TemplateType::Chat
|
completeSettings.useUserMessageTemplateForCC()
|
||||||
? completeSettings.systemPromptForNonFimModels()
|
&& promptTemplate->type() == LLMCore::TemplateType::Chat
|
||||||
: completeSettings.systemPrompt());
|
? completeSettings.systemPromptForNonFimModels()
|
||||||
|
: completeSettings.systemPrompt());
|
||||||
if (updatedContext.fileContext.has_value())
|
if (updatedContext.fileContext.has_value())
|
||||||
systemPrompt.append(updatedContext.fileContext.value());
|
systemPrompt.append(updatedContext.fileContext.value());
|
||||||
|
|
||||||
@ -243,8 +245,8 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
|||||||
m_requestHandler.sendLLMRequest(config, request);
|
m_requestHandler.sendLLMRequest(config, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLMCore::ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
|
LLMCore::ContextData LLMClientInterface::prepareContext(
|
||||||
const QStringView &accumulatedCompletion)
|
const QJsonObject &request, const QStringView &accumulatedCompletion)
|
||||||
{
|
{
|
||||||
QJsonObject params = request["params"].toObject();
|
QJsonObject params = request["params"].toObject();
|
||||||
QJsonObject doc = params["doc"].toObject();
|
QJsonObject doc = params["doc"].toObject();
|
||||||
@ -267,9 +269,8 @@ LLMCore::ContextData LLMClientInterface::prepareContext(const QJsonObject &reque
|
|||||||
return reader.prepareContext(lineNumber, cursorPosition);
|
return reader.prepareContext(lineNumber, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLMClientInterface::sendCompletionToClient(const QString &completion,
|
void LLMClientInterface::sendCompletionToClient(
|
||||||
const QJsonObject &request,
|
const QString &completion, const QJsonObject &request, bool isComplete)
|
||||||
bool isComplete)
|
|
||||||
{
|
{
|
||||||
bool isPreset1Active = Context::ContextManager::instance().isSpecifyCompletion(request);
|
bool isPreset1Active = Context::ContextManager::instance().isSpecifyCompletion(request);
|
||||||
|
|
||||||
@ -294,8 +295,8 @@ void LLMClientInterface::sendCompletionToClient(const QString &completion,
|
|||||||
QString processedCompletion
|
QString processedCompletion
|
||||||
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
||||||
&& Settings::codeCompletionSettings().smartProcessInstuctText()
|
&& Settings::codeCompletionSettings().smartProcessInstuctText()
|
||||||
? CodeHandler::processText(completion)
|
? CodeHandler::processText(completion)
|
||||||
: completion;
|
: completion;
|
||||||
|
|
||||||
completionItem[LanguageServerProtocol::textKey] = processedCompletion;
|
completionItem[LanguageServerProtocol::textKey] = processedCompletion;
|
||||||
QJsonObject range;
|
QJsonObject range;
|
||||||
@ -312,7 +313,8 @@ void LLMClientInterface::sendCompletionToClient(const QString &completion,
|
|||||||
QString("Completions: \n%1")
|
QString("Completions: \n%1")
|
||||||
.arg(QString::fromUtf8(QJsonDocument(completions).toJson(QJsonDocument::Indented))));
|
.arg(QString::fromUtf8(QJsonDocument(completions).toJson(QJsonDocument::Indented))));
|
||||||
|
|
||||||
LOG_MESSAGE(QString("Full response: \n%1")
|
LOG_MESSAGE(
|
||||||
|
QString("Full response: \n%1")
|
||||||
.arg(QString::fromUtf8(QJsonDocument(response).toJson(QJsonDocument::Indented))));
|
.arg(QString::fromUtf8(QJsonDocument(response).toJson(QJsonDocument::Indented))));
|
||||||
|
|
||||||
QString requestId = request["id"].toString();
|
QString requestId = request["id"].toString();
|
||||||
@ -336,9 +338,8 @@ void LLMClientInterface::endTimeMeasurement(const QString &requestId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLMClientInterface::logPerformance(const QString &requestId,
|
void LLMClientInterface::logPerformance(
|
||||||
const QString &operation,
|
const QString &requestId, const QString &operation, qint64 elapsedMs)
|
||||||
qint64 elapsedMs)
|
|
||||||
{
|
{
|
||||||
LOG_MESSAGE(QString("Performance: %1 %2 took %3 ms").arg(requestId, operation).arg(elapsedMs));
|
LOG_MESSAGE(QString("Performance: %1 %2 took %3 ms").arg(requestId, operation).arg(elapsedMs));
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,8 @@ public:
|
|||||||
|
|
||||||
Utils::FilePath serverDeviceTemplate() const override;
|
Utils::FilePath serverDeviceTemplate() const override;
|
||||||
|
|
||||||
void sendCompletionToClient(const QString &completion,
|
void sendCompletionToClient(
|
||||||
const QJsonObject &request,
|
const QString &completion, const QJsonObject &request, bool isComplete);
|
||||||
bool isComplete);
|
|
||||||
|
|
||||||
void handleCompletion(const QJsonObject &request);
|
void handleCompletion(const QJsonObject &request);
|
||||||
|
|
||||||
|
@ -68,9 +68,10 @@ class GetCompletionParams : public LanguageServerProtocol::JsonObject
|
|||||||
public:
|
public:
|
||||||
static constexpr LanguageServerProtocol::Key docKey{"doc"};
|
static constexpr LanguageServerProtocol::Key docKey{"doc"};
|
||||||
|
|
||||||
GetCompletionParams(const LanguageServerProtocol::TextDocumentIdentifier &document,
|
GetCompletionParams(
|
||||||
int version,
|
const LanguageServerProtocol::TextDocumentIdentifier &document,
|
||||||
const LanguageServerProtocol::Position &position)
|
int version,
|
||||||
|
const LanguageServerProtocol::Position &position)
|
||||||
{
|
{
|
||||||
setTextDocument(document);
|
setTextDocument(document);
|
||||||
setVersion(version);
|
setVersion(version);
|
||||||
|
@ -147,9 +147,10 @@ void QodeAssistClient::requestCompletions(TextEditor::TextEditorWidget *editor)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const FilePath filePath = editor->textDocument()->filePath();
|
const FilePath filePath = editor->textDocument()->filePath();
|
||||||
GetCompletionRequest request{{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
GetCompletionRequest request{
|
||||||
documentVersion(filePath),
|
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
||||||
Position(cursor.mainCursor())}};
|
documentVersion(filePath),
|
||||||
|
Position(cursor.mainCursor())}};
|
||||||
request.setResponseCallback([this, editor = QPointer<TextEditorWidget>(editor)](
|
request.setResponseCallback([this, editor = QPointer<TextEditorWidget>(editor)](
|
||||||
const GetCompletionRequest::Response &response) {
|
const GetCompletionRequest::Response &response) {
|
||||||
QTC_ASSERT(editor, return);
|
QTC_ASSERT(editor, return);
|
||||||
@ -188,8 +189,8 @@ void QodeAssistClient::scheduleRequest(TextEditor::TextEditorWidget *editor)
|
|||||||
it.value()->setProperty("cursorPosition", editor->textCursor().position());
|
it.value()->setProperty("cursorPosition", editor->textCursor().position());
|
||||||
it.value()->start(Settings::codeCompletionSettings().startSuggestionTimer());
|
it.value()->start(Settings::codeCompletionSettings().startSuggestionTimer());
|
||||||
}
|
}
|
||||||
void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &response,
|
void QodeAssistClient::handleCompletions(
|
||||||
TextEditor::TextEditorWidget *editor)
|
const GetCompletionRequest::Response &response, TextEditor::TextEditorWidget *editor)
|
||||||
{
|
{
|
||||||
if (response.error())
|
if (response.error())
|
||||||
log(*response.error());
|
log(*response.error());
|
||||||
@ -267,18 +268,13 @@ void QodeAssistClient::setupConnections()
|
|||||||
openDocument(textDocument);
|
openDocument(textDocument);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_documentOpenedConnection = connect(EditorManager::instance(),
|
m_documentOpenedConnection
|
||||||
&EditorManager::documentOpened,
|
= connect(EditorManager::instance(), &EditorManager::documentOpened, this, openDoc);
|
||||||
this,
|
m_documentClosedConnection = connect(
|
||||||
openDoc);
|
EditorManager::instance(), &EditorManager::documentClosed, this, [this](IDocument *document) {
|
||||||
m_documentClosedConnection = connect(EditorManager::instance(),
|
if (auto textDocument = qobject_cast<TextDocument *>(document))
|
||||||
&EditorManager::documentClosed,
|
closeDocument(textDocument);
|
||||||
this,
|
});
|
||||||
[this](IDocument *document) {
|
|
||||||
if (auto textDocument = qobject_cast<TextDocument *>(
|
|
||||||
document))
|
|
||||||
closeDocument(textDocument);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (IDocument *doc : DocumentModel::openedDocuments())
|
for (IDocument *doc : DocumentModel::openedDocuments())
|
||||||
openDoc(doc);
|
openDoc(doc);
|
||||||
|
@ -43,8 +43,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void scheduleRequest(TextEditor::TextEditorWidget *editor);
|
void scheduleRequest(TextEditor::TextEditorWidget *editor);
|
||||||
void handleCompletions(const GetCompletionRequest::Response &response,
|
void handleCompletions(
|
||||||
TextEditor::TextEditorWidget *editor);
|
const GetCompletionRequest::Response &response, TextEditor::TextEditorWidget *editor);
|
||||||
void cancelRunningRequest(TextEditor::TextEditorWidget *editor);
|
void cancelRunningRequest(TextEditor::TextEditorWidget *editor);
|
||||||
bool isEnabled(ProjectExplorer::Project *project) const;
|
bool isEnabled(ProjectExplorer::Project *project) const;
|
||||||
|
|
||||||
|
@ -23,16 +23,15 @@
|
|||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
NavigationPanel::NavigationPanel() {
|
NavigationPanel::NavigationPanel()
|
||||||
|
{
|
||||||
setDisplayName(tr("QodeAssist Chat"));
|
setDisplayName(tr("QodeAssist Chat"));
|
||||||
setPriority(500);
|
setPriority(500);
|
||||||
setId("QodeAssistChat");
|
setId("QodeAssistChat");
|
||||||
setActivationSequence(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_C));
|
setActivationSequence(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_C));
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationPanel::~NavigationPanel()
|
NavigationPanel::~NavigationPanel() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::NavigationView NavigationPanel::createWidget()
|
Core::NavigationView NavigationPanel::createWidget()
|
||||||
{
|
{
|
||||||
@ -42,4 +41,4 @@ Core::NavigationView NavigationPanel::createWidget()
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
@ -34,4 +34,4 @@ public:
|
|||||||
Core::NavigationView createWidget() override;
|
Core::NavigationView createWidget() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -30,17 +30,12 @@ ChangesManager &ChangesManager::instance()
|
|||||||
|
|
||||||
ChangesManager::ChangesManager()
|
ChangesManager::ChangesManager()
|
||||||
: QObject(nullptr)
|
: QObject(nullptr)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
ChangesManager::~ChangesManager()
|
ChangesManager::~ChangesManager() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangesManager::addChange(TextEditor::TextDocument *document,
|
void ChangesManager::addChange(
|
||||||
int position,
|
TextEditor::TextDocument *document, int position, int charsRemoved, int charsAdded)
|
||||||
int charsRemoved,
|
|
||||||
int charsAdded)
|
|
||||||
{
|
{
|
||||||
auto &documentQueue = m_documentChanges[document];
|
auto &documentQueue = m_documentChanges[document];
|
||||||
|
|
||||||
@ -51,9 +46,10 @@ void ChangesManager::addChange(TextEditor::TextDocument *document,
|
|||||||
|
|
||||||
ChangeInfo change{fileName, lineNumber, lineContent};
|
ChangeInfo change{fileName, lineNumber, lineContent};
|
||||||
|
|
||||||
auto it = std::find_if(documentQueue.begin(),
|
auto it
|
||||||
documentQueue.end(),
|
= std::find_if(documentQueue.begin(), documentQueue.end(), [lineNumber](const ChangeInfo &c) {
|
||||||
[lineNumber](const ChangeInfo &c) { return c.lineNumber == lineNumber; });
|
return c.lineNumber == lineNumber;
|
||||||
|
});
|
||||||
|
|
||||||
if (it != documentQueue.end()) {
|
if (it != documentQueue.end()) {
|
||||||
it->lineContent = lineContent;
|
it->lineContent = lineContent;
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <texteditor/textdocument.h>
|
|
||||||
|
|
||||||
namespace QodeAssist::Context {
|
namespace QodeAssist::Context {
|
||||||
|
|
||||||
@ -41,10 +41,8 @@ public:
|
|||||||
|
|
||||||
static ChangesManager &instance();
|
static ChangesManager &instance();
|
||||||
|
|
||||||
void addChange(TextEditor::TextDocument *document,
|
void addChange(
|
||||||
int position,
|
TextEditor::TextDocument *document, int position, int charsRemoved, int charsAdded);
|
||||||
int charsRemoved,
|
|
||||||
int charsAdded);
|
|
||||||
QString getRecentChangesContext(const TextEditor::TextDocument *currentDocument) const;
|
QString getRecentChangesContext(const TextEditor::TextDocument *currentDocument) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
#include "DocumentContextReader.hpp"
|
#include "DocumentContextReader.hpp"
|
||||||
|
|
||||||
|
#include <languageserverprotocol/lsptypes.h>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <languageserverprotocol/lsptypes.h>
|
|
||||||
|
|
||||||
#include "CodeCompletionSettings.hpp"
|
#include "CodeCompletionSettings.hpp"
|
||||||
|
|
||||||
@ -41,9 +41,8 @@ const QRegularExpression &getNameRegex()
|
|||||||
|
|
||||||
const QRegularExpression &getCommentRegex()
|
const QRegularExpression &getCommentRegex()
|
||||||
{
|
{
|
||||||
static const QRegularExpression
|
static const QRegularExpression commentRegex(
|
||||||
commentRegex(R"((/\*[\s\S]*?\*/|//.*$|#.*$|//{2,}[\s\S]*?//{2,}))",
|
R"((/\*[\s\S]*?\*/|//.*$|#.*$|//{2,}[\s\S]*?//{2,}))", QRegularExpression::MultilineOption);
|
||||||
QRegularExpression::MultilineOption);
|
|
||||||
return commentRegex;
|
return commentRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +79,8 @@ QString DocumentContextReader::getLineText(int lineNumber, int cursorPosition) c
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DocumentContextReader::getContextBefore(int lineNumber,
|
QString DocumentContextReader::getContextBefore(
|
||||||
int cursorPosition,
|
int lineNumber, int cursorPosition, int linesCount) const
|
||||||
int linesCount) const
|
|
||||||
{
|
{
|
||||||
int effectiveStartLine;
|
int effectiveStartLine;
|
||||||
if (m_copyrightInfo.found) {
|
if (m_copyrightInfo.found) {
|
||||||
@ -94,9 +92,8 @@ QString DocumentContextReader::getContextBefore(int lineNumber,
|
|||||||
return getContextBetween(effectiveStartLine, lineNumber, cursorPosition);
|
return getContextBetween(effectiveStartLine, lineNumber, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DocumentContextReader::getContextAfter(int lineNumber,
|
QString DocumentContextReader::getContextAfter(
|
||||||
int cursorPosition,
|
int lineNumber, int cursorPosition, int linesCount) const
|
||||||
int linesCount) const
|
|
||||||
{
|
{
|
||||||
int endLine = qMin(m_document->blockCount() - 1, lineNumber + linesCount);
|
int endLine = qMin(m_document->blockCount() - 1, lineNumber + linesCount);
|
||||||
return getContextBetween(lineNumber + 1, endLine, cursorPosition);
|
return getContextBetween(lineNumber + 1, endLine, cursorPosition);
|
||||||
@ -179,9 +176,7 @@ CopyrightInfo DocumentContextReader::findCopyright()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DocumentContextReader::getContextBetween(int startLine,
|
QString DocumentContextReader::getContextBetween(int startLine, int endLine, int cursorPosition) const
|
||||||
int endLine,
|
|
||||||
int cursorPosition) const
|
|
||||||
{
|
{
|
||||||
QString context;
|
QString context;
|
||||||
for (int i = startLine; i <= endLine; ++i) {
|
for (int i = startLine; i <= endLine; ++i) {
|
||||||
@ -240,8 +235,9 @@ QString DocumentContextReader::getContextAfter(int lineNumber, int cursorPositio
|
|||||||
if (Settings::codeCompletionSettings().readFullFile()) {
|
if (Settings::codeCompletionSettings().readFullFile()) {
|
||||||
return readWholeFileAfter(lineNumber, cursorPosition);
|
return readWholeFileAfter(lineNumber, cursorPosition);
|
||||||
} else {
|
} else {
|
||||||
int endLine = qMin(m_document->blockCount() - 1,
|
int endLine = qMin(
|
||||||
lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor());
|
m_document->blockCount() - 1,
|
||||||
|
lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor());
|
||||||
return getContextBetween(lineNumber + 1, endLine, -1);
|
return getContextBetween(lineNumber + 1, endLine, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
namespace QodeAssist::Context {
|
namespace QodeAssist::Context {
|
||||||
|
|
||||||
int TokenUtils::estimateTokens(const QString& text)
|
int TokenUtils::estimateTokens(const QString &text)
|
||||||
{
|
{
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -31,7 +31,7 @@ int TokenUtils::estimateTokens(const QString& text)
|
|||||||
return text.length() / 4;
|
return text.length() / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TokenUtils::estimateFileTokens(const Context::ContentFile& file)
|
int TokenUtils::estimateFileTokens(const Context::ContentFile &file)
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
@ -42,13 +42,13 @@ int TokenUtils::estimateFileTokens(const Context::ContentFile& file)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TokenUtils::estimateFilesTokens(const QList<Context::ContentFile>& files)
|
int TokenUtils::estimateFilesTokens(const QList<Context::ContentFile> &files)
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (const auto& file : files) {
|
for (const auto &file : files) {
|
||||||
total += estimateFileTokens(file);
|
total += estimateFileTokens(file);
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace QodeAssist::Context
|
||||||
|
@ -19,18 +19,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include "ContentFile.hpp"
|
#include "ContentFile.hpp"
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace QodeAssist::Context {
|
namespace QodeAssist::Context {
|
||||||
|
|
||||||
class TokenUtils
|
class TokenUtils
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int estimateTokens(const QString& text);
|
static int estimateTokens(const QString &text);
|
||||||
static int estimateFileTokens(const Context::ContentFile& file);
|
static int estimateFileTokens(const Context::ContentFile &file);
|
||||||
static int estimateFilesTokens(const QList<Context::ContentFile>& files);
|
static int estimateFilesTokens(const QList<Context::ContentFile> &files);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace QodeAssist::Context
|
||||||
|
@ -35,8 +35,7 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void registerTemplate()
|
void registerTemplate()
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<PromptTemplate, T>::value,
|
static_assert(std::is_base_of<PromptTemplate, T>::value, "T must inherit from PromptTemplate");
|
||||||
"T must inherit from PromptTemplate");
|
|
||||||
T *template_ptr = new T();
|
T *template_ptr = new T();
|
||||||
QString name = template_ptr->name();
|
QString name = template_ptr->name();
|
||||||
m_fimTemplates[name] = template_ptr;
|
m_fimTemplates[name] = template_ptr;
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include "Provider.hpp"
|
#include "Provider.hpp"
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
namespace QodeAssist::LLMCore {
|
namespace QodeAssist::LLMCore {
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QUrl>
|
|
||||||
#include "PromptTemplate.hpp"
|
#include "PromptTemplate.hpp"
|
||||||
#include "Provider.hpp"
|
#include "Provider.hpp"
|
||||||
#include "RequestType.hpp"
|
#include "RequestType.hpp"
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
namespace QodeAssist::LLMCore {
|
namespace QodeAssist::LLMCore {
|
||||||
|
|
||||||
|
@ -33,15 +33,16 @@ RequestHandler::RequestHandler(QObject *parent)
|
|||||||
void RequestHandler::sendLLMRequest(const LLMConfig &config, const QJsonObject &request)
|
void RequestHandler::sendLLMRequest(const LLMConfig &config, const QJsonObject &request)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE(QString("Sending request to llm: \nurl: %1\nRequest body:\n%2")
|
LOG_MESSAGE(QString("Sending request to llm: \nurl: %1\nRequest body:\n%2")
|
||||||
.arg(config.url.toString(),
|
.arg(
|
||||||
|
config.url.toString(),
|
||||||
QString::fromUtf8(
|
QString::fromUtf8(
|
||||||
QJsonDocument(config.providerRequest).toJson(QJsonDocument::Indented))));
|
QJsonDocument(config.providerRequest).toJson(QJsonDocument::Indented))));
|
||||||
|
|
||||||
QNetworkRequest networkRequest(config.url);
|
QNetworkRequest networkRequest(config.url);
|
||||||
config.provider->prepareNetworkRequest(networkRequest);
|
config.provider->prepareNetworkRequest(networkRequest);
|
||||||
|
|
||||||
QNetworkReply *reply = m_manager->post(networkRequest,
|
QNetworkReply *reply
|
||||||
QJsonDocument(config.providerRequest).toJson());
|
= m_manager->post(networkRequest, QJsonDocument(config.providerRequest).toJson());
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
LOG_MESSAGE("Error: Failed to create network reply");
|
LOG_MESSAGE("Error: Failed to create network reply");
|
||||||
return;
|
return;
|
||||||
@ -70,9 +71,8 @@ void RequestHandler::sendLLMRequest(const LLMConfig &config, const QJsonObject &
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestHandler::handleLLMResponse(QNetworkReply *reply,
|
void RequestHandler::handleLLMResponse(
|
||||||
const QJsonObject &request,
|
QNetworkReply *reply, const QJsonObject &request, const LLMConfig &config)
|
||||||
const LLMConfig &config)
|
|
||||||
{
|
{
|
||||||
QString &accumulatedResponse = m_accumulatedResponses[reply];
|
QString &accumulatedResponse = m_accumulatedResponses[reply];
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ void RequestHandler::handleLLMResponse(QNetworkReply *reply,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
auto cleanedCompletion = removeStopWords(accumulatedResponse,
|
auto cleanedCompletion
|
||||||
config.promptTemplate->stopWords());
|
= removeStopWords(accumulatedResponse, config.promptTemplate->stopWords());
|
||||||
|
|
||||||
emit completionReceived(cleanedCompletion, request, true);
|
emit completionReceived(cleanedCompletion, request, true);
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,7 @@ public:
|
|||||||
explicit RequestHandler(QObject *parent = nullptr);
|
explicit RequestHandler(QObject *parent = nullptr);
|
||||||
|
|
||||||
void sendLLMRequest(const LLMConfig &config, const QJsonObject &request);
|
void sendLLMRequest(const LLMConfig &config, const QJsonObject &request);
|
||||||
void handleLLMResponse(QNetworkReply *reply,
|
void handleLLMResponse(QNetworkReply *reply, const QJsonObject &request, const LLMConfig &config);
|
||||||
const QJsonObject &request,
|
|
||||||
const LLMConfig &config);
|
|
||||||
bool cancelRequest(const QString &id);
|
bool cancelRequest(const QString &id);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -52,10 +50,11 @@ private:
|
|||||||
QMap<QString, QNetworkReply *> m_activeRequests;
|
QMap<QString, QNetworkReply *> m_activeRequests;
|
||||||
QMap<QNetworkReply *, QString> m_accumulatedResponses;
|
QMap<QNetworkReply *, QString> m_accumulatedResponses;
|
||||||
|
|
||||||
bool processSingleLineCompletion(QNetworkReply *reply,
|
bool processSingleLineCompletion(
|
||||||
const QJsonObject &request,
|
QNetworkReply *reply,
|
||||||
const QString &accumulatedResponse,
|
const QJsonObject &request,
|
||||||
const LLMConfig &config);
|
const QString &accumulatedResponse,
|
||||||
|
const LLMConfig &config);
|
||||||
QString removeStopWords(const QStringView &completion, const QStringList &stopWords);
|
QString removeStopWords(const QStringView &completion, const QStringList &stopWords);
|
||||||
void removeCodeBlockWrappers(QString &response);
|
void removeCodeBlockWrappers(QString &response);
|
||||||
};
|
};
|
||||||
|
@ -112,9 +112,8 @@ bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString endpoint = reply->url().path();
|
const QString endpoint = reply->url().path();
|
||||||
auto messageType = endpoint == completionEndpoint()
|
auto messageType = endpoint == completionEndpoint() ? LLMCore::OllamaMessage::Type::Generate
|
||||||
? LLMCore::OllamaMessage::Type::Generate
|
: LLMCore::OllamaMessage::Type::Chat;
|
||||||
: LLMCore::OllamaMessage::Type::Chat;
|
|
||||||
|
|
||||||
auto message = LLMCore::OllamaMessage::fromJson(line, messageType);
|
auto message = LLMCore::OllamaMessage::fromJson(line, messageType);
|
||||||
if (message.hasError()) {
|
if (message.hasError()) {
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
class ButtonAspect : public Utils::BaseAspect
|
class ButtonAspect : public Utils::BaseAspect
|
||||||
{
|
{
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
#include "ChatAssistantSettings.hpp"
|
#include "ChatAssistantSettings.hpp"
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "SettingsConstants.hpp"
|
#include "SettingsConstants.hpp"
|
||||||
#include "SettingsTr.hpp"
|
#include "SettingsTr.hpp"
|
||||||
@ -195,10 +195,11 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
|
|
||||||
void ChatAssistantSettings::setupConnections()
|
void ChatAssistantSettings::setupConnections()
|
||||||
{
|
{
|
||||||
connect(&resetToDefaults,
|
connect(
|
||||||
&ButtonAspect::clicked,
|
&resetToDefaults,
|
||||||
this,
|
&ButtonAspect::clicked,
|
||||||
&ChatAssistantSettings::resetSettingsToDefaults);
|
this,
|
||||||
|
&ChatAssistantSettings::resetSettingsToDefaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatAssistantSettings::resetSettingsToDefaults()
|
void ChatAssistantSettings::resetSettingsToDefaults()
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
#include "CodeCompletionSettings.hpp"
|
#include "CodeCompletionSettings.hpp"
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "SettingsConstants.hpp"
|
#include "SettingsConstants.hpp"
|
||||||
#include "SettingsTr.hpp"
|
#include "SettingsTr.hpp"
|
||||||
@ -250,17 +250,18 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
contextGrid.addRow({Row{readFullFile}});
|
contextGrid.addRow({Row{readFullFile}});
|
||||||
contextGrid.addRow({Row{readFileParts, readStringsBeforeCursor, readStringsAfterCursor}});
|
contextGrid.addRow({Row{readFileParts, readStringsBeforeCursor, readStringsAfterCursor}});
|
||||||
|
|
||||||
auto contextItem = Column{Row{contextGrid, Stretch{1}},
|
auto contextItem = Column{
|
||||||
Row{useSystemPrompt, Stretch{1}},
|
Row{contextGrid, Stretch{1}},
|
||||||
Group{title(Tr::tr("Prompts for FIM models")),
|
Row{useSystemPrompt, Stretch{1}},
|
||||||
Column{systemPrompt}},
|
Group{title(Tr::tr("Prompts for FIM models")), Column{systemPrompt}},
|
||||||
Group{title(Tr::tr("Prompts for Non FIM models")),
|
Group{
|
||||||
Column{
|
title(Tr::tr("Prompts for Non FIM models")),
|
||||||
Row{useUserMessageTemplateForCC, Stretch{1}},
|
Column{
|
||||||
systemPromptForNonFimModels,
|
Row{useUserMessageTemplateForCC, Stretch{1}},
|
||||||
userMessageTemplateForCC,
|
systemPromptForNonFimModels,
|
||||||
}},
|
userMessageTemplateForCC,
|
||||||
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
}},
|
||||||
|
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
||||||
|
|
||||||
return Column{
|
return Column{
|
||||||
Row{Stretch{1}, resetToDefaults},
|
Row{Stretch{1}, resetToDefaults},
|
||||||
@ -297,10 +298,11 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
|
|
||||||
void CodeCompletionSettings::setupConnections()
|
void CodeCompletionSettings::setupConnections()
|
||||||
{
|
{
|
||||||
connect(&resetToDefaults,
|
connect(
|
||||||
&ButtonAspect::clicked,
|
&resetToDefaults,
|
||||||
this,
|
&ButtonAspect::clicked,
|
||||||
&CodeCompletionSettings::resetSettingsToDefaults);
|
this,
|
||||||
|
&CodeCompletionSettings::resetSettingsToDefaults);
|
||||||
|
|
||||||
connect(&readFullFile, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
connect(&readFullFile, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||||
if (readFullFile.volatileValue()) {
|
if (readFullFile.volatileValue()) {
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
|
|
||||||
#include "CustomPromptSettings.hpp"
|
#include "CustomPromptSettings.hpp"
|
||||||
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "SettingsConstants.hpp"
|
#include "SettingsConstants.hpp"
|
||||||
#include "SettingsTr.hpp"
|
#include "SettingsTr.hpp"
|
||||||
@ -86,30 +86,36 @@ CustomPromptSettings::CustomPromptSettings()
|
|||||||
|
|
||||||
setLayouter([this]() {
|
setLayouter([this]() {
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
return Column{Group{title(Tr::tr("Custom prompt for FIM model")),
|
return Column{Group{
|
||||||
Column{Row{customJsonLabel, Stretch{1}, resetToDefaults},
|
title(Tr::tr("Custom prompt for FIM model")),
|
||||||
Row{customJsonTemplate,
|
Column{
|
||||||
Column{saveCustomTemplateButton,
|
Row{customJsonLabel, Stretch{1}, resetToDefaults},
|
||||||
loadCustomTemplateButton,
|
Row{customJsonTemplate,
|
||||||
customJsonLegend,
|
Column{
|
||||||
Stretch{1}}}}}};
|
saveCustomTemplateButton,
|
||||||
|
loadCustomTemplateButton,
|
||||||
|
customJsonLegend,
|
||||||
|
Stretch{1}}}}}};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPromptSettings::setupConnection()
|
void CustomPromptSettings::setupConnection()
|
||||||
{
|
{
|
||||||
connect(&resetToDefaults,
|
connect(
|
||||||
&ButtonAspect::clicked,
|
&resetToDefaults,
|
||||||
this,
|
&ButtonAspect::clicked,
|
||||||
&CustomPromptSettings::resetSettingsToDefaults);
|
this,
|
||||||
connect(&saveCustomTemplateButton,
|
&CustomPromptSettings::resetSettingsToDefaults);
|
||||||
&ButtonAspect::clicked,
|
connect(
|
||||||
this,
|
&saveCustomTemplateButton,
|
||||||
&CustomPromptSettings::saveCustomTemplate);
|
&ButtonAspect::clicked,
|
||||||
connect(&loadCustomTemplateButton,
|
this,
|
||||||
&ButtonAspect::clicked,
|
&CustomPromptSettings::saveCustomTemplate);
|
||||||
this,
|
connect(
|
||||||
&CustomPromptSettings::loadCustomTemplate);
|
&loadCustomTemplateButton,
|
||||||
|
&ButtonAspect::clicked,
|
||||||
|
this,
|
||||||
|
&CustomPromptSettings::loadCustomTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPromptSettings::resetSettingsToDefaults()
|
void CustomPromptSettings::resetSettingsToDefaults()
|
||||||
@ -128,10 +134,8 @@ void CustomPromptSettings::resetSettingsToDefaults()
|
|||||||
|
|
||||||
void CustomPromptSettings::saveCustomTemplate()
|
void CustomPromptSettings::saveCustomTemplate()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(nullptr,
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
Tr::tr("Save JSON Template"),
|
nullptr, Tr::tr("Save JSON Template"), QString(), Tr::tr("JSON Files (*.json)"));
|
||||||
QString(),
|
|
||||||
Tr::tr("JSON Files (*.json)"));
|
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -140,22 +144,19 @@ void CustomPromptSettings::saveCustomTemplate()
|
|||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
out << customJsonTemplate.value();
|
out << customJsonTemplate.value();
|
||||||
file.close();
|
file.close();
|
||||||
QMessageBox::information(nullptr,
|
QMessageBox::information(
|
||||||
Tr::tr("Save Successful"),
|
nullptr,
|
||||||
Tr::tr("JSON template has been saved successfully."));
|
Tr::tr("Save Successful"),
|
||||||
|
Tr::tr("JSON template has been saved successfully."));
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(nullptr,
|
QMessageBox::critical(nullptr, Tr::tr("Save Failed"), Tr::tr("Failed to save JSON template."));
|
||||||
Tr::tr("Save Failed"),
|
|
||||||
Tr::tr("Failed to save JSON template."));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPromptSettings::loadCustomTemplate()
|
void CustomPromptSettings::loadCustomTemplate()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(nullptr,
|
QString fileName = QFileDialog::getOpenFileName(
|
||||||
Tr::tr("Load JSON Template"),
|
nullptr, Tr::tr("Load JSON Template"), QString(), Tr::tr("JSON Files (*.json)"));
|
||||||
QString(),
|
|
||||||
Tr::tr("JSON Files (*.json)"));
|
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -169,18 +170,16 @@ void CustomPromptSettings::loadCustomTemplate()
|
|||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonContent.toUtf8(), &parseError);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonContent.toUtf8(), &parseError);
|
||||||
if (parseError.error == QJsonParseError::NoError) {
|
if (parseError.error == QJsonParseError::NoError) {
|
||||||
customJsonTemplate.setVolatileValue(jsonContent);
|
customJsonTemplate.setVolatileValue(jsonContent);
|
||||||
QMessageBox::information(nullptr,
|
QMessageBox::information(
|
||||||
Tr::tr("Load Successful"),
|
nullptr,
|
||||||
Tr::tr("JSON template has been loaded successfully."));
|
Tr::tr("Load Successful"),
|
||||||
|
Tr::tr("JSON template has been loaded successfully."));
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(nullptr,
|
QMessageBox::critical(
|
||||||
Tr::tr("Invalid JSON"),
|
nullptr, Tr::tr("Invalid JSON"), Tr::tr("The selected file contains invalid JSON."));
|
||||||
Tr::tr("The selected file contains invalid JSON."));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(nullptr,
|
QMessageBox::critical(nullptr, Tr::tr("Load Failed"), Tr::tr("Failed to load JSON template."));
|
||||||
Tr::tr("Load Failed"),
|
|
||||||
Tr::tr("Failed to load JSON template."));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,16 +392,17 @@ void GeneralSettings::setupConnections()
|
|||||||
|
|
||||||
connect(&specifyPreset1, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
connect(&specifyPreset1, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||||
updatePreset1Visiblity(specifyPreset1.volatileValue());
|
updatePreset1Visiblity(specifyPreset1.volatileValue());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralSettings::resetPageToDefaults()
|
void GeneralSettings::resetPageToDefaults()
|
||||||
{
|
{
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
reply = QMessageBox::question(Core::ICore::dialogParent(),
|
reply = QMessageBox::question(
|
||||||
TrConstants::RESET_SETTINGS,
|
Core::ICore::dialogParent(),
|
||||||
TrConstants::CONFIRMATION,
|
TrConstants::RESET_SETTINGS,
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
TrConstants::CONFIRMATION,
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
if (reply == QMessageBox::Yes) {
|
if (reply == QMessageBox::Yes) {
|
||||||
resetAspect(enableQodeAssist);
|
resetAspect(enableQodeAssist);
|
||||||
|
@ -94,10 +94,11 @@ public:
|
|||||||
|
|
||||||
Utils::StringAspect caTemplateDescription{this};
|
Utils::StringAspect caTemplateDescription{this};
|
||||||
|
|
||||||
void showSelectionDialog(const QStringList &data,
|
void showSelectionDialog(
|
||||||
Utils::StringAspect &aspect,
|
const QStringList &data,
|
||||||
const QString &title = {},
|
Utils::StringAspect &aspect,
|
||||||
const QString &text = {});
|
const QString &title = {},
|
||||||
|
const QString &text = {});
|
||||||
|
|
||||||
void showModelsNotFoundDialog(Utils::StringAspect &aspect);
|
void showModelsNotFoundDialog(Utils::StringAspect &aspect);
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ namespace QodeAssist::Settings {
|
|||||||
namespace TrConstants {
|
namespace TrConstants {
|
||||||
inline const char *ENABLE_QODE_ASSIST = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Enable Qode Assist");
|
inline const char *ENABLE_QODE_ASSIST = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Enable Qode Assist");
|
||||||
inline const char *GENERAL = QT_TRANSLATE_NOOP("QtC::QodeAssist", "General");
|
inline const char *GENERAL = QT_TRANSLATE_NOOP("QtC::QodeAssist", "General");
|
||||||
inline const char *RESET_TO_DEFAULTS = QT_TRANSLATE_NOOP("QtC::QodeAssist",
|
inline const char *RESET_TO_DEFAULTS
|
||||||
"Reset Page to Defaults");
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Reset Page to Defaults");
|
||||||
inline const char *CHECK_UPDATE = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Check Update");
|
inline const char *CHECK_UPDATE = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Check Update");
|
||||||
inline const char *SELECT = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Select...");
|
inline const char *SELECT = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Select...");
|
||||||
inline const char *PROVIDER = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Provider:");
|
inline const char *PROVIDER = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Provider:");
|
||||||
@ -46,9 +46,8 @@ inline const char *ENABLE_CHAT = QT_TRANSLATE_NOOP(
|
|||||||
inline const char *CODE_COMPLETION = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Code Completion");
|
inline const char *CODE_COMPLETION = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Code Completion");
|
||||||
inline const char *CHAT_ASSISTANT = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Chat Assistant");
|
inline const char *CHAT_ASSISTANT = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Chat Assistant");
|
||||||
inline const char *RESET_SETTINGS = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Reset Settings");
|
inline const char *RESET_SETTINGS = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Reset Settings");
|
||||||
inline const char *CONFIRMATION
|
inline const char *CONFIRMATION = QT_TRANSLATE_NOOP(
|
||||||
= QT_TRANSLATE_NOOP("QtC::QodeAssist",
|
"QtC::QodeAssist", "Are you sure you want to reset all settings to default values?");
|
||||||
"Are you sure you want to reset all settings to default values?");
|
|
||||||
inline const char *CURRENT_TEMPLATE_DESCRIPTION
|
inline const char *CURRENT_TEMPLATE_DESCRIPTION
|
||||||
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Current template description:");
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Current template description:");
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utils/aspects.h>
|
||||||
|
#include <utils/layoutbuilder.h>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QtCore/qtimer.h>
|
#include <QtCore/qtimer.h>
|
||||||
#include <utils/aspects.h>
|
|
||||||
#include <utils/layoutbuilder.h>
|
|
||||||
|
|
||||||
namespace QodeAssist::Settings {
|
namespace QodeAssist::Settings {
|
||||||
|
|
||||||
@ -67,10 +67,11 @@ void resetAspect(AspectType &aspect)
|
|||||||
aspect.setVolatileValue(aspect.defaultValue());
|
aspect.setVolatileValue(aspect.defaultValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void initStringAspect(Utils::StringAspect &aspect,
|
inline void initStringAspect(
|
||||||
const Utils::Key &settingsKey,
|
Utils::StringAspect &aspect,
|
||||||
const QString &labelText,
|
const Utils::Key &settingsKey,
|
||||||
const QString &defaultValue)
|
const QString &labelText,
|
||||||
|
const QString &defaultValue)
|
||||||
{
|
{
|
||||||
aspect.setSettingsKey(settingsKey);
|
aspect.setSettingsKey(settingsKey);
|
||||||
aspect.setLabelText(labelText);
|
aspect.setLabelText(labelText);
|
||||||
|
@ -77,8 +77,8 @@ private:
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject processJsonTemplate(const QJsonObject &templateObj,
|
QJsonObject processJsonTemplate(
|
||||||
const LLMCore::ContextData &context) const
|
const QJsonObject &templateObj, const LLMCore::ContextData &context) const
|
||||||
{
|
{
|
||||||
QJsonObject result;
|
QJsonObject result;
|
||||||
for (auto it = templateObj.begin(); it != templateObj.end(); ++it) {
|
for (auto it = templateObj.begin(); it != templateObj.end(); ++it) {
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include "llmcore/PromptTemplate.hpp"
|
#include "llmcore/PromptTemplate.hpp"
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
namespace QodeAssist::Templates {
|
namespace QodeAssist::Templates {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user