Skip to content

Commit

Permalink
Move Settings to library
Browse files Browse the repository at this point in the history
  • Loading branch information
Palm1r committed Oct 9, 2024
1 parent e019650 commit ec19566
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 81 deletions.
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.16)

list(APPEND CMAKE_PREFIX_PATH "/Users/palm1r/Qt/Qt Creator.app/Contents/Resources/lib/cmake/QtCreator")

project(QodeAssist)

set(CMAKE_AUTOMOC ON)
Expand All @@ -16,6 +14,7 @@ find_package(Qt6 COMPONENTS Core Gui Widgets Network REQUIRED)

add_subdirectory(llmcore)
add_subdirectory(chatview)
add_subdirectory(settings)

add_qtc_plugin(QodeAssist
PLUGIN_DEPENDS
Expand Down Expand Up @@ -51,16 +50,16 @@ add_qtc_plugin(QodeAssist
QodeAssistUtils.hpp
DocumentContextReader.hpp DocumentContextReader.cpp
utils/CounterTooltip.hpp utils/CounterTooltip.cpp
settings/GeneralSettings.hpp settings/GeneralSettings.cpp
settings/ContextSettings.hpp settings/ContextSettings.cpp
settings/CustomPromptSettings.hpp settings/CustomPromptSettings.cpp
settings/PresetPromptsSettings.hpp settings/PresetPromptsSettings.cpp
settings/SettingsUtils.hpp
# settings/GeneralSettings.hpp settings/GeneralSettings.cpp
# settings/ContextSettings.hpp settings/ContextSettings.cpp
# settings/CustomPromptSettings.hpp settings/CustomPromptSettings.cpp
# settings/PresetPromptsSettings.hpp settings/PresetPromptsSettings.cpp
# settings/SettingsUtils.hpp
core/ChangesManager.h core/ChangesManager.cpp
chat/ChatWidget.h chat/ChatWidget.cpp
chat/ChatOutputPane.h chat/ChatOutputPane.cpp
chat/ChatClientInterface.hpp chat/ChatClientInterface.cpp
chat/NavigationPanel.hpp chat/NavigationPanel.cpp
)

target_link_libraries(QodeAssist PRIVATE LLMCore QodeAssistChatViewplugin)
target_link_libraries(QodeAssist PRIVATE QodeAssistSettings LLMCore QodeAssistChatViewplugin)
54 changes: 0 additions & 54 deletions QodeAssistConstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,6 @@ namespace QodeAssist::Constants {
const char ACTION_ID[] = "QodeAssist.Action";
const char MENU_ID[] = "QodeAssist.Menu";

// settings
const char ENABLE_QODE_ASSIST[] = "QodeAssist.enableQodeAssist";
const char ENABLE_AUTO_COMPLETE[] = "QodeAssist.enableAutoComplete";
const char ENABLE_LOGGING[] = "QodeAssist.enableLogging";
const char LLM_PROVIDERS[] = "QodeAssist.llmProviders";
const char URL[] = "QodeAssist.url";
const char END_POINT[] = "QodeAssist.endPoint";
const char MODEL_NAME[] = "QodeAssist.modelName";
const char SELECT_MODELS[] = "QodeAssist.selectModels";
const char FIM_PROMPTS[] = "QodeAssist.fimPrompts";
const char TEMPERATURE[] = "QodeAssist.temperature";
const char MAX_TOKENS[] = "QodeAssist.maxTokens";
const char READ_FULL_FILE[] = "QodeAssist.readFullFile";
const char READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.readStringsBeforeCursor";
const char READ_STRINGS_AFTER_CURSOR[] = "QodeAssist.readStringsAfterCursor";
const char USE_TOP_P[] = "QodeAssist.useTopP";
const char TOP_P[] = "QodeAssist.topP";
const char USE_TOP_K[] = "QodeAssist.useTopK";
const char TOP_K[] = "QodeAssist.topK";
const char USE_PRESENCE_PENALTY[] = "QodeAssist.usePresencePenalty";
const char PRESENCE_PENALTY[] = "QodeAssist.presencePenalty";
const char USE_FREQUENCY_PENALTY[] = "QodeAssist.useFrequencyPenalty";
const char FREQUENCY_PENALTY[] = "QodeAssist.frequencyPenalty";
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 MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime";
const char SYSTEM_PROMPT[] = "QodeAssist.systemPrompt";
const char MULTILINE_COMPLETION[] = "QodeAssist.multilineCompletion";
const char API_KEY[] = "QodeAssist.apiKey";
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";
const char MAX_CHANGES_CACHE_SIZE[] = "QodeAssist.maxChangesCacheSize";
const char CHAT_LLM_PROVIDERS[] = "QodeAssist.chatLlmProviders";
const char CHAT_URL[] = "QodeAssist.chatUrl";
const char CHAT_END_POINT[] = "QodeAssist.chatEndPoint";
const char CHAT_MODEL_NAME[] = "QodeAssist.chatModelName";
const char CHAT_SELECT_MODELS[] = "QodeAssist.chatSelectModels";
const char CHAT_PROMPTS[] = "QodeAssist.chatPrompts";

const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
const char QODE_ASSIST_CONTEXT_SETTINGS_PAGE_ID[] = "QodeAssist.2ContextSettingsPageId";
const char QODE_ASSIST_PRESET_PROMPTS_SETTINGS_PAGE_ID[]
= "QodeAssist.3PresetPromptsSettingsPageId";
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";

const char QODE_ASSIST_REQUEST_SUGGESTION[] = "QodeAssist.RequestSuggestion";

} // namespace QodeAssist::Constants
3 changes: 2 additions & 1 deletion llmcore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(QtCreator REQUIRED COMPONENTS Core)
find_package(QtCreator REQUIRED COMPONENTS Core Utils ExtensionSystem)
find_package(Qt6 COMPONENTS Core Gui Widgets Network REQUIRED)

add_library(LLMCore STATIC
Expand All @@ -20,6 +20,7 @@ target_link_libraries(LLMCore
Qt::Network
QtCreator::Core
QtCreator::Utils
QtCreator::ExtensionSystem
)

set_target_properties(LLMCore PROPERTIES
Expand Down
31 changes: 31 additions & 0 deletions settings/Assisttr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <QCoreApplication>

namespace QodeAssist {

struct Tr
{
Q_DECLARE_TR_FUNCTIONS(QtC::QodeAssist)
};

} // namespace QodeAssist
26 changes: 26 additions & 0 deletions settings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
find_package(QtCreator REQUIRED COMPONENTS Core)

add_library(QodeAssistSettings STATIC
GeneralSettings.hpp GeneralSettings.cpp
ContextSettings.hpp ContextSettings.cpp
CustomPromptSettings.hpp CustomPromptSettings.cpp
PresetPromptsSettings.hpp PresetPromptsSettings.cpp
SettingsUtils.hpp
SettingsConstants.hpp
)

target_include_directories(QodeAssistSettings PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(QodeAssistSettings
PRIVATE
Qt::Core
Qt::Network
QtCreator::Core
QtCreator::Utils
LLMCore
)

set_target_properties(QodeAssistSettings PROPERTIES
PUBLIC_HEADER
"GeneralSettings.hpp;ContextSettings.hpp;CustomPromptSettings.hpp;PresetPromptsSettings.hpp;SettingsUtils.hpp"
)
3 changes: 1 addition & 2 deletions settings/ContextSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>

#include "QodeAssistConstants.hpp"
#include "QodeAssisttr.h"
#include "SettingsConstants.hpp"

namespace QodeAssist::Settings {
ContextSettings &contextSettings()
Expand Down
3 changes: 1 addition & 2 deletions settings/CustomPromptSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>

#include "QodeAssistConstants.hpp"
#include "QodeAssisttr.h"
#include "SettingsConstants.hpp"

namespace QodeAssist::Settings {

Expand Down
2 changes: 1 addition & 1 deletion settings/CustomPromptSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#pragma once

#include "settings/SettingsUtils.hpp"
#include "SettingsUtils.hpp"
#include <utils/aspects.h>

namespace QodeAssist::Settings {
Expand Down
13 changes: 6 additions & 7 deletions settings/GeneralSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

#include "PromptTemplateManager.hpp"
#include "ProvidersManager.hpp"
#include "QodeAssistConstants.hpp"
#include "QodeAssistUtils.hpp"
#include "QodeAssisttr.h"
#include "SettingsConstants.hpp"
// #include "QodeAssistUtils.hpp"

namespace QodeAssist::Settings {

Expand Down Expand Up @@ -148,7 +147,7 @@ GeneralSettings::GeneralSettings()
auto nameChatPromts = chatPrompts.displayForIndex(chatPrompts.value());
LLMCore::PromptTemplateManager::instance().setCurrentChatTemplate(nameChatPromts);

setLoggingEnabled(enableLogging());
// setLoggingEnabled(enableLogging());

setupConnections();

Expand Down Expand Up @@ -218,7 +217,7 @@ void GeneralSettings::setupConnections()
});

connect(&enableLogging, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
setLoggingEnabled(enableLogging.volatileValue());
// setLoggingEnabled(enableLogging.volatileValue());
});
connect(&resetToDefaults, &ButtonAspect::clicked, this, &GeneralSettings::resetPageToDefaults);

Expand Down Expand Up @@ -303,12 +302,12 @@ void GeneralSettings::updateStatusIndicators()
bool fimPingSuccessful = false;
if (fimUrlValid) {
QUrl pingUrl(url.volatileValue());
fimPingSuccessful = QodeAssist::pingUrl(pingUrl);
// fimPingSuccessful = QodeAssist::pingUrl(pingUrl);
}
bool chatPingSuccessful = false;
if (chatUrlValid) {
QUrl pingUrl(chatUrl.volatileValue());
chatPingSuccessful = QodeAssist::pingUrl(pingUrl);
// chatPingSuccessful = QodeAssist::pingUrl(pingUrl);
}

setIndicatorStatus(fimModelIndicator,
Expand Down
5 changes: 2 additions & 3 deletions settings/GeneralSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

#include <utils/aspects.h>

// #include "providers/Provider.hpp"
#include <llmcore/Provider.hpp>
#include <Provider.hpp>

#include "settings/SettingsUtils.hpp"
#include "SettingsUtils.hpp"

namespace QodeAssist::Settings {

Expand Down
3 changes: 1 addition & 2 deletions settings/PresetPromptsSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>

#include "QodeAssistConstants.hpp"
#include "QodeAssisttr.h"
#include "SettingsConstants.hpp"

namespace QodeAssist::Settings {

Expand Down
2 changes: 1 addition & 1 deletion settings/PresetPromptsSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#pragma once

#include "settings/SettingsUtils.hpp"
#include "SettingsUtils.hpp"
#include <utils/aspects.h>

namespace QodeAssist::Settings {
Expand Down
83 changes: 83 additions & 0 deletions settings/SettingsConstants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

#pragma once

namespace QodeAssist::Constants {

const char ACTION_ID[] = "QodeAssist.Action";
const char MENU_ID[] = "QodeAssist.Menu";

// settings
const char ENABLE_QODE_ASSIST[] = "QodeAssist.enableQodeAssist";
const char ENABLE_AUTO_COMPLETE[] = "QodeAssist.enableAutoComplete";
const char ENABLE_LOGGING[] = "QodeAssist.enableLogging";
const char LLM_PROVIDERS[] = "QodeAssist.llmProviders";
const char URL[] = "QodeAssist.url";
const char END_POINT[] = "QodeAssist.endPoint";
const char MODEL_NAME[] = "QodeAssist.modelName";
const char SELECT_MODELS[] = "QodeAssist.selectModels";
const char FIM_PROMPTS[] = "QodeAssist.fimPrompts";
const char TEMPERATURE[] = "QodeAssist.temperature";
const char MAX_TOKENS[] = "QodeAssist.maxTokens";
const char READ_FULL_FILE[] = "QodeAssist.readFullFile";
const char READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.readStringsBeforeCursor";
const char READ_STRINGS_AFTER_CURSOR[] = "QodeAssist.readStringsAfterCursor";
const char USE_TOP_P[] = "QodeAssist.useTopP";
const char TOP_P[] = "QodeAssist.topP";
const char USE_TOP_K[] = "QodeAssist.useTopK";
const char TOP_K[] = "QodeAssist.topK";
const char USE_PRESENCE_PENALTY[] = "QodeAssist.usePresencePenalty";
const char PRESENCE_PENALTY[] = "QodeAssist.presencePenalty";
const char USE_FREQUENCY_PENALTY[] = "QodeAssist.useFrequencyPenalty";
const char FREQUENCY_PENALTY[] = "QodeAssist.frequencyPenalty";
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 MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime";
const char SYSTEM_PROMPT[] = "QodeAssist.systemPrompt";
const char MULTILINE_COMPLETION[] = "QodeAssist.multilineCompletion";
const char API_KEY[] = "QodeAssist.apiKey";
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";
const char MAX_CHANGES_CACHE_SIZE[] = "QodeAssist.maxChangesCacheSize";
const char CHAT_LLM_PROVIDERS[] = "QodeAssist.chatLlmProviders";
const char CHAT_URL[] = "QodeAssist.chatUrl";
const char CHAT_END_POINT[] = "QodeAssist.chatEndPoint";
const char CHAT_MODEL_NAME[] = "QodeAssist.chatModelName";
const char CHAT_SELECT_MODELS[] = "QodeAssist.chatSelectModels";
const char CHAT_PROMPTS[] = "QodeAssist.chatPrompts";

const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
const char QODE_ASSIST_CONTEXT_SETTINGS_PAGE_ID[] = "QodeAssist.2ContextSettingsPageId";
const char QODE_ASSIST_PRESET_PROMPTS_SETTINGS_PAGE_ID[]
= "QodeAssist.3PresetPromptsSettingsPageId";
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";

const char QODE_ASSIST_REQUEST_SUGGESTION[] = "QodeAssist.RequestSuggestion";

} // namespace QodeAssist::Constants
6 changes: 6 additions & 0 deletions settings/SettingsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

#pragma once

#include <QCoreApplication>
#include <QPushButton>
#include <utils/aspects.h>
#include <utils/layoutbuilder.h>

namespace QodeAssist::Settings {

struct Tr
{
Q_DECLARE_TR_FUNCTIONS(QtC::QodeAssist)
};

template<typename AspectType>
void resetAspect(AspectType &aspect)
{
Expand Down

0 comments on commit ec19566

Please sign in to comment.