mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
refactor: Decouple prompt template manager from their users (#115)
This makes it possible to test the user classes
This commit is contained in:
parent
b6f36d61ae
commit
98e1047bf1
@ -45,7 +45,8 @@ namespace QodeAssist::Chat {
|
|||||||
ChatRootView::ChatRootView(QQuickItem *parent)
|
ChatRootView::ChatRootView(QQuickItem *parent)
|
||||||
: QQuickItem(parent)
|
: QQuickItem(parent)
|
||||||
, m_chatModel(new ChatModel(this))
|
, m_chatModel(new ChatModel(this))
|
||||||
, m_clientInterface(new ClientInterface(m_chatModel, this))
|
, m_promptProvider(LLMCore::PromptTemplateManager::instance())
|
||||||
|
, m_clientInterface(new ClientInterface(m_chatModel, &m_promptProvider, this))
|
||||||
{
|
{
|
||||||
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
||||||
connect(
|
connect(
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "ChatModel.hpp"
|
#include "ChatModel.hpp"
|
||||||
#include "ClientInterface.hpp"
|
#include "ClientInterface.hpp"
|
||||||
|
#include "llmcore/PromptProviderChat.hpp"
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
@ -99,6 +100,7 @@ private:
|
|||||||
QString getSuggestedFileName() const;
|
QString getSuggestedFileName() const;
|
||||||
|
|
||||||
ChatModel *m_chatModel;
|
ChatModel *m_chatModel;
|
||||||
|
LLMCore::PromptProviderChat m_promptProvider;
|
||||||
ClientInterface *m_clientInterface;
|
ClientInterface *m_clientInterface;
|
||||||
QString m_currentTemplate;
|
QString m_currentTemplate;
|
||||||
QString m_recentFilePath;
|
QString m_recentFilePath;
|
||||||
|
@ -36,15 +36,16 @@
|
|||||||
#include "ContextManager.hpp"
|
#include "ContextManager.hpp"
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
#include "PromptTemplateManager.hpp"
|
|
||||||
#include "ProvidersManager.hpp"
|
#include "ProvidersManager.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
ClientInterface::ClientInterface(ChatModel *chatModel, QObject *parent)
|
ClientInterface::ClientInterface(
|
||||||
|
ChatModel *chatModel, LLMCore::IPromptProvider *promptProvider, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_requestHandler(new LLMCore::RequestHandler(this))
|
, m_requestHandler(new LLMCore::RequestHandler(this))
|
||||||
, m_chatModel(chatModel)
|
, m_chatModel(chatModel)
|
||||||
|
, m_promptProvider(promptProvider)
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
m_requestHandler,
|
m_requestHandler,
|
||||||
@ -86,8 +87,7 @@ void ClientInterface::sendMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto templateName = Settings::generalSettings().caTemplate();
|
auto templateName = Settings::generalSettings().caTemplate();
|
||||||
auto promptTemplate = LLMCore::PromptTemplateManager::instance().getChatTemplateByName(
|
auto promptTemplate = m_promptProvider->getTemplateByName(templateName);
|
||||||
templateName);
|
|
||||||
|
|
||||||
if (!promptTemplate) {
|
if (!promptTemplate) {
|
||||||
LOG_MESSAGE(QString("No template found with name: %1").arg(templateName));
|
LOG_MESSAGE(QString("No template found with name: %1").arg(templateName));
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "ChatModel.hpp"
|
#include "ChatModel.hpp"
|
||||||
#include "RequestHandler.hpp"
|
#include "RequestHandler.hpp"
|
||||||
|
#include "llmcore/IPromptProvider.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ class ClientInterface : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClientInterface(ChatModel *chatModel, QObject *parent = nullptr);
|
explicit ClientInterface(
|
||||||
|
ChatModel *chatModel, LLMCore::IPromptProvider *promptProvider, QObject *parent = nullptr);
|
||||||
~ClientInterface();
|
~ClientInterface();
|
||||||
|
|
||||||
void sendMessage(
|
void sendMessage(
|
||||||
@ -53,8 +55,9 @@ private:
|
|||||||
QString getSystemPromptWithLinkedFiles(
|
QString getSystemPromptWithLinkedFiles(
|
||||||
const QString &basePrompt, const QList<QString> &linkedFiles) const;
|
const QString &basePrompt, const QList<QString> &linkedFiles) const;
|
||||||
|
|
||||||
LLMCore::RequestHandler *m_requestHandler;
|
LLMCore::IPromptProvider *m_promptProvider = nullptr;
|
||||||
ChatModel *m_chatModel;
|
ChatModel *m_chatModel;
|
||||||
|
LLMCore::RequestHandler *m_requestHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -40,10 +40,12 @@ namespace QodeAssist {
|
|||||||
|
|
||||||
LLMClientInterface::LLMClientInterface(
|
LLMClientInterface::LLMClientInterface(
|
||||||
const Settings::GeneralSettings &generalSettings,
|
const Settings::GeneralSettings &generalSettings,
|
||||||
const Settings::CodeCompletionSettings &completeSettings)
|
const Settings::CodeCompletionSettings &completeSettings,
|
||||||
|
LLMCore::IPromptProvider *promptProvider)
|
||||||
: m_requestHandler(this)
|
: m_requestHandler(this)
|
||||||
, m_generalSettings(generalSettings)
|
, m_generalSettings(generalSettings)
|
||||||
, m_completeSettings(completeSettings)
|
, m_completeSettings(completeSettings)
|
||||||
|
, m_promptProvider(promptProvider)
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
&m_requestHandler,
|
&m_requestHandler,
|
||||||
@ -175,8 +177,7 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
|||||||
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
||||||
: m_generalSettings.ccPreset1Template();
|
: m_generalSettings.ccPreset1Template();
|
||||||
|
|
||||||
auto promptTemplate = LLMCore::PromptTemplateManager::instance().getFimTemplateByName(
|
auto promptTemplate = m_promptProvider->getTemplateByName(templateName);
|
||||||
templateName);
|
|
||||||
|
|
||||||
if (!promptTemplate) {
|
if (!promptTemplate) {
|
||||||
LOG_MESSAGE(QString("No template found with name: %1").arg(templateName));
|
LOG_MESSAGE(QString("No template found with name: %1").arg(templateName));
|
||||||
@ -281,8 +282,7 @@ void LLMClientInterface::sendCompletionToClient(
|
|||||||
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
||||||
: m_generalSettings.ccPreset1Template();
|
: m_generalSettings.ccPreset1Template();
|
||||||
|
|
||||||
auto promptTemplate = LLMCore::PromptTemplateManager::instance().getFimTemplateByName(
|
auto promptTemplate = m_promptProvider->getTemplateByName(templateName);
|
||||||
templateName);
|
|
||||||
|
|
||||||
QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject();
|
QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject();
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <context/ProgrammingLanguage.hpp>
|
#include <context/ProgrammingLanguage.hpp>
|
||||||
#include <llmcore/ContextData.hpp>
|
#include <llmcore/ContextData.hpp>
|
||||||
|
#include <llmcore/IPromptProvider.hpp>
|
||||||
#include <llmcore/RequestHandler.hpp>
|
#include <llmcore/RequestHandler.hpp>
|
||||||
#include <settings/CodeCompletionSettings.hpp>
|
#include <settings/CodeCompletionSettings.hpp>
|
||||||
#include <settings/GeneralSettings.hpp>
|
#include <settings/GeneralSettings.hpp>
|
||||||
@ -40,7 +41,8 @@ class LLMClientInterface : public LanguageClient::BaseClientInterface
|
|||||||
public:
|
public:
|
||||||
LLMClientInterface(
|
LLMClientInterface(
|
||||||
const Settings::GeneralSettings &generalSettings,
|
const Settings::GeneralSettings &generalSettings,
|
||||||
const Settings::CodeCompletionSettings &completeSettings);
|
const Settings::CodeCompletionSettings &completeSettings,
|
||||||
|
LLMCore::IPromptProvider *promptProvider);
|
||||||
|
|
||||||
Utils::FilePath serverDeviceTemplate() const override;
|
Utils::FilePath serverDeviceTemplate() const override;
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ private:
|
|||||||
|
|
||||||
const Settings::CodeCompletionSettings &m_completeSettings;
|
const Settings::CodeCompletionSettings &m_completeSettings;
|
||||||
const Settings::GeneralSettings &m_generalSettings;
|
const Settings::GeneralSettings &m_generalSettings;
|
||||||
|
LLMCore::IPromptProvider *m_promptProvider = nullptr;
|
||||||
LLMCore::RequestHandler m_requestHandler;
|
LLMCore::RequestHandler m_requestHandler;
|
||||||
QElapsedTimer m_completionTimer;
|
QElapsedTimer m_completionTimer;
|
||||||
QMap<QString, qint64> m_requestStartTimes;
|
QMap<QString, qint64> m_requestStartTimes;
|
||||||
|
@ -44,9 +44,9 @@ using namespace Core;
|
|||||||
|
|
||||||
namespace QodeAssist {
|
namespace QodeAssist {
|
||||||
|
|
||||||
QodeAssistClient::QodeAssistClient()
|
QodeAssistClient::QodeAssistClient(LLMCore::IPromptProvider *promptProvider)
|
||||||
: LanguageClient::Client(
|
: LanguageClient::Client(new LLMClientInterface(
|
||||||
new LLMClientInterface(Settings::generalSettings(), Settings::codeCompletionSettings()))
|
Settings::generalSettings(), Settings::codeCompletionSettings(), promptProvider))
|
||||||
, m_recentCharCount(0)
|
, m_recentCharCount(0)
|
||||||
{
|
{
|
||||||
setName("Qode Assist");
|
setName("Qode Assist");
|
||||||
|
@ -24,16 +24,16 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <languageclient/client.h>
|
|
||||||
|
|
||||||
#include "LSPCompletion.hpp"
|
#include "LSPCompletion.hpp"
|
||||||
|
#include <languageclient/client.h>
|
||||||
|
#include <llmcore/IPromptProvider.hpp>
|
||||||
|
|
||||||
namespace QodeAssist {
|
namespace QodeAssist {
|
||||||
|
|
||||||
class QodeAssistClient : public LanguageClient::Client
|
class QodeAssistClient : public LanguageClient::Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit QodeAssistClient();
|
explicit QodeAssistClient(LLMCore::IPromptProvider *promptProvider);
|
||||||
~QodeAssistClient() override;
|
~QodeAssistClient() override;
|
||||||
|
|
||||||
void openDocument(TextEditor::TextDocument *document) override;
|
void openDocument(TextEditor::TextDocument *document) override;
|
||||||
|
@ -3,6 +3,9 @@ add_library(LLMCore STATIC
|
|||||||
Provider.hpp
|
Provider.hpp
|
||||||
ProvidersManager.hpp ProvidersManager.cpp
|
ProvidersManager.hpp ProvidersManager.cpp
|
||||||
ContextData.hpp
|
ContextData.hpp
|
||||||
|
IPromptProvider.hpp
|
||||||
|
PromptProviderChat.hpp
|
||||||
|
PromptProviderFim.hpp
|
||||||
PromptTemplate.hpp
|
PromptTemplate.hpp
|
||||||
PromptTemplateManager.hpp PromptTemplateManager.cpp
|
PromptTemplateManager.hpp PromptTemplateManager.cpp
|
||||||
RequestConfig.hpp
|
RequestConfig.hpp
|
||||||
|
39
llmcore/IPromptProvider.hpp
Normal file
39
llmcore/IPromptProvider.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Povilas Kanapickas <povilas@radix.lt>
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PromptTemplate.hpp"
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace QodeAssist::LLMCore {
|
||||||
|
|
||||||
|
class IPromptProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IPromptProvider() = default;
|
||||||
|
|
||||||
|
virtual PromptTemplate *getTemplateByName(const QString &templateName) const = 0;
|
||||||
|
|
||||||
|
virtual QStringList templatesNames() const = 0;
|
||||||
|
|
||||||
|
virtual QStringList getTemplatesForProvider(ProviderID id) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::LLMCore
|
53
llmcore/PromptProviderChat.hpp
Normal file
53
llmcore/PromptProviderChat.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Povilas Kanapickas <povilas@radix.lt>
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IPromptProvider.hpp"
|
||||||
|
#include "PromptTemplate.hpp"
|
||||||
|
#include "PromptTemplateManager.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::LLMCore {
|
||||||
|
|
||||||
|
class PromptProviderChat : public IPromptProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PromptProviderChat(PromptTemplateManager &templateManager)
|
||||||
|
: m_templateManager(templateManager)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~PromptProviderChat() = default;
|
||||||
|
|
||||||
|
PromptTemplate *getTemplateByName(const QString &templateName) const override
|
||||||
|
{
|
||||||
|
return m_templateManager.getChatTemplateByName(templateName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList templatesNames() const override { return m_templateManager.chatTemplatesNames(); }
|
||||||
|
|
||||||
|
QStringList getTemplatesForProvider(ProviderID id) const override
|
||||||
|
{
|
||||||
|
return m_templateManager.getChatTemplatesForProvider(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PromptTemplateManager &m_templateManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::LLMCore
|
52
llmcore/PromptProviderFim.hpp
Normal file
52
llmcore/PromptProviderFim.hpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Povilas Kanapickas <povilas@radix.lt>
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IPromptProvider.hpp"
|
||||||
|
#include "PromptTemplateManager.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::LLMCore {
|
||||||
|
|
||||||
|
class PromptProviderFim : public IPromptProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PromptProviderFim(PromptTemplateManager &templateManager)
|
||||||
|
: m_templateManager(templateManager)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~PromptProviderFim() = default;
|
||||||
|
|
||||||
|
PromptTemplate *getTemplateByName(const QString &templateName) const override
|
||||||
|
{
|
||||||
|
return m_templateManager.getFimTemplateByName(templateName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList templatesNames() const override { return m_templateManager.fimTemplatesNames(); }
|
||||||
|
|
||||||
|
QStringList getTemplatesForProvider(ProviderID id) const override
|
||||||
|
{
|
||||||
|
return m_templateManager.getFimTemplatesForProvider(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PromptTemplateManager &m_templateManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::LLMCore
|
@ -46,6 +46,7 @@
|
|||||||
#include "Version.hpp"
|
#include "Version.hpp"
|
||||||
#include "chat/ChatOutputPane.h"
|
#include "chat/ChatOutputPane.h"
|
||||||
#include "chat/NavigationPanel.hpp"
|
#include "chat/NavigationPanel.hpp"
|
||||||
|
#include "llmcore/PromptProviderFim.hpp"
|
||||||
#include "settings/GeneralSettings.hpp"
|
#include "settings/GeneralSettings.hpp"
|
||||||
#include "settings/ProjectSettingsPanel.hpp"
|
#include "settings/ProjectSettingsPanel.hpp"
|
||||||
#include "settings/SettingsConstants.hpp"
|
#include "settings/SettingsConstants.hpp"
|
||||||
@ -68,6 +69,7 @@ class QodeAssistPlugin final : public ExtensionSystem::IPlugin
|
|||||||
public:
|
public:
|
||||||
QodeAssistPlugin()
|
QodeAssistPlugin()
|
||||||
: m_updater(new PluginUpdater(this))
|
: m_updater(new PluginUpdater(this))
|
||||||
|
, m_promptProvider(LLMCore::PromptTemplateManager::instance())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~QodeAssistPlugin() final
|
~QodeAssistPlugin() final
|
||||||
@ -135,7 +137,7 @@ public:
|
|||||||
void restartClient()
|
void restartClient()
|
||||||
{
|
{
|
||||||
LanguageClient::LanguageClientManager::shutdownClient(m_qodeAssistClient);
|
LanguageClient::LanguageClientManager::shutdownClient(m_qodeAssistClient);
|
||||||
m_qodeAssistClient = new QodeAssistClient();
|
m_qodeAssistClient = new QodeAssistClient(&m_promptProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool delayedInitialize() final
|
bool delayedInitialize() final
|
||||||
@ -176,6 +178,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPointer<QodeAssistClient> m_qodeAssistClient;
|
QPointer<QodeAssistClient> m_qodeAssistClient;
|
||||||
|
LLMCore::PromptProviderFim m_promptProvider;
|
||||||
QPointer<Chat::ChatOutputPane> m_chatOutputPane;
|
QPointer<Chat::ChatOutputPane> m_chatOutputPane;
|
||||||
QPointer<Chat::NavigationPanel> m_navigationPanel;
|
QPointer<Chat::NavigationPanel> m_navigationPanel;
|
||||||
QPointer<PluginUpdater> m_updater;
|
QPointer<PluginUpdater> m_updater;
|
||||||
|
Loading…
Reference in New Issue
Block a user