diff --git a/ChatView/ChatRootView.cpp b/ChatView/ChatRootView.cpp index f82e6ac..0da8195 100644 --- a/ChatView/ChatRootView.cpp +++ b/ChatView/ChatRootView.cpp @@ -45,7 +45,8 @@ namespace QodeAssist::Chat { ChatRootView::ChatRootView(QQuickItem *parent) : QQuickItem(parent) , 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(); connect( diff --git a/ChatView/ChatRootView.hpp b/ChatView/ChatRootView.hpp index 0ca96f8..341a244 100644 --- a/ChatView/ChatRootView.hpp +++ b/ChatView/ChatRootView.hpp @@ -23,6 +23,7 @@ #include "ChatModel.hpp" #include "ClientInterface.hpp" +#include "llmcore/PromptProviderChat.hpp" #include namespace QodeAssist::Chat { @@ -99,6 +100,7 @@ private: QString getSuggestedFileName() const; ChatModel *m_chatModel; + LLMCore::PromptProviderChat m_promptProvider; ClientInterface *m_clientInterface; QString m_currentTemplate; QString m_recentFilePath; diff --git a/ChatView/ClientInterface.cpp b/ChatView/ClientInterface.cpp index f0f2846..774069e 100644 --- a/ChatView/ClientInterface.cpp +++ b/ChatView/ClientInterface.cpp @@ -36,15 +36,16 @@ #include "ContextManager.hpp" #include "GeneralSettings.hpp" #include "Logger.hpp" -#include "PromptTemplateManager.hpp" #include "ProvidersManager.hpp" namespace QodeAssist::Chat { -ClientInterface::ClientInterface(ChatModel *chatModel, QObject *parent) +ClientInterface::ClientInterface( + ChatModel *chatModel, LLMCore::IPromptProvider *promptProvider, QObject *parent) : QObject(parent) , m_requestHandler(new LLMCore::RequestHandler(this)) , m_chatModel(chatModel) + , m_promptProvider(promptProvider) { connect( m_requestHandler, @@ -86,8 +87,7 @@ void ClientInterface::sendMessage( } auto templateName = Settings::generalSettings().caTemplate(); - auto promptTemplate = LLMCore::PromptTemplateManager::instance().getChatTemplateByName( - templateName); + auto promptTemplate = m_promptProvider->getTemplateByName(templateName); if (!promptTemplate) { LOG_MESSAGE(QString("No template found with name: %1").arg(templateName)); diff --git a/ChatView/ClientInterface.hpp b/ChatView/ClientInterface.hpp index 3e71b0d..1e56c36 100644 --- a/ChatView/ClientInterface.hpp +++ b/ChatView/ClientInterface.hpp @@ -25,6 +25,7 @@ #include "ChatModel.hpp" #include "RequestHandler.hpp" +#include "llmcore/IPromptProvider.hpp" namespace QodeAssist::Chat { @@ -33,7 +34,8 @@ class ClientInterface : public QObject Q_OBJECT public: - explicit ClientInterface(ChatModel *chatModel, QObject *parent = nullptr); + explicit ClientInterface( + ChatModel *chatModel, LLMCore::IPromptProvider *promptProvider, QObject *parent = nullptr); ~ClientInterface(); void sendMessage( @@ -53,8 +55,9 @@ private: QString getSystemPromptWithLinkedFiles( const QString &basePrompt, const QList &linkedFiles) const; - LLMCore::RequestHandler *m_requestHandler; + LLMCore::IPromptProvider *m_promptProvider = nullptr; ChatModel *m_chatModel; + LLMCore::RequestHandler *m_requestHandler; }; } // namespace QodeAssist::Chat diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index a37715b..598358a 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -40,10 +40,12 @@ namespace QodeAssist { LLMClientInterface::LLMClientInterface( const Settings::GeneralSettings &generalSettings, - const Settings::CodeCompletionSettings &completeSettings) + const Settings::CodeCompletionSettings &completeSettings, + LLMCore::IPromptProvider *promptProvider) : m_requestHandler(this) , m_generalSettings(generalSettings) , m_completeSettings(completeSettings) + , m_promptProvider(promptProvider) { connect( &m_requestHandler, @@ -175,8 +177,7 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request) auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate() : m_generalSettings.ccPreset1Template(); - auto promptTemplate = LLMCore::PromptTemplateManager::instance().getFimTemplateByName( - templateName); + auto promptTemplate = m_promptProvider->getTemplateByName(templateName); if (!promptTemplate) { LOG_MESSAGE(QString("No template found with name: %1").arg(templateName)); @@ -281,8 +282,7 @@ void LLMClientInterface::sendCompletionToClient( auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate() : m_generalSettings.ccPreset1Template(); - auto promptTemplate = LLMCore::PromptTemplateManager::instance().getFimTemplateByName( - templateName); + auto promptTemplate = m_promptProvider->getTemplateByName(templateName); QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject(); diff --git a/LLMClientInterface.hpp b/LLMClientInterface.hpp index 7832f98..5de2beb 100644 --- a/LLMClientInterface.hpp +++ b/LLMClientInterface.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,8 @@ class LLMClientInterface : public LanguageClient::BaseClientInterface public: LLMClientInterface( const Settings::GeneralSettings &generalSettings, - const Settings::CodeCompletionSettings &completeSettings); + const Settings::CodeCompletionSettings &completeSettings, + LLMCore::IPromptProvider *promptProvider); Utils::FilePath serverDeviceTemplate() const override; @@ -67,6 +69,7 @@ private: const Settings::CodeCompletionSettings &m_completeSettings; const Settings::GeneralSettings &m_generalSettings; + LLMCore::IPromptProvider *m_promptProvider = nullptr; LLMCore::RequestHandler m_requestHandler; QElapsedTimer m_completionTimer; QMap m_requestStartTimes; diff --git a/QodeAssistClient.cpp b/QodeAssistClient.cpp index 219e617..74a761d 100644 --- a/QodeAssistClient.cpp +++ b/QodeAssistClient.cpp @@ -44,9 +44,9 @@ using namespace Core; namespace QodeAssist { -QodeAssistClient::QodeAssistClient() - : LanguageClient::Client( - new LLMClientInterface(Settings::generalSettings(), Settings::codeCompletionSettings())) +QodeAssistClient::QodeAssistClient(LLMCore::IPromptProvider *promptProvider) + : LanguageClient::Client(new LLMClientInterface( + Settings::generalSettings(), Settings::codeCompletionSettings(), promptProvider)) , m_recentCharCount(0) { setName("Qode Assist"); diff --git a/QodeAssistClient.hpp b/QodeAssistClient.hpp index af3cf12..12cdbf1 100644 --- a/QodeAssistClient.hpp +++ b/QodeAssistClient.hpp @@ -24,16 +24,16 @@ #pragma once -#include - #include "LSPCompletion.hpp" +#include +#include namespace QodeAssist { class QodeAssistClient : public LanguageClient::Client { public: - explicit QodeAssistClient(); + explicit QodeAssistClient(LLMCore::IPromptProvider *promptProvider); ~QodeAssistClient() override; void openDocument(TextEditor::TextDocument *document) override; diff --git a/llmcore/CMakeLists.txt b/llmcore/CMakeLists.txt index 988b164..34b89f2 100644 --- a/llmcore/CMakeLists.txt +++ b/llmcore/CMakeLists.txt @@ -3,6 +3,9 @@ add_library(LLMCore STATIC Provider.hpp ProvidersManager.hpp ProvidersManager.cpp ContextData.hpp + IPromptProvider.hpp + PromptProviderChat.hpp + PromptProviderFim.hpp PromptTemplate.hpp PromptTemplateManager.hpp PromptTemplateManager.cpp RequestConfig.hpp diff --git a/llmcore/IPromptProvider.hpp b/llmcore/IPromptProvider.hpp new file mode 100644 index 0000000..0dde34a --- /dev/null +++ b/llmcore/IPromptProvider.hpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 Povilas Kanapickas + * + * 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 . + */ + +#pragma once + +#include "PromptTemplate.hpp" +#include + +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 diff --git a/llmcore/PromptProviderChat.hpp b/llmcore/PromptProviderChat.hpp new file mode 100644 index 0000000..19804f1 --- /dev/null +++ b/llmcore/PromptProviderChat.hpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 Povilas Kanapickas + * + * 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 . + */ + +#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 diff --git a/llmcore/PromptProviderFim.hpp b/llmcore/PromptProviderFim.hpp new file mode 100644 index 0000000..19529c0 --- /dev/null +++ b/llmcore/PromptProviderFim.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2025 Povilas Kanapickas + * + * 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 . + */ + +#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 diff --git a/qodeassist.cpp b/qodeassist.cpp index a81ff13..1d7d54b 100644 --- a/qodeassist.cpp +++ b/qodeassist.cpp @@ -46,6 +46,7 @@ #include "Version.hpp" #include "chat/ChatOutputPane.h" #include "chat/NavigationPanel.hpp" +#include "llmcore/PromptProviderFim.hpp" #include "settings/GeneralSettings.hpp" #include "settings/ProjectSettingsPanel.hpp" #include "settings/SettingsConstants.hpp" @@ -68,6 +69,7 @@ class QodeAssistPlugin final : public ExtensionSystem::IPlugin public: QodeAssistPlugin() : m_updater(new PluginUpdater(this)) + , m_promptProvider(LLMCore::PromptTemplateManager::instance()) {} ~QodeAssistPlugin() final @@ -135,7 +137,7 @@ public: void restartClient() { LanguageClient::LanguageClientManager::shutdownClient(m_qodeAssistClient); - m_qodeAssistClient = new QodeAssistClient(); + m_qodeAssistClient = new QodeAssistClient(&m_promptProvider); } bool delayedInitialize() final @@ -176,6 +178,7 @@ private: } QPointer m_qodeAssistClient; + LLMCore::PromptProviderFim m_promptProvider; QPointer m_chatOutputPane; QPointer m_navigationPanel; QPointer m_updater;