From bc93bce03bff3d5fe4d9d75f762514e1640dd259 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Sun, 10 Nov 2024 23:42:06 +0100 Subject: [PATCH] Adapt new settings --- ConfigurationManager.cpp | 4 +- DocumentContextReader.cpp | 14 ++-- LLMClientInterface.cpp | 2 - QodeAssistClient.cpp | 126 ++++++++++++++-------------- chatview/ChatUtils.cpp | 19 +++++ chatview/ChatUtils.h | 19 +++++ core/ChangesManager.cpp | 5 +- llmcore/RequestType.hpp | 19 +++++ providers/LMStudioProvider.cpp | 56 +++++++------ providers/OllamaProvider.cpp | 40 +++++---- providers/OpenAICompatProvider.cpp | 59 ++++++------- settings/CMakeLists.txt | 2 - settings/CodeCompletionSettings.cpp | 35 ++++++-- settings/CodeCompletionSettings.hpp | 4 + settings/GeneralSettings.cpp | 4 + settings/SettingsConstants.hpp | 15 ++-- 16 files changed, 264 insertions(+), 159 deletions(-) diff --git a/ConfigurationManager.cpp b/ConfigurationManager.cpp index 5ab05ff..e9e4e44 100644 --- a/ConfigurationManager.cpp +++ b/ConfigurationManager.cpp @@ -88,8 +88,8 @@ void ConfigurationManager::selectModel() return; const auto providerUrl = (settingsButton == &m_generalSettings.ccSelectModel) - ? m_generalSettings.ccUrl() - : m_generalSettings.caUrl(); + ? m_generalSettings.ccUrl.volatileValue() + : m_generalSettings.caUrl.volatileValue(); const auto modelList = m_providersManager.getProviderByName(providerName) ->getInstalledModels(providerUrl); diff --git a/DocumentContextReader.cpp b/DocumentContextReader.cpp index 7ac0189..2a2a864 100644 --- a/DocumentContextReader.cpp +++ b/DocumentContextReader.cpp @@ -24,7 +24,7 @@ #include #include "core/ChangesManager.h" -#include "settings/ContextSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" const QRegularExpression &getYearRegex() { @@ -214,11 +214,11 @@ LLMCore::ContextData DocumentContextReader::prepareContext(int lineNumber, int c QString DocumentContextReader::getContextBefore(int lineNumber, int cursorPosition) const { - if (Settings::contextSettings().readFullFile()) { + if (Settings::codeCompletionSettings().readFullFile()) { return readWholeFileBefore(lineNumber, cursorPosition); } else { int effectiveStartLine; - int beforeCursor = Settings::contextSettings().readStringsBeforeCursor(); + int beforeCursor = Settings::codeCompletionSettings().readStringsBeforeCursor(); if (m_copyrightInfo.found) { effectiveStartLine = qMax(m_copyrightInfo.endLine + 1, lineNumber - beforeCursor); } else { @@ -230,11 +230,11 @@ QString DocumentContextReader::getContextBefore(int lineNumber, int cursorPositi QString DocumentContextReader::getContextAfter(int lineNumber, int cursorPosition) const { - if (Settings::contextSettings().readFullFile()) { + if (Settings::codeCompletionSettings().readFullFile()) { return readWholeFileAfter(lineNumber, cursorPosition); } else { int endLine = qMin(m_document->blockCount() - 1, - lineNumber + Settings::contextSettings().readStringsAfterCursor()); + lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor()); return getContextBetween(lineNumber + 1, endLine, -1); } } @@ -243,10 +243,10 @@ QString DocumentContextReader::getInstructions() const { QString instructions; - if (Settings::contextSettings().useFilePathInContext()) + if (Settings::codeCompletionSettings().useFilePathInContext()) instructions += getLanguageAndFileInfo(); - if (Settings::contextSettings().useProjectChangesCache()) + if (Settings::codeCompletionSettings().useProjectChangesCache()) instructions += ChangesManager::instance().getRecentChangesContext(m_textDocument); return instructions; diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index d94ea72..5a27114 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -26,13 +26,11 @@ #include #include -#include "ConfigurationManager.hpp" #include "DocumentContextReader.hpp" #include "llmcore/PromptTemplateManager.hpp" #include "llmcore/ProvidersManager.hpp" #include "logger/Logger.hpp" #include "settings/CodeCompletionSettings.hpp" -#include "settings/ContextSettings.hpp" #include "settings/GeneralSettings.hpp" namespace QodeAssist { diff --git a/QodeAssistClient.cpp b/QodeAssistClient.cpp index 89549c0..26eb763 100644 --- a/QodeAssistClient.cpp +++ b/QodeAssistClient.cpp @@ -32,7 +32,7 @@ #include "LLMClientInterface.hpp" #include "LLMSuggestion.hpp" #include "core/ChangesManager.h" -#include "settings/ContextSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" #include "settings/GeneralSettings.hpp" using namespace LanguageServerProtocol; @@ -65,52 +65,53 @@ QodeAssistClient::~QodeAssistClient() void QodeAssistClient::openDocument(TextEditor::TextDocument *document) { - // auto project = ProjectManager::projectForFile(document->filePath()); - // if (!isEnabled(project)) - // return; + auto project = ProjectManager::projectForFile(document->filePath()); + if (!isEnabled(project)) + return; - // Client::openDocument(document); - // connect(document, - // &TextDocument::contentsChangedWithPosition, - // this, - // [this, document](int position, int charsRemoved, int charsAdded) { - // Q_UNUSED(charsRemoved) - // if (!Settings::generalSettings().enableAutoComplete()) - // return; + Client::openDocument(document); + connect(document, + &TextDocument::contentsChangedWithPosition, + this, + [this, document](int position, int charsRemoved, int charsAdded) { + Q_UNUSED(charsRemoved) + if (!Settings::codeCompletionSettings().autoCompletion()) + return; - // auto project = ProjectManager::projectForFile(document->filePath()); - // if (!isEnabled(project)) - // return; + auto project = ProjectManager::projectForFile(document->filePath()); + if (!isEnabled(project)) + return; - // auto textEditor = BaseTextEditor::currentTextEditor(); - // if (!textEditor || textEditor->document() != document) - // return; + auto textEditor = BaseTextEditor::currentTextEditor(); + if (!textEditor || textEditor->document() != document) + return; - // if (Settings::contextSettings().useProjectChangesCache()) - // ChangesManager::instance().addChange(document, - // position, - // charsRemoved, - // charsAdded); + if (Settings::codeCompletionSettings().useProjectChangesCache()) + ChangesManager::instance().addChange(document, + position, + charsRemoved, + charsAdded); - // TextEditorWidget *widget = textEditor->editorWidget(); - // if (widget->isReadOnly() || widget->multiTextCursor().hasMultipleCursors()) - // return; - // const int cursorPosition = widget->textCursor().position(); - // if (cursorPosition < position || cursorPosition > position + charsAdded) - // return; + TextEditorWidget *widget = textEditor->editorWidget(); + if (widget->isReadOnly() || widget->multiTextCursor().hasMultipleCursors()) + return; + const int cursorPosition = widget->textCursor().position(); + if (cursorPosition < position || cursorPosition > position + charsAdded) + return; - // m_recentCharCount += charsAdded; + m_recentCharCount += charsAdded; - // if (m_typingTimer.elapsed() - // > Settings::generalSettings().autoCompletionTypingInterval()) { - // m_recentCharCount = charsAdded; - // m_typingTimer.restart(); - // } + if (m_typingTimer.elapsed() + > Settings::codeCompletionSettings().autoCompletionTypingInterval()) { + m_recentCharCount = charsAdded; + m_typingTimer.restart(); + } - // if (m_recentCharCount > Settings::generalSettings().autoCompletionCharThreshold()) { - // scheduleRequest(widget); - // } - // }); + if (m_recentCharCount + > Settings::codeCompletionSettings().autoCompletionCharThreshold()) { + scheduleRequest(widget); + } + }); } bool QodeAssistClient::canOpenProject(ProjectExplorer::Project *project) @@ -144,31 +145,32 @@ void QodeAssistClient::requestCompletions(TextEditor::TextEditorWidget *editor) void QodeAssistClient::scheduleRequest(TextEditor::TextEditorWidget *editor) { - // cancelRunningRequest(editor); + cancelRunningRequest(editor); - // auto it = m_scheduledRequests.find(editor); - // if (it == m_scheduledRequests.end()) { - // auto timer = new QTimer(this); - // timer->setSingleShot(true); - // connect(timer, &QTimer::timeout, this, [this, editor]() { - // if (editor - // && editor->textCursor().position() - // == m_scheduledRequests[editor]->property("cursorPosition").toInt() - // && m_recentCharCount > Settings::generalSettings().autoCompletionCharThreshold()) - // requestCompletions(editor); - // }); - // connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() { - // delete m_scheduledRequests.take(editor); - // cancelRunningRequest(editor); - // }); - // connect(editor, &TextEditorWidget::cursorPositionChanged, this, [this, editor] { - // cancelRunningRequest(editor); - // }); - // it = m_scheduledRequests.insert(editor, timer); - // } + auto it = m_scheduledRequests.find(editor); + if (it == m_scheduledRequests.end()) { + auto timer = new QTimer(this); + timer->setSingleShot(true); + connect(timer, &QTimer::timeout, this, [this, editor]() { + if (editor + && editor->textCursor().position() + == m_scheduledRequests[editor]->property("cursorPosition").toInt() + && m_recentCharCount + > Settings::codeCompletionSettings().autoCompletionCharThreshold()) + requestCompletions(editor); + }); + connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() { + delete m_scheduledRequests.take(editor); + cancelRunningRequest(editor); + }); + connect(editor, &TextEditorWidget::cursorPositionChanged, this, [this, editor] { + cancelRunningRequest(editor); + }); + it = m_scheduledRequests.insert(editor, timer); + } - // it.value()->setProperty("cursorPosition", editor->textCursor().position()); - // it.value()->start(Settings::generalSettings().startSuggestionTimer()); + it.value()->setProperty("cursorPosition", editor->textCursor().position()); + it.value()->start(Settings::codeCompletionSettings().startSuggestionTimer()); } void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &response, TextEditor::TextEditorWidget *editor) diff --git a/chatview/ChatUtils.cpp b/chatview/ChatUtils.cpp index 97079bc..571c35c 100644 --- a/chatview/ChatUtils.cpp +++ b/chatview/ChatUtils.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2024 Petr Mironychev + * + * 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 . + */ + #include "ChatUtils.h" #include diff --git a/chatview/ChatUtils.h b/chatview/ChatUtils.h index fd2c3a6..2584b2c 100644 --- a/chatview/ChatUtils.h +++ b/chatview/ChatUtils.h @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2024 Petr Mironychev + * + * 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 diff --git a/core/ChangesManager.cpp b/core/ChangesManager.cpp index ae5a4ca..40809f3 100644 --- a/core/ChangesManager.cpp +++ b/core/ChangesManager.cpp @@ -18,8 +18,7 @@ */ #include "ChangesManager.h" -#include "logger/Logger.hpp" -#include "settings/ContextSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" namespace QodeAssist { @@ -61,7 +60,7 @@ void ChangesManager::addChange(TextEditor::TextDocument *document, } else { documentQueue.enqueue(change); - if (documentQueue.size() > Settings::contextSettings().maxChangesCacheSize()) { + if (documentQueue.size() > Settings::codeCompletionSettings().maxChangesCacheSize()) { documentQueue.dequeue(); } } diff --git a/llmcore/RequestType.hpp b/llmcore/RequestType.hpp index 80f64d5..763e35e 100644 --- a/llmcore/RequestType.hpp +++ b/llmcore/RequestType.hpp @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2024 Petr Mironychev + * + * 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 namespace QodeAssist::LLMCore { diff --git a/providers/LMStudioProvider.cpp b/providers/LMStudioProvider.cpp index 06bc67e..dde92c8 100644 --- a/providers/LMStudioProvider.cpp +++ b/providers/LMStudioProvider.cpp @@ -26,7 +26,8 @@ #include #include "logger/Logger.hpp" -#include "settings/PresetPromptsSettings.hpp" +#include "settings/ChatAssistantSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" namespace QodeAssist::Providers { @@ -54,36 +55,43 @@ QString LMStudioProvider::chatEndpoint() const void LMStudioProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type) { - auto &promptSettings = Settings::presetPromptsSettings(); - auto settings = promptSettings.getSettings(type); + auto prepareMessages = [](QJsonObject &req) -> QJsonArray { + QJsonArray messages; + if (req.contains("system")) { + messages.append( + QJsonObject{{"role", "system"}, {"content", req.take("system").toString()}}); + } + if (req.contains("prompt")) { + messages.append( + QJsonObject{{"role", "user"}, {"content", req.take("prompt").toString()}}); + } + return messages; + }; - QJsonArray messages; + auto applyModelParams = [&request](const auto &settings) { + request["max_tokens"] = settings.maxTokens(); + request["temperature"] = settings.temperature(); - if (request.contains("system")) { - QJsonObject systemMessage{{"role", "system"}, - {"content", request.take("system").toString()}}; - messages.append(systemMessage); - } - - if (request.contains("prompt")) { - QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}}; - messages.append(userMessage); - } + if (settings.useTopP()) + request["top_p"] = settings.topP(); + if (settings.useTopK()) + request["top_k"] = settings.topK(); + if (settings.useFrequencyPenalty()) + request["frequency_penalty"] = settings.frequencyPenalty(); + if (settings.usePresencePenalty()) + request["presence_penalty"] = settings.presencePenalty(); + }; + QJsonArray messages = prepareMessages(request); if (!messages.isEmpty()) { request["messages"] = std::move(messages); } - request["max_tokens"] = settings.maxTokens; - request["temperature"] = settings.temperature; - if (settings.useTopP) - request["top_p"] = settings.topP; - if (settings.useTopK) - request["top_k"] = settings.topK; - if (settings.useFrequencyPenalty) - request["frequency_penalty"] = settings.frequencyPenalty; - if (settings.usePresencePenalty) - request["presence_penalty"] = settings.presencePenalty; + if (type == LLMCore::RequestType::Fim) { + applyModelParams(Settings::codeCompletionSettings()); + } else { + applyModelParams(Settings::chatAssistantSettings()); + } } bool LMStudioProvider::handleResponse(QNetworkReply *reply, QString &accumulatedResponse) diff --git a/providers/OllamaProvider.cpp b/providers/OllamaProvider.cpp index 223b568..65aa3ce 100644 --- a/providers/OllamaProvider.cpp +++ b/providers/OllamaProvider.cpp @@ -26,7 +26,8 @@ #include #include "logger/Logger.hpp" -#include "settings/PresetPromptsSettings.hpp" +#include "settings/ChatAssistantSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" namespace QodeAssist::Providers { @@ -54,22 +55,29 @@ QString OllamaProvider::chatEndpoint() const void OllamaProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type) { - auto &promptSettings = Settings::presetPromptsSettings(); - auto settings = promptSettings.getSettings(type); + auto applySettings = [&request](const auto &settings) { + QJsonObject options; + options["num_predict"] = settings.maxTokens(); + options["temperature"] = settings.temperature(); - QJsonObject options; - options["num_predict"] = settings.maxTokens; - options["temperature"] = settings.temperature; - if (settings.useTopP) - options["top_p"] = settings.topP; - if (settings.useTopK) - options["top_k"] = settings.topK; - if (settings.useFrequencyPenalty) - options["frequency_penalty"] = settings.frequencyPenalty; - if (settings.usePresencePenalty) - options["presence_penalty"] = settings.presencePenalty; - request["options"] = options; - request["keep_alive"] = settings.ollamaLivetime; + if (settings.useTopP()) + options["top_p"] = settings.topP(); + if (settings.useTopK()) + options["top_k"] = settings.topK(); + if (settings.useFrequencyPenalty()) + options["frequency_penalty"] = settings.frequencyPenalty(); + if (settings.usePresencePenalty()) + options["presence_penalty"] = settings.presencePenalty(); + + request["options"] = options; + request["keep_alive"] = settings.ollamaLivetime(); + }; + + if (type == LLMCore::RequestType::Fim) { + applySettings(Settings::codeCompletionSettings()); + } else { + applySettings(Settings::chatAssistantSettings()); + } } bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedResponse) diff --git a/providers/OpenAICompatProvider.cpp b/providers/OpenAICompatProvider.cpp index 8f7b7e9..a0ea2bb 100644 --- a/providers/OpenAICompatProvider.cpp +++ b/providers/OpenAICompatProvider.cpp @@ -18,14 +18,14 @@ */ #include "OpenAICompatProvider.hpp" +#include "settings/ChatAssistantSettings.hpp" +#include "settings/CodeCompletionSettings.hpp" #include #include #include #include -#include "settings/PresetPromptsSettings.hpp" - namespace QodeAssist::Providers { OpenAICompatProvider::OpenAICompatProvider() {} @@ -52,39 +52,42 @@ QString OpenAICompatProvider::chatEndpoint() const void OpenAICompatProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type) { - auto &promptSettings = Settings::presetPromptsSettings(); - auto settings = promptSettings.getSettings(type); - QJsonArray messages; + auto prepareMessages = [](QJsonObject &req) -> QJsonArray { + QJsonArray messages; + if (req.contains("system")) { + messages.append( + QJsonObject{{"role", "system"}, {"content", req.take("system").toString()}}); + } + if (req.contains("prompt")) { + messages.append( + QJsonObject{{"role", "user"}, {"content", req.take("prompt").toString()}}); + } + return messages; + }; - if (request.contains("system")) { - QJsonObject systemMessage{{"role", "system"}, - {"content", request.take("system").toString()}}; - messages.append(systemMessage); - } + auto applyModelParams = [&request](const auto &settings) { + request["max_tokens"] = settings.maxTokens(); + request["temperature"] = settings.temperature(); - if (request.contains("prompt")) { - QJsonObject userMessage{{"role", "user"}, {"content", request.take("prompt").toString()}}; - messages.append(userMessage); - } + if (settings.useTopP()) + request["top_p"] = settings.topP(); + if (settings.useTopK()) + request["top_k"] = settings.topK(); + if (settings.useFrequencyPenalty()) + request["frequency_penalty"] = settings.frequencyPenalty(); + if (settings.usePresencePenalty()) + request["presence_penalty"] = settings.presencePenalty(); + }; + QJsonArray messages = prepareMessages(request); if (!messages.isEmpty()) { request["messages"] = std::move(messages); } - request["max_tokens"] = settings.maxTokens; - request["temperature"] = settings.temperature; - if (settings.useTopP) - request["top_p"] = settings.topP; - if (settings.useTopK) - request["top_k"] = settings.topK; - if (settings.useFrequencyPenalty) - request["frequency_penalty"] = settings.frequencyPenalty; - if (settings.usePresencePenalty) - request["presence_penalty"] = settings.presencePenalty; - - const QString &apiKey = settings.apiKey; - if (!apiKey.isEmpty()) { - request["api_key"] = apiKey; + if (type == LLMCore::RequestType::Fim) { + applyModelParams(Settings::codeCompletionSettings()); + } else { + applyModelParams(Settings::chatAssistantSettings()); } } diff --git a/settings/CMakeLists.txt b/settings/CMakeLists.txt index 84fe20f..cd4b281 100644 --- a/settings/CMakeLists.txt +++ b/settings/CMakeLists.txt @@ -1,8 +1,6 @@ add_library(QodeAssistSettings STATIC GeneralSettings.hpp GeneralSettings.cpp - ContextSettings.hpp ContextSettings.cpp CustomPromptSettings.hpp CustomPromptSettings.cpp - PresetPromptsSettings.hpp PresetPromptsSettings.cpp SettingsUtils.hpp SettingsConstants.hpp ButtonAspect.hpp diff --git a/settings/CodeCompletionSettings.cpp b/settings/CodeCompletionSettings.cpp index 3379ff6..ebcb46e 100644 --- a/settings/CodeCompletionSettings.cpp +++ b/settings/CodeCompletionSettings.cpp @@ -51,6 +51,27 @@ CodeCompletionSettings::CodeCompletionSettings() multiLineCompletion.setDefaultValue(false); multiLineCompletion.setLabelText(Tr::tr("Enable Multiline Completion(experimental)")); + startSuggestionTimer.setSettingsKey(Constants::СС_START_SUGGESTION_TIMER); + startSuggestionTimer.setLabelText(Tr::tr("with delay(ms)")); + startSuggestionTimer.setRange(10, 10000); + startSuggestionTimer.setDefaultValue(500); + + autoCompletionCharThreshold.setSettingsKey(Constants::СС_AUTO_COMPLETION_CHAR_THRESHOLD); + autoCompletionCharThreshold.setLabelText(Tr::tr("AI suggestion triggers after typing")); + autoCompletionCharThreshold.setToolTip( + Tr::tr("The number of characters that need to be typed within the typing interval " + "before an AI suggestion request is sent.")); + autoCompletionCharThreshold.setRange(0, 10); + autoCompletionCharThreshold.setDefaultValue(0); + + autoCompletionTypingInterval.setSettingsKey(Constants::СС_AUTO_COMPLETION_TYPING_INTERVAL); + autoCompletionTypingInterval.setLabelText(Tr::tr("character(s) within(ms)")); + autoCompletionTypingInterval.setToolTip( + Tr::tr("The time window (in milliseconds) during which the character threshold " + "must be met to trigger an AI suggestion request.")); + autoCompletionTypingInterval.setRange(500, 5000); + autoCompletionTypingInterval.setDefaultValue(2000); + // General Parameters Settings temperature.setSettingsKey(Constants::CC_TEMPERATURE); temperature.setLabelText(Tr::tr("Temperature:")); @@ -136,7 +157,7 @@ CodeCompletionSettings::CodeCompletionSettings() maxChangesCacheSize.setSettingsKey(Constants::CC_MAX_CHANGES_CACHE_SIZE); maxChangesCacheSize.setRange(2, 1000); - maxChangesCacheSize.setDefaultValue(20); + maxChangesCacheSize.setDefaultValue(10); // Ollama Settings ollamaLivetime.setSettingsKey(Constants::CC_OLLAMA_LIVETIME); @@ -196,11 +217,13 @@ CodeCompletionSettings::CodeCompletionSettings() return Column{Row{Stretch{1}, resetToDefaults}, Space{8}, Group{title(Tr::tr("Auto Completion Settings")), - Column{ - autoCompletion, - Space{8}, - multiLineCompletion, - }}, + Column{autoCompletion, + Space{8}, + multiLineCompletion, + Row{autoCompletionCharThreshold, + autoCompletionTypingInterval, + startSuggestionTimer, + Stretch{1}}}}, Space{8}, Group{title(Tr::tr("General Parameters")), Column{ diff --git a/settings/CodeCompletionSettings.hpp b/settings/CodeCompletionSettings.hpp index 52b2d8f..c6b990c 100644 --- a/settings/CodeCompletionSettings.hpp +++ b/settings/CodeCompletionSettings.hpp @@ -36,6 +36,10 @@ public: Utils::BoolAspect autoCompletion{this}; Utils::BoolAspect multiLineCompletion{this}; + Utils::IntegerAspect startSuggestionTimer{this}; + Utils::IntegerAspect autoCompletionCharThreshold{this}; + Utils::IntegerAspect autoCompletionTypingInterval{this}; + // General Parameters Settings Utils::DoubleAspect temperature{this}; Utils::IntegerAspect maxTokens{this}; diff --git a/settings/GeneralSettings.cpp b/settings/GeneralSettings.cpp index bfab84f..ea39e9b 100644 --- a/settings/GeneralSettings.cpp +++ b/settings/GeneralSettings.cpp @@ -60,6 +60,7 @@ GeneralSettings::GeneralSettings() ccSelectProvider.m_buttonText = TrConstants::SELECT; initStringAspect(ccModel, Constants::CC_MODEL, TrConstants::MODEL, "codellama:7b-code"); + ccModel.setHistoryCompleter(Constants::CC_MODEL_HISTORY); ccSelectModel.m_buttonText = TrConstants::SELECT; initStringAspect(ccTemplate, Constants::CC_TEMPLATE, TrConstants::TEMPLATE, "CodeLlama FIM"); @@ -67,6 +68,7 @@ GeneralSettings::GeneralSettings() ccSelectTemplate.m_buttonText = TrConstants::SELECT; initStringAspect(ccUrl, Constants::CC_URL, TrConstants::URL, "http://localhost:11434"); + ccUrl.setHistoryCompleter(Constants::CC_URL_HISTORY); ccSetUrl.m_buttonText = TrConstants::SELECT; ccStatus.setDisplayStyle(Utils::StringAspect::LabelDisplay); @@ -79,6 +81,7 @@ GeneralSettings::GeneralSettings() caSelectProvider.m_buttonText = TrConstants::SELECT; initStringAspect(caModel, Constants::CA_MODEL, TrConstants::MODEL, "codellama:7b-instruct"); + caModel.setHistoryCompleter(Constants::CA_MODEL_HISTORY); caSelectModel.m_buttonText = TrConstants::SELECT; initStringAspect(caTemplate, Constants::CA_TEMPLATE, TrConstants::TEMPLATE, "CodeLlama Chat"); @@ -87,6 +90,7 @@ GeneralSettings::GeneralSettings() caSelectTemplate.m_buttonText = TrConstants::SELECT; initStringAspect(caUrl, Constants::CA_URL, TrConstants::URL, "http://localhost:11434"); + caUrl.setHistoryCompleter(Constants::CA_URL_HISTORY); caSetUrl.m_buttonText = TrConstants::SELECT; caStatus.setDisplayStyle(Utils::StringAspect::LabelDisplay); diff --git a/settings/SettingsConstants.hpp b/settings/SettingsConstants.hpp index b7e9074..1eae254 100644 --- a/settings/SettingsConstants.hpp +++ b/settings/SettingsConstants.hpp @@ -27,22 +27,26 @@ const char MENU_ID[] = "QodeAssist.Menu"; // new settings const char CC_PROVIDER[] = "QodeAssist.ccProvider"; const char CC_MODEL[] = "QodeAssist.ccModel"; +const char CC_MODEL_HISTORY[] = "QodeAssist.ccModelHistory"; const char CC_TEMPLATE[] = "QodeAssist.ccTemplate"; const char CC_URL[] = "QodeAssist.ccUrl"; +const char CC_URL_HISTORY[] = "QodeAssist.ccUrlHistory"; const char CA_PROVIDER[] = "QodeAssist.caProvider"; const char CA_MODEL[] = "QodeAssist.caModel"; +const char CA_MODEL_HISTORY[] = "QodeAssist.caModelHistory"; const char CA_TEMPLATE[] = "QodeAssist.caTemplate"; const char CA_URL[] = "QodeAssist.caUrl"; +const char CA_URL_HISTORY[] = "QodeAssist.caUrlHistory"; // settings const char ENABLE_QODE_ASSIST[] = "QodeAssist.enableQodeAssist"; const char CC_AUTO_COMPLETION[] = "QodeAssist.ccAutoCompletion"; const char ENABLE_LOGGING[] = "QodeAssist.enableLogging"; const char PROVIDER_PATHS[] = "QodeAssist.providerPaths"; -const char START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer"; -const char AUTO_COMPLETION_CHAR_THRESHOLD[] = "QodeAssist.autoCompletionCharThreshold"; -const char AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval"; +const char СС_START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer"; +const char СС_AUTO_COMPLETION_CHAR_THRESHOLD[] = "QodeAssist.autoCompletionCharThreshold"; +const char СС_AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion"; const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate"; @@ -54,10 +58,7 @@ const char QODE_ASSIST_CODE_COMPLETION_SETTINGS_PAGE_ID[] = "QodeAssist.2CodeCompletionSettingsPageId"; const char QODE_ASSIST_CHAT_ASSISTANT_SETTINGS_PAGE_ID[] = "QodeAssist.3ChatAssistantSettingsPageId"; -const char QODE_ASSIST_CONTEXT_SETTINGS_PAGE_ID[] = "QodeAssist.4ContextSettingsPageId"; -const char QODE_ASSIST_PRESET_PROMPTS_SETTINGS_PAGE_ID[] - = "QodeAssist.5PresetPromptsSettingsPageId"; -const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.6CustomPromptSettingsPageId"; +const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.4CustomPromptSettingsPageId"; const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category"; const char QODE_ASSIST_GENERAL_OPTIONS_DISPLAY_CATEGORY[] = "Qode Assist";