Skip to content

Commit 4ddbe0b

Browse files
authored
feat: Support Ollama authorization via BaseAuth (Palm1r#145) (Palm1r#146)
1 parent f41e063 commit 4ddbe0b

5 files changed

+23
-1
lines changed

providers/GoogleAIProvider.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "logger/Logger.hpp"
3131
#include "settings/ChatAssistantSettings.hpp"
3232
#include "settings/CodeCompletionSettings.hpp"
33-
#include "settings/GeneralSettings.hpp"
3433
#include "settings/ProviderSettings.hpp"
3534

3635
namespace QodeAssist::Providers {

providers/OllamaProvider.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "logger/Logger.hpp"
3131
#include "settings/ChatAssistantSettings.hpp"
3232
#include "settings/CodeCompletionSettings.hpp"
33+
#include "settings/ProviderSettings.hpp"
3334

3435
namespace QodeAssist::Providers {
3536

@@ -210,6 +211,10 @@ QString OllamaProvider::apiKey() const
210211
void OllamaProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) const
211212
{
212213
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
214+
const auto key = Settings::providerSettings().ollamaBasicAuthApiKey();
215+
if (!key.isEmpty()) {
216+
networkRequest.setRawHeader("Authorization", "Basic " + key.toLatin1());
217+
}
213218
}
214219

215220
LLMCore::ProviderID OllamaProvider::providerID() const

settings/ProviderSettings.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ ProviderSettings::ProviderSettings()
9696
googleAiApiKey.setDefaultValue("");
9797
googleAiApiKey.setAutoApply(true);
9898

99+
// Ollama with BasicAuth Settings
100+
ollamaBasicAuthApiKey.setSettingsKey(Constants::OLLAMA_BASIC_AUTH_API_KEY);
101+
ollamaBasicAuthApiKey.setLabelText(Tr::tr("Ollama BasicAuth API Key:"));
102+
ollamaBasicAuthApiKey.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
103+
ollamaBasicAuthApiKey.setPlaceHolderText(Tr::tr("Enter your API key here"));
104+
ollamaBasicAuthApiKey.setHistoryCompleter(Constants::OLLAMA_BASIC_AUTH_API_KEY_HISTORY);
105+
ollamaBasicAuthApiKey.setDefaultValue("");
106+
ollamaBasicAuthApiKey.setAutoApply(true);
107+
99108
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
100109

101110
readSettings();
@@ -119,6 +128,8 @@ ProviderSettings::ProviderSettings()
119128
Group{title(Tr::tr("Mistral AI Settings")), Column{mistralAiApiKey}},
120129
Space{8},
121130
Group{title(Tr::tr("Google AI Settings")), Column{googleAiApiKey}},
131+
Space{8},
132+
Group{title(Tr::tr("Ollama Settings")), Column{ollamaBasicAuthApiKey}},
122133
Stretch{1}};
123134
});
124135
}
@@ -141,6 +152,9 @@ void ProviderSettings::setupConnections()
141152
connect(&googleAiApiKey, &ButtonAspect::changed, this, [this]() {
142153
googleAiApiKey.writeSettings();
143154
});
155+
connect(&ollamaBasicAuthApiKey, &ButtonAspect::changed, this, [this]() {
156+
ollamaBasicAuthApiKey.writeSettings();
157+
});
144158
}
145159

146160
void ProviderSettings::resetSettingsToDefaults()
@@ -159,6 +173,7 @@ void ProviderSettings::resetSettingsToDefaults()
159173
resetAspect(openAiApiKey);
160174
resetAspect(mistralAiApiKey);
161175
resetAspect(googleAiApiKey);
176+
resetAspect(ollamaBasicAuthApiKey);
162177
}
163178
}
164179

settings/ProviderSettings.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ProviderSettings : public Utils::AspectContainer
3939
Utils::StringAspect openAiApiKey{this};
4040
Utils::StringAspect mistralAiApiKey{this};
4141
Utils::StringAspect googleAiApiKey{this};
42+
Utils::StringAspect ollamaBasicAuthApiKey{this};
4243

4344
private:
4445
void setupConnections();

settings/SettingsConstants.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ const char MISTRAL_AI_API_KEY[] = "QodeAssist.mistralAiApiKey";
100100
const char MISTRAL_AI_API_KEY_HISTORY[] = "QodeAssist.mistralAiApiKeyHistory";
101101
const char GOOGLE_AI_API_KEY[] = "QodeAssist.googleAiApiKey";
102102
const char GOOGLE_AI_API_KEY_HISTORY[] = "QodeAssist.googleAiApiKeyHistory";
103+
const char OLLAMA_BASIC_AUTH_API_KEY[] = "QodeAssist.ollamaBasicAuthApiKey";
104+
const char OLLAMA_BASIC_AUTH_API_KEY_HISTORY[] = "QodeAssist.ollamaBasicAuthApiKeyHistory";
103105

104106
// context settings
105107
const char CC_READ_FULL_FILE[] = "QodeAssist.ccReadFullFile";

0 commit comments

Comments
 (0)