diff --git a/servers/fastapi/api/routers/presentation/handlers/list_ollama_pulled_models.py b/servers/fastapi/api/routers/presentation/handlers/list_ollama_pulled_models.py index 29177aed..56820ff0 100644 --- a/servers/fastapi/api/routers/presentation/handlers/list_ollama_pulled_models.py +++ b/servers/fastapi/api/routers/presentation/handlers/list_ollama_pulled_models.py @@ -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() diff --git a/servers/fastapi/api/routers/presentation/handlers/pull_ollama_model.py b/servers/fastapi/api/routers/presentation/handlers/pull_ollama_model.py index 29dc6394..87178bc2 100644 --- a/servers/fastapi/api/routers/presentation/handlers/pull_ollama_model.py +++ b/servers/fastapi/api/routers/presentation/handlers/pull_ollama_model.py @@ -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: diff --git a/servers/fastapi/api/utils/model_utils.py b/servers/fastapi/api/utils/model_utils.py index 2e4b3b7d..e26dc4d2 100644 --- a/servers/fastapi/api/utils/model_utils.py +++ b/servers/fastapi/api/utils/model_utils.py @@ -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") diff --git a/servers/nextjs/app/settings/SettingPage.tsx b/servers/nextjs/app/settings/SettingPage.tsx index d7a54425..512c929e 100644 --- a/servers/nextjs/app/settings/SettingPage.tsx +++ b/servers/nextjs/app/settings/SettingPage.tsx @@ -74,19 +74,15 @@ const SettingsPage = () => { const [openModelSelect, setOpenModelSelect] = useState(false); const [useCustomOllamaUrl, setUseCustomOllamaUrl] = useState(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 = () => { 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')} />

@@ -432,25 +428,7 @@ const SettingsPage = () => { Change this if you are using a custom Ollama instance

-
- -
- api_key_changed(e.target.value, 'ollama_api_key')} - /> -
-

- - Provide this if you are using a custom Ollama instance -

-
+ )} @@ -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')} />