fix(ollama): removes required ollama api key field

This commit is contained in:
sauravniraula 2025-07-07 12:23:41 +05:45
parent 62e56b988d
commit bfa3eb8e80
No known key found for this signature in database
GPG key ID: 60FCC1B5A5E83326
5 changed files with 52 additions and 92 deletions

View file

@ -3,10 +3,7 @@ from fastapi import HTTPException
from api.models import LogMetadata
from api.routers.presentation.models import OllamaModelStatusResponse
from api.services.logging import LoggingService
from api.utils.model_utils import (
get_llm_provider_url_or,
get_ollama_request_headers,
)
from api.utils.model_utils import get_llm_provider_url_or
class ListPulledOllamaModelsHandler:
@ -19,7 +16,6 @@ class ListPulledOllamaModelsHandler:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{get_llm_provider_url_or()}/api/tags",
headers=get_ollama_request_headers(),
) as response:
if response.status == 200:
response_data = await response.json()

View file

@ -9,10 +9,7 @@ from api.routers.presentation.handlers.list_supported_ollama_models import (
from api.routers.presentation.models import OllamaModelStatusResponse
from api.services.instances import REDIS_SERVICE
from api.services.logging import LoggingService
from api.utils.model_utils import (
get_llm_provider_url_or,
get_ollama_request_headers,
)
from api.utils.model_utils import get_llm_provider_url_or
class PullOllamaModelHandler:
@ -42,7 +39,6 @@ class PullOllamaModelHandler:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{get_llm_provider_url_or()}/api/tags",
headers=get_ollama_request_headers(),
) as response:
if response.status == 200:
pulled_models = await response.json()
@ -129,7 +125,6 @@ class PullOllamaModelHandler:
async with aiohttp.ClientSession() as session:
async with session.post(
f"{get_llm_provider_url_or()}/api/pull",
headers=get_ollama_request_headers(),
json={"model": self.name},
) as response:
if response.status != 200:

View file

@ -16,14 +16,6 @@ def get_llm_provider_url_or():
return llm_provider_url
def get_ollama_request_headers():
if os.getenv("LLM_API_KEY"):
return {
"Authorization": f"Bearer {os.getenv('LLM_API_KEY')}",
}
return {}
def get_selected_llm_provider() -> SelectedLLMProvider:
return SelectedLLMProvider(os.getenv("LLM"))
@ -48,7 +40,7 @@ def get_llm_api_key():
elif selected_llm == SelectedLLMProvider.GOOGLE:
return os.getenv("GOOGLE_API_KEY")
elif selected_llm == SelectedLLMProvider.OLLAMA:
return os.getenv("LLM_API_KEY") or "ollama"
return "ollama"
else:
raise ValueError(f"Invalid LLM API key")

View file

