diff --git a/DocumentContextReader.cpp b/DocumentContextReader.cpp index b3c2707..5bbde27 100644 --- a/DocumentContextReader.cpp +++ b/DocumentContextReader.cpp @@ -250,9 +250,6 @@ QString DocumentContextReader::getInstructions() const { QString instructions; - if (Settings::contextSettings().useSpecificInstructions()) - instructions += getSpecificInstructions(); - if (Settings::contextSettings().useFilePathInContext()) instructions += getLanguageAndFileInfo(); diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index 6dd25ae..b9b0230 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -30,6 +30,7 @@ #include "PromptTemplateManager.hpp" #include "QodeAssistUtils.hpp" #include "core/LLMRequestConfig.hpp" +#include "settings/ContextSettings.hpp" #include "settings/GeneralSettings.hpp" namespace QodeAssist { @@ -159,6 +160,9 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request) {"stop", QJsonArray::fromStringList(config.promptTemplate->stopWords())}}; + if (Settings::contextSettings().useSpecificInstructions()) + config.providerRequest["system"] = Settings::contextSettings().specificInstractions(); + config.promptTemplate->prepareRequest(config.providerRequest, updatedContext); config.provider->prepareRequest(config.providerRequest); diff --git a/QodeAssistConstants.hpp b/QodeAssistConstants.hpp index fc5b6d8..dd4c88d 100644 --- a/QodeAssistConstants.hpp +++ b/QodeAssistConstants.hpp @@ -53,10 +53,10 @@ const char AUTO_COMPLETION_CHAR_THRESHOLD[] = "QodeAssist.autoCompletionCharThre const char AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime"; -const char SPECIFIC_INSTRUCTIONS[] = "QodeAssist.specificInstractions"; +const char SYSTEM_PROMPT[] = "QodeAssist.systemPrompt"; const char MULTILINE_COMPLETION[] = "QodeAssist.multilineCompletion"; const char API_KEY[] = "QodeAssist.apiKey"; -const char USE_SPECIFIC_INSTRUCTIONS[] = "QodeAssist.useSpecificInstructions"; +const char USE_SYSTEM_PROMPT[] = "QodeAssist.useSystemPrompt"; const char USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.useFilePathInContext"; const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate"; const char USE_PROJECT_CHANGES_CACHE[] = "QodeAssist.useProjectChangesCache"; diff --git a/providers/LMStudioProvider.cpp b/providers/LMStudioProvider.cpp index 75afce1..67651b2 100644 --- a/providers/LMStudioProvider.cpp +++ b/providers/LMStudioProvider.cpp @@ -55,9 +55,20 @@ QString LMStudioProvider::chatEndpoint() const void LMStudioProvider::prepareRequest(QJsonObject &request) { auto &settings = Settings::presetPromptsSettings(); + QJsonArray messages; + + if (request.contains("system")) { + QJsonObject systemMessage{{"role", "system"}, + {"content", request.take("system").toString()}}; + messages.append(systemMessage); + } + if (request.contains("prompt")) { - QJsonArray messages{ - {QJsonObject{{"role", "user"}, {"content", request.take("prompt").toString()}}}}; + QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}}; + messages.append(userMessage); + } + + if (!messages.isEmpty()) { request["messages"] = std::move(messages); } diff --git a/providers/OpenAICompatProvider.cpp b/providers/OpenAICompatProvider.cpp index 36960f6..8d322f6 100644 --- a/providers/OpenAICompatProvider.cpp +++ b/providers/OpenAICompatProvider.cpp @@ -24,7 +24,6 @@ #include #include -#include "PromptTemplateManager.hpp" #include "settings/PresetPromptsSettings.hpp" namespace QodeAssist::Providers { @@ -54,9 +53,20 @@ QString OpenAICompatProvider::chatEndpoint() const void OpenAICompatProvider::prepareRequest(QJsonObject &request) { auto &settings = Settings::presetPromptsSettings(); + QJsonArray messages; + + if (request.contains("system")) { + QJsonObject systemMessage{{"role", "system"}, + {"content", request.take("system").toString()}}; + messages.append(systemMessage); + } + if (request.contains("prompt")) { - QJsonArray messages{ - {QJsonObject{{"role", "user"}, {"content", request.take("prompt").toString()}}}}; + QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}}; + messages.append(userMessage); + } + + if (!messages.isEmpty()) { request["messages"] = std::move(messages); } diff --git a/settings/ContextSettings.cpp b/settings/ContextSettings.cpp index c76e902..d14aed9 100644 --- a/settings/ContextSettings.cpp +++ b/settings/ContextSettings.cpp @@ -17,8 +17,6 @@ * along with QodeAssist. If not, see . */ -#pragma once - #include "ContextSettings.hpp" #include @@ -60,11 +58,11 @@ ContextSettings::ContextSettings() useFilePathInContext.setDefaultValue(false); useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context")); - useSpecificInstructions.setSettingsKey(Constants::USE_SPECIFIC_INSTRUCTIONS); + useSpecificInstructions.setSettingsKey(Constants::USE_SYSTEM_PROMPT); useSpecificInstructions.setDefaultValue(true); - useSpecificInstructions.setLabelText(Tr::tr("Use Specific Instructions")); + useSpecificInstructions.setLabelText(Tr::tr("Use System Prompt")); - specificInstractions.setSettingsKey(Constants::SPECIFIC_INSTRUCTIONS); + specificInstractions.setSettingsKey(Constants::SYSTEM_PROMPT); specificInstractions.setDisplayStyle(Utils::StringAspect::TextEditDisplay); specificInstractions.setLabelText( Tr::tr("Instructions: Please keep %1 for languge name, warning, it shouldn't too big"));