Add Claude provider and templates for chat and code (#55)

* feat: Add provider settings
* feat: Add Claude provider
* feat: Add Claude templates
* refactor: Setting input sensitivity
* fix: Back text after read code block
* fix: Add missing system message for ollama fim
This commit is contained in:
Petr Mironychev
2024-12-23 22:22:01 +01:00
committed by GitHub
parent d8ef9d0120
commit d04e5bc967
28 changed files with 683 additions and 56 deletions

View File

@ -10,6 +10,7 @@ add_library(QodeAssistSettings STATIC
SettingsDialog.hpp SettingsDialog.cpp
ProjectSettings.hpp ProjectSettings.cpp
ProjectSettingsPanel.hpp ProjectSettingsPanel.cpp
ProviderSettings.hpp ProviderSettings.cpp
)
target_link_libraries(QodeAssistSettings

View File

@ -62,7 +62,7 @@ CodeCompletionSettings::CodeCompletionSettings()
startSuggestionTimer.setSettingsKey(Constants::СС_START_SUGGESTION_TIMER);
startSuggestionTimer.setLabelText(Tr::tr("with delay(ms)"));
startSuggestionTimer.setRange(10, 10000);
startSuggestionTimer.setDefaultValue(500);
startSuggestionTimer.setDefaultValue(350);
autoCompletionCharThreshold.setSettingsKey(Constants::СС_AUTO_COMPLETION_CHAR_THRESHOLD);
autoCompletionCharThreshold.setLabelText(Tr::tr("AI suggestion triggers after typing"));
@ -70,7 +70,7 @@ CodeCompletionSettings::CodeCompletionSettings()
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);
autoCompletionCharThreshold.setDefaultValue(1);
autoCompletionTypingInterval.setSettingsKey(Constants::СС_AUTO_COMPLETION_TYPING_INTERVAL);
autoCompletionTypingInterval.setLabelText(Tr::tr("character(s) within(ms)"));
@ -78,7 +78,7 @@ CodeCompletionSettings::CodeCompletionSettings()
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);
autoCompletionTypingInterval.setDefaultValue(1200);
// General Parameters Settings
temperature.setSettingsKey(Constants::CC_TEMPERATURE);
@ -151,8 +151,10 @@ CodeCompletionSettings::CodeCompletionSettings()
systemPrompt.setSettingsKey(Constants::CC_SYSTEM_PROMPT);
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
systemPrompt.setDefaultValue("You are an expert C++, Qt, and QML code completion AI. Answer "
"should be ONLY in CODE and without repeating current.");
systemPrompt.setDefaultValue(
"You are an expert C++, Qt, and QML. You insert the code into the areas where the user "
"specifies. In answer should be ONLY code suggestions in code block, without comments or "
"description. Don't repeat existing code. Complete ONLY one logic expression.");
useFilePathInContext.setSettingsKey(Constants::CC_USE_FILE_PATH_IN_CONTEXT);
useFilePathInContext.setDefaultValue(true);

View File

