mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-03 09:08:21 -04:00
Move context settings to page
This commit is contained in:
parent
b5ca11ed38
commit
356f28a97b
@ -24,6 +24,7 @@
|
||||
#include <languageserverprotocol/lsptypes.h>
|
||||
|
||||
#include "QodeAssistSettings.hpp"
|
||||
#include "settings/ContextSettings.hpp"
|
||||
|
||||
const QRegularExpression &getYearRegex()
|
||||
{
|
||||
@ -136,7 +137,7 @@ QString DocumentContextReader::getLanguageAndFileInfo() const
|
||||
|
||||
QString DocumentContextReader::getSpecificInstructions() const
|
||||
{
|
||||
QString specificInstruction = settings().specificInstractions().arg(
|
||||
QString specificInstruction = Settings::contextSettings().specificInstractions().arg(
|
||||
LanguageServerProtocol::TextDocumentItem::mimeTypeToLanguageId(m_textDocument->mimeType()));
|
||||
return QString("%1").arg(specificInstruction);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "PromptTemplateManager.hpp"
|
||||
#include "QodeAssistSettings.hpp"
|
||||
#include "QodeAssistUtils.hpp"
|
||||
#include "settings/ContextSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
|
||||
namespace QodeAssist {
|
||||
@ -131,12 +132,13 @@ QString LLMClientInterface::сontextBefore(TextEditor::TextEditorWidget *widget,
|
||||
return QString();
|
||||
|
||||
QString contextBefore;
|
||||
if (settings().readFullFile()) {
|
||||
if (Settings::contextSettings().readFullFile()) {
|
||||
contextBefore = reader.readWholeFileBefore(lineNumber, cursorPosition);
|
||||
} else {
|
||||
contextBefore = reader.getContextBefore(lineNumber,
|
||||
cursorPosition,
|
||||
settings().readStringsBeforeCursor());
|
||||
contextBefore
|
||||
= reader.getContextBefore(lineNumber,
|
||||
cursorPosition,
|
||||
Settings::contextSettings().readStringsBeforeCursor());
|
||||
}
|
||||
|
||||
return contextBefore;
|
||||
@ -154,12 +156,12 @@ QString LLMClientInterface::сontextAfter(TextEditor::TextEditorWidget *widget,
|
||||
return QString();
|
||||
|
||||
QString contextAfter;
|
||||
if (settings().readFullFile()) {
|
||||
if (Settings::contextSettings().readFullFile()) {
|
||||
contextAfter = reader.readWholeFileAfter(lineNumber, cursorPosition);
|
||||
} else {
|
||||
contextAfter = reader.getContextAfter(lineNumber,
|
||||
cursorPosition,
|
||||
settings().readStringsAfterCursor());
|
||||
Settings::contextSettings().readStringsAfterCursor());
|
||||
}
|
||||
|
||||
return contextAfter;
|
||||
@ -228,7 +230,7 @@ void LLMClientInterface::handleLLMResponse(QNetworkReply *reply, const QJsonObje
|
||||
|
||||
QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject();
|
||||
|
||||
if (!settings().multiLineCompletion()
|
||||
if (!Settings::generalSettings().multiLineCompletion()
|
||||
&& processSingleLineCompletion(reply, request, accumulatedResponse)) {
|
||||
return;
|
||||
}
|
||||
@ -278,10 +280,10 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
|
||||
|
||||
QString contextBefore = сontextBefore(widget, lineNumber, cursorPosition);
|
||||
QString contextAfter = сontextAfter(widget, lineNumber, cursorPosition);
|
||||
QString instructions = QString("%1%2").arg(settings().useSpecificInstructions()
|
||||
QString instructions = QString("%1%2").arg(Settings::contextSettings().useSpecificInstructions()
|
||||
? reader.getSpecificInstructions()
|
||||
: QString(),
|
||||
settings().useFilePathInContext()
|
||||
Settings::contextSettings().useFilePathInContext()
|
||||
? reader.getLanguageAndFileInfo()
|
||||
: QString());
|
||||
|
||||
|
@ -58,23 +58,6 @@ QodeAssistSettings::QodeAssistSettings()
|
||||
ollamaLivetime.setDefaultValue("5m");
|
||||
ollamaLivetime.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
|
||||
|
||||
readFullFile.setSettingsKey(Constants::READ_FULL_FILE);
|
||||
readFullFile.setLabelText(Tr::tr("Read Full File"));
|
||||
readFullFile.setDefaultValue(false);
|
||||
|
||||
maxFileThreshold.setSettingsKey(Constants::MAX_FILE_THRESHOLD);
|
||||
maxFileThreshold.setLabelText(Tr::tr("Max File Threshold:"));
|
||||
maxFileThreshold.setRange(10, 100000);
|
||||
maxFileThreshold.setDefaultValue(600);
|
||||
|
||||
readStringsBeforeCursor.setSettingsKey(Constants::READ_STRINGS_BEFORE_CURSOR);
|
||||
readStringsBeforeCursor.setLabelText(Tr::tr("Read Strings Before Cursor"));
|
||||
readStringsBeforeCursor.setDefaultValue(50);
|
||||
|
||||
readStringsAfterCursor.setSettingsKey(Constants::READ_STRINGS_AFTER_CURSOR);
|
||||
readStringsAfterCursor.setLabelText(Tr::tr("Read Strings After Cursor"));
|
||||
readStringsAfterCursor.setDefaultValue(30);
|
||||
|
||||
maxTokens.setSettingsKey(Constants::MAX_TOKENS);
|
||||
maxTokens.setLabelText(Tr::tr("Max Tokens"));
|
||||
maxTokens.setRange(-1, 10000);
|
||||
@ -117,26 +100,7 @@ QodeAssistSettings::QodeAssistSettings()
|
||||
startSuggestionTimer.setRange(10, 10000);
|
||||
startSuggestionTimer.setDefaultValue(500);
|
||||
|
||||
useFilePathInContext.setSettingsKey(Constants::USE_FILE_PATH_IN_CONTEXT);
|
||||
useFilePathInContext.setDefaultValue(false);
|
||||
useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context"));
|
||||
|
||||
useSpecificInstructions.setSettingsKey(Constants::USE_SPECIFIC_INSTRUCTIONS);
|
||||
useSpecificInstructions.setDefaultValue(false);
|
||||
useSpecificInstructions.setLabelText(Tr::tr("Use Specific Instructions"));
|
||||
|
||||
specificInstractions.setSettingsKey(Constants::SPECIFIC_INSTRUCTIONS);
|
||||
specificInstractions.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||
specificInstractions.setLabelText(
|
||||
Tr::tr("Instructions: Please keep %1 for languge name, warning, it shouldn't too big"));
|
||||
specificInstractions.setDefaultValue(
|
||||
"You are an expert %1 code completion AI."
|
||||
"CRITICAL: Please provide minimal the best possible code completion suggestions.\n");
|
||||
|
||||
resetToDefaults.m_buttonText = Tr::tr("Reset to Defaults");
|
||||
multiLineCompletion.setSettingsKey(Constants::MULTILINE_COMPLETION);
|
||||
multiLineCompletion.setDefaultValue(true);
|
||||
multiLineCompletion.setLabelText(Tr::tr("Enable Multiline Completion"));
|
||||
|
||||
apiKey.setSettingsKey(Constants::API_KEY);
|
||||
apiKey.setLabelText(Tr::tr("API Key:"));
|
||||
@ -175,9 +139,7 @@ QodeAssistSettings::QodeAssistSettings()
|
||||
topP.setEnabled(useTopP());
|
||||
presencePenalty.setEnabled(usePresencePenalty());
|
||||
frequencyPenalty.setEnabled(useFrequencyPenalty());
|
||||
readStringsAfterCursor.setEnabled(!readFullFile());
|
||||
readStringsBeforeCursor.setEnabled(!readFullFile());
|
||||
specificInstractions.setEnabled(useSpecificInstructions());
|
||||
|
||||
customJsonTemplate.setVisible(PromptTemplateManager::instance().getCurrentTemplate()->name()
|
||||
== "Custom Template");
|
||||
|
||||
@ -189,15 +151,15 @@ QodeAssistSettings::QodeAssistSettings()
|
||||
Row{saveCustomTemplateButton,
|
||||
loadCustomTemplateButton,
|
||||
Stretch{1}}},
|
||||
readFullFile,
|
||||
maxFileThreshold,
|
||||
readStringsBeforeCursor,
|
||||
readStringsAfterCursor,
|
||||
// readFullFile,
|
||||
// maxFileThreshold,
|
||||
// readStringsBeforeCursor,
|
||||
// readStringsAfterCursor,
|
||||
ollamaLivetime,
|
||||
apiKey,
|
||||
useFilePathInContext,
|
||||
useSpecificInstructions,
|
||||
specificInstractions,
|
||||
// useFilePathInContext,
|
||||
// useSpecificInstructions,
|
||||
// specificInstractions,
|
||||
temperature,
|
||||
maxTokens,
|
||||
startSuggestionTimer,
|
||||
@ -225,19 +187,12 @@ void QodeAssistSettings::setupConnections()
|
||||
connect(&useFrequencyPenalty, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||
frequencyPenalty.setEnabled(useFrequencyPenalty.volatileValue());
|
||||
});
|
||||
connect(&readFullFile, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||
readStringsAfterCursor.setEnabled(!readFullFile.volatileValue());
|
||||
readStringsBeforeCursor.setEnabled(!readFullFile.volatileValue());
|
||||
});
|
||||
|
||||
connect(&resetToDefaults,
|
||||
&ButtonAspect::clicked,
|
||||
this,
|
||||
&QodeAssistSettings::resetSettingsToDefaults);
|
||||
|
||||
connect(&useSpecificInstructions, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||
specificInstractions.setEnabled(useSpecificInstructions.volatileValue());
|
||||
});
|
||||
|
||||
connect(&saveCustomTemplateButton,
|
||||
&ButtonAspect::clicked,
|
||||
this,
|
||||
@ -277,10 +232,10 @@ void QodeAssistSettings::resetSettingsToDefaults()
|
||||
// resetAspect(fimPrompts);
|
||||
resetAspect(temperature);
|
||||
resetAspect(maxTokens);
|
||||
resetAspect(readFullFile);
|
||||
resetAspect(maxFileThreshold);
|
||||
resetAspect(readStringsBeforeCursor);
|
||||
resetAspect(readStringsAfterCursor);
|
||||
// resetAspect(readFullFile);
|
||||
// resetAspect(maxFileThreshold);
|
||||
// resetAspect(readStringsBeforeCursor);
|
||||
// resetAspect(readStringsAfterCursor);
|
||||
resetAspect(useTopP);
|
||||
resetAspect(topP);
|
||||
resetAspect(useTopK);
|
||||
@ -292,10 +247,10 @@ void QodeAssistSettings::resetSettingsToDefaults()
|
||||
resetAspect(startSuggestionTimer);
|
||||
// resetAspect(enableLogging);
|
||||
resetAspect(ollamaLivetime);
|
||||
resetAspect(specificInstractions);
|
||||
resetAspect(multiLineCompletion);
|
||||
resetAspect(useFilePathInContext);
|
||||
resetAspect(useSpecificInstructions);
|
||||
// resetAspect(specificInstractions);
|
||||
// resetAspect(multiLineCompletion);
|
||||
// resetAspect(useFilePathInContext);
|
||||
// resetAspect(useSpecificInstructions);
|
||||
resetAspect(customJsonTemplate);
|
||||
|
||||
// fimPrompts.setStringValue("StarCoder2");
|
||||
|
@ -60,10 +60,6 @@ public:
|
||||
Utils::DoubleAspect temperature{this};
|
||||
Utils::IntegerAspect maxTokens{this};
|
||||
|
||||
Utils::BoolAspect readFullFile{this};
|
||||
Utils::IntegerAspect readStringsBeforeCursor{this};
|
||||
Utils::IntegerAspect readStringsAfterCursor{this};
|
||||
|
||||
Utils::BoolAspect useTopP{this};
|
||||
Utils::DoubleAspect topP{this};
|
||||
|
||||
@ -77,13 +73,8 @@ public:
|
||||
Utils::DoubleAspect frequencyPenalty{this};
|
||||
|
||||
Utils::IntegerAspect startSuggestionTimer{this};
|
||||
Utils::IntegerAspect maxFileThreshold{this};
|
||||
|
||||
Utils::StringAspect ollamaLivetime{this};
|
||||
Utils::StringAspect specificInstractions{this};
|
||||
Utils::BoolAspect useSpecificInstructions{this};
|
||||
Utils::BoolAspect useFilePathInContext{this};
|
||||
Utils::BoolAspect multiLineCompletion{this};
|
||||
|
||||
Utils::StringAspect customJsonTemplate{this};
|
||||
ButtonAspect saveCustomTemplateButton{this};
|
||||
|
@ -21,7 +21,9 @@
|
||||
|
||||
#include "ContextSettings.hpp"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include "QodeAssistConstants.hpp"
|
||||
@ -40,12 +42,93 @@ ContextSettings::ContextSettings()
|
||||
|
||||
setDisplayName(Tr::tr("Context"));
|
||||
|
||||
readFullFile.setSettingsKey(Constants::READ_FULL_FILE);
|
||||
readFullFile.setLabelText(Tr::tr("Read Full File"));
|
||||
readFullFile.setDefaultValue(false);
|
||||
|
||||
readStringsBeforeCursor.setSettingsKey(Constants::READ_STRINGS_BEFORE_CURSOR);
|
||||
readStringsBeforeCursor.setLabelText(Tr::tr("Read Strings Before Cursor"));
|
||||
readStringsBeforeCursor.setRange(0, 10000);
|
||||
readStringsBeforeCursor.setDefaultValue(50);
|
||||
|
||||
readStringsAfterCursor.setSettingsKey(Constants::READ_STRINGS_AFTER_CURSOR);
|
||||
readStringsAfterCursor.setLabelText(Tr::tr("Read Strings After Cursor"));
|
||||
readStringsAfterCursor.setRange(0, 10000);
|
||||
readStringsAfterCursor.setDefaultValue(30);
|
||||
|
||||
useFilePathInContext.setSettingsKey(Constants::USE_FILE_PATH_IN_CONTEXT);
|
||||
useFilePathInContext.setDefaultValue(false);
|
||||
useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context"));
|
||||
|
||||
useSpecificInstructions.setSettingsKey(Constants::USE_SPECIFIC_INSTRUCTIONS);
|
||||
useSpecificInstructions.setDefaultValue(false);
|
||||
useSpecificInstructions.setLabelText(Tr::tr("Use Specific Instructions"));
|
||||
|
||||
specificInstractions.setSettingsKey(Constants::SPECIFIC_INSTRUCTIONS);
|
||||
specificInstractions.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||
specificInstractions.setLabelText(
|
||||
Tr::tr("Instructions: Please keep %1 for languge name, warning, it shouldn't too big"));
|
||||
specificInstractions.setDefaultValue(
|
||||
"You are an expert %1 code completion AI."
|
||||
"CRITICAL: Please provide minimal the best possible code completion suggestions.\n");
|
||||
|
||||
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
|
||||
|
||||
readSettings();
|
||||
|
||||
readStringsAfterCursor.setEnabled(!readFullFile());
|
||||
readStringsBeforeCursor.setEnabled(!readFullFile());
|
||||
specificInstractions.setEnabled(useSpecificInstructions());
|
||||
|
||||
setupConnection();
|
||||
|
||||
setLayouter([this]() {
|
||||
using namespace Layouting;
|
||||
return Column{Stretch{1}};
|
||||
return Column{Row{readFullFile, Stretch{1}, resetToDefaults},
|
||||
readStringsBeforeCursor,
|
||||
readStringsAfterCursor,
|
||||
useFilePathInContext,
|
||||
useSpecificInstructions,
|
||||
specificInstractions,
|
||||
Stretch{1}};
|
||||
});
|
||||
}
|
||||
|
||||
void ContextSettings::setupConnection()
|
||||
{
|
||||
connect(&readFullFile, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||
readStringsAfterCursor.setEnabled(!readFullFile.volatileValue());
|
||||
readStringsBeforeCursor.setEnabled(!readFullFile.volatileValue());
|
||||
});
|
||||
connect(&useSpecificInstructions, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||
specificInstractions.setEnabled(useSpecificInstructions.volatileValue());
|
||||
});
|
||||
connect(&resetToDefaults, &ButtonAspect::clicked, this, &ContextSettings::resetPageToDefaults);
|
||||
}
|
||||
|
||||
void ContextSettings::resetPageToDefaults()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(
|
||||
Core::ICore::dialogParent(),
|
||||
Tr::tr("Reset Settings"),
|
||||
Tr::tr("Are you sure you want to reset all settings to default values?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes) {
|
||||
resetAspect(readFullFile);
|
||||
resetAspect(readStringsBeforeCursor);
|
||||
resetAspect(readStringsAfterCursor);
|
||||
resetAspect(useFilePathInContext);
|
||||
resetAspect(useSpecificInstructions);
|
||||
resetAspect(specificInstractions);
|
||||
}
|
||||
|
||||
QMessageBox::information(Core::ICore::dialogParent(),
|
||||
Tr::tr("Settings Reset"),
|
||||
Tr::tr("All settings have been reset to their default values."));
|
||||
}
|
||||
|
||||
class ContextSettingsPage : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
|
@ -21,12 +21,28 @@
|
||||
|
||||
#include <utils/aspects.h>
|
||||
|
||||
#include "SettingsUtils.hpp"
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
class ContextSettings : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
ContextSettings();
|
||||
|
||||
Utils::BoolAspect readFullFile{this};
|
||||
Utils::IntegerAspect readStringsBeforeCursor{this};
|
||||
Utils::IntegerAspect readStringsAfterCursor{this};
|
||||
|
||||
Utils::StringAspect specificInstractions{this};
|
||||
Utils::BoolAspect useSpecificInstructions{this};
|
||||
Utils::BoolAspect useFilePathInContext{this};
|
||||
|
||||
ButtonAspect resetToDefaults{this};
|
||||
|
||||
private:
|
||||
void setupConnection();
|
||||
void resetPageToDefaults();
|
||||
};
|
||||
|
||||
ContextSettings &contextSettings();
|
||||
|
@ -155,8 +155,8 @@ void GeneralSettings::updateProviderSettings()
|
||||
const auto provider = LLMProvidersManager::instance().getCurrentProvider();
|
||||
|
||||
if (provider) {
|
||||
url.setValue(provider->url());
|
||||
endPoint.setValue(provider->completionEndpoint());
|
||||
url.setVolatileValue(provider->url());
|
||||
endPoint.setVolatileValue(provider->completionEndpoint());
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ void GeneralSettings::showModelSelectionDialog()
|
||||
&ok);
|
||||
|
||||
if (ok && !selectedModel.isEmpty()) {
|
||||
modelName.setValue(selectedModel);
|
||||
modelName.setVolatileValue(selectedModel);
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
@ -206,8 +206,6 @@ void GeneralSettings::resetPageToDefaults()
|
||||
fimPrompts.setStringValue("StarCoder2");
|
||||
llmProviders.setStringValue("Ollama");
|
||||
|
||||
apply();
|
||||
|
||||
QMessageBox::information(Core::ICore::dialogParent(),
|
||||
Tr::tr("Settings Reset"),
|
||||
Tr::tr("All settings have been reset to their default values."));
|
||||
|
@ -28,7 +28,7 @@ namespace QodeAssist::Settings {
|
||||
template<typename AspectType>
|
||||
void resetAspect(AspectType &aspect)
|
||||
{
|
||||
aspect.setValue(aspect.defaultValue());
|
||||
aspect.setVolatileValue(aspect.defaultValue());
|
||||
}
|
||||
|
||||
class ButtonAspect : public Utils::BaseAspect
|
||||
|
Loading…
x
Reference in New Issue
Block a user