]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix openai api key, config settings saving
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 26 Apr 2025 04:34:14 +0000 (21:34 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 2 Jul 2025 18:03:55 +0000 (11:03 -0700)
src-ui/src/app/data/paperless-config.ts
src/paperless/ai/client.py
src/paperless/serialisers.py
src/paperless/tests/test_ai_client.py

index 58030e0af5f4ee287469ac7a2004299c18e6aee9..f41776e78e28161b933895718a6d84116ef28d3a 100644 (file)
@@ -56,7 +56,7 @@ export const ConfigCategory = {
 
 export const LLMEmbeddingBackendConfig = {
   OPENAI: 'openai',
-  LOCAL: 'local',
+  HUGGINGFACE: 'huggingface',
 }
 
 export const LLMBackendConfig = {
index d89e1348c92a5e0e75ff04692770943ca6eceaac..0fdc03d17b7c935723d189d37d86ac058783e5a4 100644 (file)
@@ -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}")
index 716b72a8ae87ff8bad4c9b726210d005fbb7d7f8..31910fc827b3f89684f5cc9708dd6f5941f89761 100644 (file)
@@ -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):
index 3992bec42dc3dfc7d6d08accb0e09b69fb10f6a9..a64fcfd710b0b0c43cc4bd3e66dcca2a69170122 100644 (file)
@@ -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()