@ -0,0 +1,136 @@
/*
* 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/>.
*/
#include "ProviderSettings.hpp"
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <QMessageBox>
#include "SettingsConstants.hpp"
#include "SettingsTr.hpp"
#include "SettingsUtils.hpp"
namespace QodeAssist::Settings {
ProviderSettings &providerSettings()
{
static ProviderSettings settings;
return settings;
}
ProviderSettings::ProviderSettings()
{
setAutoApply(false);
setDisplayName(Tr::tr("Provider Settings"));
// OpenRouter Settings
openRouterApiKey.setSettingsKey(Constants::OPEN_ROUTER_API_KEY);
openRouterApiKey.setLabelText(Tr::tr("OpenRouter API Key:"));
openRouterApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
openRouterApiKey.setPlaceHolderText(Tr::tr("Enter your API key here"));
openRouterApiKey.setHistoryCompleter(Constants::OPEN_ROUTER_API_KEY_HISTORY);
openRouterApiKey.setDefaultValue("");
openRouterApiKey.setAutoApply(true);
// OpenAI Compatible Settings
openAiCompatApiKey.setSettingsKey(Constants::OPEN_AI_COMPAT_API_KEY);
openAiCompatApiKey.setLabelText(Tr::tr("OpenAI Compatible API Key:"));
openAiCompatApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
openAiCompatApiKey.setPlaceHolderText(Tr::tr("Enter your API key here"));
openAiCompatApiKey.setHistoryCompleter(Constants::OPEN_AI_COMPAT_API_KEY_HISTORY);
openAiCompatApiKey.setDefaultValue("");
openAiCompatApiKey.setAutoApply(true);
// Claude Compatible Settings
claudeApiKey.setSettingsKey(Constants::CLAUDE_API_KEY);
claudeApiKey.setLabelText(Tr::tr("Claude API Key:"));
claudeApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
claudeApiKey.setPlaceHolderText(Tr::tr("Enter your API key here"));
claudeApiKey.setHistoryCompleter(Constants::CLAUDE_API_KEY_HISTORY);
claudeApiKey.setDefaultValue("");
claudeApiKey.setAutoApply(true);
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
readSettings();
setupConnections();
setLayouter([this]() {
using namespace Layouting;
return Column{
Row{Stretch{1}, resetToDefaults},
Space{8},
Group{title(Tr::tr("OpenRouter Settings")), Column{openRouterApiKey}},
Space{8},
Group{title(Tr::tr("OpenAI Compatible Settings")), Column{openAiCompatApiKey}},
Space{8},
Group{title(Tr::tr("Claude Settings")), Column{claudeApiKey}},
Stretch{1}};
});
}
void ProviderSettings::setupConnections()
{
connect(
&resetToDefaults, &ButtonAspect::clicked, this, &ProviderSettings::resetSettingsToDefaults);
connect(&openRouterApiKey, &ButtonAspect::changed, this, [this]() {
openRouterApiKey.writeSettings();
});
connect(&openAiCompatApiKey, &ButtonAspect::changed, this, [this]() {
openAiCompatApiKey.writeSettings();
});
connect(&claudeApiKey, &ButtonAspect::changed, this, [this]() { claudeApiKey.writeSettings(); });
}
void ProviderSettings::resetSettingsToDefaults()
{
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(openRouterApiKey);
resetAspect(openAiCompatApiKey);
resetAspect(claudeApiKey);
}
}
class ProviderSettingsPage : public Core::IOptionsPage
{
public:
ProviderSettingsPage()
{
setId(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
setDisplayName(Tr::tr("Provider Settings"));
setCategory(Constants::QODE_ASSIST_GENERAL_OPTIONS_CATEGORY);
setSettingsProvider([] { return &providerSettings(); });
}
};
const ProviderSettingsPage providerSettingsPage;
} // namespace QodeAssist::Settings

View File

@ -0,0 +1,47 @@
/*
* 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 <utils/aspects.h>
#include "ButtonAspect.hpp"
namespace QodeAssist::Settings {
class ProviderSettings : public Utils::AspectContainer
{
public:
ProviderSettings();
ButtonAspect resetToDefaults{this};
// API Keys
Utils::StringAspect openRouterApiKey{this};
Utils::StringAspect openAiCompatApiKey{this};
Utils::StringAspect claudeApiKey{this};
private:
void setupConnections();
void resetSettingsToDefaults();
};
ProviderSettings &providerSettings();
} // namespace QodeAssist::Settings

View File

@ -77,6 +77,17 @@ const char QODE_ASSIST_GENERAL_OPTIONS_DISPLAY_CATEGORY[] = "Qode Assist";
const char QODE_ASSIST_REQUEST_SUGGESTION[] = "QodeAssist.RequestSuggestion";
// Provider Settings Page ID
const char QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID[] = "QodeAssist.5ProviderSettingsPageId";
// Provider API Keys
const char OPEN_ROUTER_API_KEY[] = "QodeAssist.openRouterApiKey";
const char OPEN_ROUTER_API_KEY_HISTORY[] = "QodeAssist.openRouterApiKeyHistory";
const char OPEN_AI_COMPAT_API_KEY[] = "QodeAssist.openAiCompatApiKey";
const char OPEN_AI_COMPAT_API_KEY_HISTORY[] = "QodeAssist.openAiCompatApiKeyHistory";
const char CLAUDE_API_KEY[] = "QodeAssist.claudeApiKey";
const char CLAUDE_API_KEY_HISTORY[] = "QodeAssist.claudeApiKeyHistory";
// context settings
const char CC_READ_FULL_FILE[] = "QodeAssist.ccReadFullFile";
const char CC_READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.ccReadStringsBeforeCursor";