@ -74,19 +74,15 @@ const SettingsPage = () => {
const [openModelSelect, setOpenModelSelect] = useState(false);
const [useCustomOllamaUrl, setUseCustomOllamaUrl] = useState<boolean>(userConfigState.llm_config.USE_CUSTOM_URL || false);
const api_key_changed = (apiKey: string, field?: string) => {
if (llmConfig.LLM === 'openai') {
setLlmConfig({ ...llmConfig, OPENAI_API_KEY: apiKey });
} else if (llmConfig.LLM === 'google') {
setLlmConfig({ ...llmConfig, GOOGLE_API_KEY: apiKey });
} else if (llmConfig.LLM === 'ollama') {
if (field === 'pexels') {
setLlmConfig({ ...llmConfig, PEXELS_API_KEY: apiKey });
} else if (field === 'ollama_url') {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: apiKey });
} else if (field === 'ollama_api_key') {
setLlmConfig({ ...llmConfig, LLM_API_KEY: apiKey });
}
const input_field_changed = (new_value: string, field: string) => {
if (field === 'openai_api_key') {
setLlmConfig({ ...llmConfig, OPENAI_API_KEY: new_value });
} else if (field === 'google_api_key') {
setLlmConfig({ ...llmConfig, GOOGLE_API_KEY: new_value });
} else if (field === 'llm_provider_url') {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: new_value });
} else if (field === 'pexels_api_key') {
setLlmConfig({ ...llmConfig, PEXELS_API_KEY: new_value });
}
}
@ -178,7 +174,7 @@ const SettingsPage = () => {
const setOllamaConfig = () => {
if (!useCustomOllamaUrl) {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: 'http://localhost:11434', LLM_API_KEY: undefined, USE_CUSTOM_URL: false });
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: 'http://localhost:11434', USE_CUSTOM_URL: false });
} else {
setLlmConfig({ ...llmConfig, USE_CUSTOM_URL: true });
}
@ -261,7 +257,7 @@ const SettingsPage = () => {
<input
type="text"
value={llmConfig.LLM === 'openai' ? llmConfig.OPENAI_API_KEY || '' : llmConfig.GOOGLE_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value)}
onChange={(e) => input_field_changed(e.target.value, llmConfig.LLM === 'openai' ? 'openai_api_key' : 'google_api_key')}
className="flex-1 px-4 py-2.5 border border-gray-300 outline-none rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
placeholder={PROVIDER_CONFIGS[llmConfig.LLM!].placeholder}
/>
@ -424,7 +420,7 @@ const SettingsPage = () => {
placeholder="Enter your Ollama URL"
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.LLM_PROVIDER_URL || ''}
onChange={(e) => api_key_changed(e.target.value, 'ollama_url')}
onChange={(e) => input_field_changed(e.target.value, 'llm_provider_url')}
/>
</div>
<p className="mt-2 text-sm text-gray-500 flex items-center gap-2">
@ -432,25 +428,7 @@ const SettingsPage = () => {
Change this if you are using a custom Ollama instance
</p>
</div>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Ollama API Key
</label>
<div className="relative">
<input
type="text"
required
placeholder="Enter your Ollama API key"
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.LLM_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value, 'ollama_api_key')}
/>
</div>
<p className="mt-2 text-sm text-gray-500 flex items-center gap-2">
<span className="block w-1 h-1 rounded-full bg-gray-400"></span>
Provide this if you are using a custom Ollama instance
</p>
</div>
</>
)}
</div>
@ -466,7 +444,7 @@ const SettingsPage = () => {
placeholder="Enter your Pexels API key"
className="flex-1 px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.PEXELS_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value, 'pexels')}
onChange={(e) => input_field_changed(e.target.value, 'pexels_api_key')}
/>
<button
onClick={handleSaveConfig}

View file

@ -137,6 +137,28 @@ const PROVIDER_CONFIGS: Record<string, ProviderConfig> = {
docsUrl: "https://www.pexels.com/api/documentation/",
},
},
// custom: {
// textModels: [],
// imageModels: [
// {
// value: "pexels",
// label: "Pexels",
// description: "Pexels is a free stock photo and video platform that allows you to download high-quality images and videos for free.",
// icon: "/icons/pexels.png",
// size: "8GB",
// },
// ],
// apiGuide: {
// title: "How to get your Pexels API Key",
// steps: [
// "Visit pexels.com",
// 'Click on "Get API key" in the top navigation',
// "Copy your API key - you're ready to go!",
// ],
// videoUrl: "https://www.youtube.com/watch?v=o8iyrtQyrZM&t=66s",
// docsUrl: "https://www.pexels.com/api/documentation/",
// },
// },
};
export default function Home() {
@ -163,19 +185,15 @@ export default function Home() {
const canChangeKeys = config.can_change_keys;
const api_key_changed = (newApiKey: string, field?: string) => {
if (llmConfig.LLM === 'openai') {
setLlmConfig({ ...llmConfig, OPENAI_API_KEY: newApiKey });
} else if (llmConfig.LLM === 'google') {
setLlmConfig({ ...llmConfig, GOOGLE_API_KEY: newApiKey });
} else if (llmConfig.LLM === 'ollama') {
if (field === 'pexels') {
setLlmConfig({ ...llmConfig, PEXELS_API_KEY: newApiKey });
} else if (field === 'ollama_url') {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: newApiKey });
} else if (field === 'ollama_api_key') {
setLlmConfig({ ...llmConfig, LLM_API_KEY: newApiKey });
}
const input_field_changed = (new_value: string, field: string) => {
if (field === 'openai_api_key') {
setLlmConfig({ ...llmConfig, OPENAI_API_KEY: new_value });
} else if (field === 'google_api_key') {
setLlmConfig({ ...llmConfig, GOOGLE_API_KEY: new_value });
} else if (field === 'llm_provider_url') {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: new_value });
} else if (field === 'pexels_api_key') {
setLlmConfig({ ...llmConfig, PEXELS_API_KEY: new_value });
}
}
@ -267,7 +285,7 @@ export default function Home() {
const setOllamaConfig = () => {
if (!useCustomOllamaUrl) {
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: 'http://localhost:11434', LLM_API_KEY: undefined, USE_CUSTOM_URL: false });
setLlmConfig({ ...llmConfig, LLM_PROVIDER_URL: 'http://localhost:11434', USE_CUSTOM_URL: false });
} else {
setLlmConfig({ ...llmConfig, USE_CUSTOM_URL: true });
}
@ -347,7 +365,7 @@ export default function Home() {
<input
type="text"
value={llmConfig.LLM === 'openai' ? llmConfig.OPENAI_API_KEY || '' : llmConfig.GOOGLE_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value)}
onChange={(e) => input_field_changed(e.target.value, llmConfig.LLM === 'openai' ? 'openai_api_key' : 'google_api_key')}
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
placeholder="Enter your API key"
/>
@ -490,7 +508,7 @@ export default function Home() {
placeholder="Enter your Ollama URL"
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.LLM_PROVIDER_URL || ''}
onChange={(e) => api_key_changed(e.target.value, 'ollama_url')}
onChange={(e) => input_field_changed(e.target.value, 'llm_provider_url')}
/>
</div>
<p className="mt-2 text-sm text-gray-500 flex items-center gap-2">
@ -498,25 +516,6 @@ export default function Home() {
Change this if you are using a custom Ollama instance
</p>
</div>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Ollama API Key
</label>
<div className="relative">
<input
type="text"
required
placeholder="Enter your Ollama API key"
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.LLM_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value, 'ollama_api_key')}
/>
</div>
<p className="mt-2 text-sm text-gray-500 flex items-center gap-2">
<span className="block w-1 h-1 rounded-full bg-gray-400"></span>
Provide this if you are using a custom Ollama instance
</p>
</div>
</>
)}
</div>
@ -531,7 +530,7 @@ export default function Home() {
placeholder="Enter your Pexels API key"
className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors"
value={llmConfig.PEXELS_API_KEY || ''}
onChange={(e) => api_key_changed(e.target.value, 'pexels')}
onChange={(e) => input_field_changed(e.target.value, 'pexels_api_key')}
/>
</div>
<p className="mt-2 text-sm text-gray-500 flex items-center gap-2">