diff --git a/providers/GoogleAIProvider.cpp b/providers/GoogleAIProvider.cpp index d0815ad..9c918e5 100644 --- a/providers/GoogleAIProvider.cpp +++ b/providers/GoogleAIProvider.cpp @@ -30,7 +30,6 @@ #include "logger/Logger.hpp" #include "settings/ChatAssistantSettings.hpp" #include "settings/CodeCompletionSettings.hpp" -#include "settings/GeneralSettings.hpp" #include "settings/ProviderSettings.hpp" namespace QodeAssist::Providers { diff --git a/providers/OllamaProvider.cpp b/providers/OllamaProvider.cpp index 56db3cd..24d60d1 100644 --- a/providers/OllamaProvider.cpp +++ b/providers/OllamaProvider.cpp @@ -30,6 +30,7 @@ #include "logger/Logger.hpp" #include "settings/ChatAssistantSettings.hpp" #include "settings/CodeCompletionSettings.hpp" +#include "settings/ProviderSettings.hpp" namespace QodeAssist::Providers { @@ -210,6 +211,10 @@ QString OllamaProvider::apiKey() const void OllamaProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) const { networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + const auto key = Settings::providerSettings().ollamaBasicAuthApiKey(); + if (!key.isEmpty()) { + networkRequest.setRawHeader("Authorization", "Basic " + key.toLatin1()); + } } LLMCore::ProviderID OllamaProvider::providerID() const diff --git a/settings/ProviderSettings.cpp b/settings/ProviderSettings.cpp index a0d7a7c..d7a7d3b 100644 --- a/settings/ProviderSettings.cpp +++ b/settings/ProviderSettings.cpp @@ -96,6 +96,15 @@ ProviderSettings::ProviderSettings() googleAiApiKey.setDefaultValue(""); googleAiApiKey.setAutoApply(true); + // Ollama with BasicAuth Settings + ollamaBasicAuthApiKey.setSettingsKey(Constants::OLLAMA_BASIC_AUTH_API_KEY); + ollamaBasicAuthApiKey.setLabelText(Tr::tr("Ollama BasicAuth API Key:")); + ollamaBasicAuthApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay); + ollamaBasicAuthApiKey.setPlaceHolderText(Tr::tr("Enter your API key here")); + ollamaBasicAuthApiKey.setHistoryCompleter(Constants::OLLAMA_BASIC_AUTH_API_KEY_HISTORY); + ollamaBasicAuthApiKey.setDefaultValue(""); + ollamaBasicAuthApiKey.setAutoApply(true); + resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults"); readSettings(); @@ -119,6 +128,8 @@ ProviderSettings::ProviderSettings() Group{title(Tr::tr("Mistral AI Settings")), Column{mistralAiApiKey}}, Space{8}, Group{title(Tr::tr("Google AI Settings")), Column{googleAiApiKey}}, + Space{8}, + Group{title(Tr::tr("Ollama Settings")), Column{ollamaBasicAuthApiKey}}, Stretch{1}}; }); } @@ -141,6 +152,9 @@ void ProviderSettings::setupConnections() connect(&googleAiApiKey, &ButtonAspect::changed, this, [this]() { googleAiApiKey.writeSettings(); }); + connect(&ollamaBasicAuthApiKey, &ButtonAspect::changed, this, [this]() { + ollamaBasicAuthApiKey.writeSettings(); + }); } void ProviderSettings::resetSettingsToDefaults() @@ -159,6 +173,7 @@ void ProviderSettings::resetSettingsToDefaults() resetAspect(openAiApiKey); resetAspect(mistralAiApiKey); resetAspect(googleAiApiKey); + resetAspect(ollamaBasicAuthApiKey); } } diff --git a/settings/ProviderSettings.hpp b/settings/ProviderSettings.hpp index 9e84b89..e9b407b 100644 --- a/settings/ProviderSettings.hpp +++ b/settings/ProviderSettings.hpp @@ -39,6 +39,7 @@ public: Utils::StringAspect openAiApiKey{this}; Utils::StringAspect mistralAiApiKey{this}; Utils::StringAspect googleAiApiKey{this}; + Utils::StringAspect ollamaBasicAuthApiKey{this}; private: void setupConnections(); diff --git a/settings/SettingsConstants.hpp b/settings/SettingsConstants.hpp index cdf33a0..f766bb6 100644 --- a/settings/SettingsConstants.hpp +++ b/settings/SettingsConstants.hpp @@ -100,6 +100,8 @@ const char MISTRAL_AI_API_KEY[] = "QodeAssist.mistralAiApiKey"; const char MISTRAL_AI_API_KEY_HISTORY[] = "QodeAssist.mistralAiApiKeyHistory"; 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"; +const char OLLAMA_BASIC_AUTH_API_KEY_HISTORY[] = "QodeAssist.ollamaBasicAuthApiKeyHistory"; // context settings const char CC_READ_FULL_FILE[] = "QodeAssist.ccReadFullFile";