Fix system prompt for FIM

This commit is contained in:
Petr Mironychev 2024-10-02 21:44:15 +02:00
parent fbe363689f
commit 9903ac8f7b
6 changed files with 35 additions and 15 deletions

View File

@ -250,9 +250,6 @@ QString DocumentContextReader::getInstructions() const
{ {
QString instructions; QString instructions;
if (Settings::contextSettings().useSpecificInstructions())
instructions += getSpecificInstructions();
if (Settings::contextSettings().useFilePathInContext()) if (Settings::contextSettings().useFilePathInContext())
instructions += getLanguageAndFileInfo(); instructions += getLanguageAndFileInfo();

View File

@ -30,6 +30,7 @@
#include "PromptTemplateManager.hpp" #include "PromptTemplateManager.hpp"
#include "QodeAssistUtils.hpp" #include "QodeAssistUtils.hpp"
#include "core/LLMRequestConfig.hpp" #include "core/LLMRequestConfig.hpp"
#include "settings/ContextSettings.hpp"
#include "settings/GeneralSettings.hpp" #include "settings/GeneralSettings.hpp"
namespace QodeAssist { namespace QodeAssist {
@ -159,6 +160,9 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
{"stop", {"stop",
QJsonArray::fromStringList(config.promptTemplate->stopWords())}}; QJsonArray::fromStringList(config.promptTemplate->stopWords())}};
if (Settings::contextSettings().useSpecificInstructions())
config.providerRequest["system"] = Settings::contextSettings().specificInstractions();
config.promptTemplate->prepareRequest(config.providerRequest, updatedContext); config.promptTemplate->prepareRequest(config.providerRequest, updatedContext);
config.provider->prepareRequest(config.providerRequest); config.provider->prepareRequest(config.providerRequest);

View File

@ -53,10 +53,10 @@ const char AUTO_COMPLETION_CHAR_THRESHOLD[] = "QodeAssist.autoCompletionCharThre
const char AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval"; const char AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval";
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime"; 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 MULTILINE_COMPLETION[] = "QodeAssist.multilineCompletion";
const char API_KEY[] = "QodeAssist.apiKey"; 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 USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.useFilePathInContext";
const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate"; const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate";
const char USE_PROJECT_CHANGES_CACHE[] = "QodeAssist.useProjectChangesCache"; const char USE_PROJECT_CHANGES_CACHE[] = "QodeAssist.useProjectChangesCache";

View File

@ -55,9 +55,20 @@ QString LMStudioProvider::chatEndpoint() const
void LMStudioProvider::prepareRequest(QJsonObject &request) void LMStudioProvider::prepareRequest(QJsonObject &request)
{ {
auto &settings = Settings::presetPromptsSettings(); 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")) { if (request.contains("prompt")) {
QJsonArray messages{ QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}};
{QJsonObject{{"role", "user"}, {"content", request.take("prompt").toString()}}}}; messages.append(userMessage);
}
if (!messages.isEmpty()) {
request["messages"] = std::move(messages); request["messages"] = std::move(messages);
} }

View File

@ -24,7 +24,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QNetworkReply> #include <QNetworkReply>
#include "PromptTemplateManager.hpp"
#include "settings/PresetPromptsSettings.hpp" #include "settings/PresetPromptsSettings.hpp"
namespace QodeAssist::Providers { namespace QodeAssist::Providers {
@ -54,9 +53,20 @@ QString OpenAICompatProvider::chatEndpoint() const
void OpenAICompatProvider::prepareRequest(QJsonObject &request) void OpenAICompatProvider::prepareRequest(QJsonObject &request)
{ {
auto &settings = Settings::presetPromptsSettings(); 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")) { if (request.contains("prompt")) {
QJsonArray messages{ QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}};
{QJsonObject{{"role", "user"}, {"content", request.take("prompt").toString()}}}}; messages.append(userMessage);
}
if (!messages.isEmpty()) {
request["messages"] = std::move(messages); request["messages"] = std::move(messages);
} }

View File

@ -17,8 +17,6 @@
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>. * along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "ContextSettings.hpp" #include "ContextSettings.hpp"
#include <QMessageBox> #include <QMessageBox>
@ -60,11 +58,11 @@ ContextSettings::ContextSettings()
useFilePathInContext.setDefaultValue(false); useFilePathInContext.setDefaultValue(false);
useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context")); 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.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.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
specificInstractions.setLabelText( specificInstractions.setLabelText(
Tr::tr("Instructions: Please keep %1 for languge name, warning, it shouldn't too big")); Tr::tr("Instructions: Please keep %1 for languge name, warning, it shouldn't too big"));