From 9a54f04a0d1ec2a1caade44f0e3a6f77a7b3bdca Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Sun, 20 Apr 2025 09:48:36 +0200 Subject: [PATCH] feat: Add Codestral as separate ai provider (#171) --- CMakeLists.txt | 1 + providers/CodestralProvider.cpp | 46 +++++++++++++++++++++++++++++++++ providers/CodestralProvider.hpp | 35 +++++++++++++++++++++++++ providers/Providers.hpp | 2 ++ settings/ProviderSettings.cpp | 10 ++++++- settings/ProviderSettings.hpp | 1 + settings/SettingsConstants.hpp | 2 ++ 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 providers/CodestralProvider.cpp create mode 100644 providers/CodestralProvider.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ce868b..0e19ab4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ add_qtc_plugin(QodeAssist providers/OpenRouterAIProvider.hpp providers/OpenRouterAIProvider.cpp providers/GoogleAIProvider.hpp providers/GoogleAIProvider.cpp providers/LlamaCppProvider.hpp providers/LlamaCppProvider.cpp + providers/CodestralProvider.hpp providers/CodestralProvider.cpp QodeAssist.qrc LSPCompletion.hpp LLMSuggestion.hpp LLMSuggestion.cpp diff --git a/providers/CodestralProvider.cpp b/providers/CodestralProvider.cpp new file mode 100644 index 0000000..8c2902f --- /dev/null +++ b/providers/CodestralProvider.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2025 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 "CodestralProvider.hpp" + +#include "settings/ProviderSettings.hpp" + +namespace QodeAssist::Providers { + +QString CodestralProvider::name() const +{ + return "Codestral"; +} + +QString CodestralProvider::url() const +{ + return "https://codestral.mistral.ai"; +} + +bool CodestralProvider::supportsModelListing() const +{ + return false; +} + +QString CodestralProvider::apiKey() const +{ + return Settings::providerSettings().codestralApiKey(); +} + +} // namespace QodeAssist::Providers diff --git a/providers/CodestralProvider.hpp b/providers/CodestralProvider.hpp new file mode 100644 index 0000000..e4ea63c --- /dev/null +++ b/providers/CodestralProvider.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2025 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 "MistralAIProvider.hpp" + +namespace QodeAssist::Providers { + +class CodestralProvider : public MistralAIProvider +{ +public: + QString name() const override; + QString url() const override; + bool supportsModelListing() const override; + QString apiKey() const override; +}; + +} // namespace QodeAssist::Providers diff --git a/providers/Providers.hpp b/providers/Providers.hpp index 2159659..989fb52 100644 --- a/providers/Providers.hpp +++ b/providers/Providers.hpp @@ -21,6 +21,7 @@ #include "llmcore/ProvidersManager.hpp" #include "providers/ClaudeProvider.hpp" +#include "providers/CodestralProvider.hpp" #include "providers/GoogleAIProvider.hpp" #include "providers/LMStudioProvider.hpp" #include "providers/LlamaCppProvider.hpp" @@ -44,6 +45,7 @@ inline void registerProviders() providerManager.registerProvider(); providerManager.registerProvider(); providerManager.registerProvider(); + providerManager.registerProvider(); } } // namespace QodeAssist::Providers diff --git a/settings/ProviderSettings.cpp b/settings/ProviderSettings.cpp index a681dbf..01b10eb 100644 --- a/settings/ProviderSettings.cpp +++ b/settings/ProviderSettings.cpp @@ -87,6 +87,14 @@ ProviderSettings::ProviderSettings() mistralAiApiKey.setDefaultValue(""); mistralAiApiKey.setAutoApply(true); + codestralApiKey.setSettingsKey(Constants::CODESTRAL_API_KEY); + codestralApiKey.setLabelText(Tr::tr("Codestral API Key:")); + codestralApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay); + codestralApiKey.setPlaceHolderText(Tr::tr("Enter your API key here")); + codestralApiKey.setHistoryCompleter(Constants::CODESTRAL_API_KEY_HISTORY); + codestralApiKey.setDefaultValue(""); + codestralApiKey.setAutoApply(true); + // GoogleAI Settings googleAiApiKey.setSettingsKey(Constants::GOOGLE_AI_API_KEY); googleAiApiKey.setLabelText(Tr::tr("Google AI API Key:")); @@ -125,7 +133,7 @@ ProviderSettings::ProviderSettings() Space{8}, Group{title(Tr::tr("Claude Settings")), Column{claudeApiKey}}, Space{8}, - Group{title(Tr::tr("Mistral AI Settings")), Column{mistralAiApiKey}}, + Group{title(Tr::tr("Mistral AI Settings")), Column{mistralAiApiKey, codestralApiKey}}, Space{8}, Group{title(Tr::tr("Google AI Settings")), Column{googleAiApiKey}}, Space{8}, diff --git a/settings/ProviderSettings.hpp b/settings/ProviderSettings.hpp index c401c27..dfae5fa 100644 --- a/settings/ProviderSettings.hpp +++ b/settings/ProviderSettings.hpp @@ -38,6 +38,7 @@ public: Utils::StringAspect claudeApiKey{this}; Utils::StringAspect openAiApiKey{this}; Utils::StringAspect mistralAiApiKey{this}; + Utils::StringAspect codestralApiKey{this}; Utils::StringAspect googleAiApiKey{this}; Utils::StringAspect ollamaBasicAuthApiKey{this}; diff --git a/settings/SettingsConstants.hpp b/settings/SettingsConstants.hpp index 7dc5fab..35c2147 100644 --- a/settings/SettingsConstants.hpp +++ b/settings/SettingsConstants.hpp @@ -101,6 +101,8 @@ const char OPEN_AI_API_KEY[] = "QodeAssist.openAiApiKey"; const char OPEN_AI_API_KEY_HISTORY[] = "QodeAssist.openAiApiKeyHistory"; const char MISTRAL_AI_API_KEY[] = "QodeAssist.mistralAiApiKey"; const char MISTRAL_AI_API_KEY_HISTORY[] = "QodeAssist.mistralAiApiKeyHistory"; +const char CODESTRAL_API_KEY[] = "QodeAssist.codestralApiKey"; +const char CODESTRAL_API_KEY_HISTORY[] = "QodeAssist.codestralApiKeyHistory"; const char GOOGLE_AI_API_KEY[] = "QodeAssist.googleAiApiKey"; const char GOOGLE_AI_API_KEY_HISTORY[] = "QodeAssist.googleAiApiKeyHistory"; const char OLLAMA_BASIC_AUTH_API_KEY[] = "QodeAssist.ollamaBasicAuthApiKey";