From 7ab15cda963c1dc5de32aa0ae5fe00cce1b8f495 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 25 Apr 2025 21:34:14 -0700 Subject: [PATCH] Fix openai api key, config settings saving --- src-ui/src/app/data/paperless-config.ts | 2 +- src/paperless/ai/client.py | 2 +- src/paperless/serialisers.py | 5 +++++ src/paperless/tests/test_ai_client.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/data/paperless-config.ts b/src-ui/src/app/data/paperless-config.ts index 58030e0af..f41776e78 100644 --- a/src-ui/src/app/data/paperless-config.ts +++ b/src-ui/src/app/data/paperless-config.ts @@ -56,7 +56,7 @@ export const ConfigCategory = { export const LLMEmbeddingBackendConfig = { OPENAI: 'openai', - LOCAL: 'local', + HUGGINGFACE: 'huggingface', } export const LLMBackendConfig = { diff --git a/src/paperless/ai/client.py b/src/paperless/ai/client.py index d89e1348c..0fdc03d17 100644 --- a/src/paperless/ai/client.py +++ b/src/paperless/ai/client.py @@ -28,7 +28,7 @@ class AIClient: elif self.settings.llm_backend == "openai": return OpenAI( model=self.settings.llm_model or "gpt-3.5-turbo", - api_key=self.settings.openai_api_key, + api_key=self.settings.llm_api_key, ) else: raise ValueError(f"Unsupported LLM backend: {self.settings.llm_backend}") diff --git a/src/paperless/serialisers.py b/src/paperless/serialisers.py index 716b72a8a..31910fc82 100644 --- a/src/paperless/serialisers.py +++ b/src/paperless/serialisers.py @@ -203,6 +203,11 @@ class ApplicationConfigurationSerializer(serializers.ModelSerializer): data["barcode_tag_mapping"] = None if "language" in data and data["language"] == "": data["language"] = None + if "llm_api_key" in data and data["llm_api_key"] is not None: + if data["llm_api_key"] == "": + data["llm_api_key"] = None + elif len(data["llm_api_key"].replace("*", "")) == 0: + del data["llm_api_key"] return super().run_validation(data) def update(self, instance, validated_data): diff --git a/src/paperless/tests/test_ai_client.py b/src/paperless/tests/test_ai_client.py index 3992bec42..a64fcfd71 100644 --- a/src/paperless/tests/test_ai_client.py +++ b/src/paperless/tests/test_ai_client.py @@ -45,7 +45,7 @@ def test_get_llm_ollama(mock_ai_config, mock_ollama_llm): def test_get_llm_openai(mock_ai_config, mock_openai_llm): mock_ai_config.llm_backend = "openai" mock_ai_config.llm_model = "test_model" - mock_ai_config.openai_api_key = "test_api_key" + mock_ai_config.llm_api_key = "test_api_key" client = AIClient()