From 98273d67fecba129a6a234551cbbf27d7a3abdbb Mon Sep 17 00:00:00 2001 From: hzlq <1018053166@qq.com> Date: Wed, 17 Sep 2025 14:47:03 +0800 Subject: [PATCH 1/6] fix(openai_rerank): Handle empty API keys consistently with authorization header --- .../interfaces/model/openai_compatible/rerank.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index 6d116027..8a16f767 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -55,9 +55,13 @@ def _invoke( url = server_url headers = { - "Authorization": f"Bearer {credentials.get('api_key')}", "Content-Type": "application/json", } + + # 只有当api_key不为空时才添加Authorization头 + api_key = credentials.get('api_key') + if api_key: + headers["Authorization"] = f"Bearer {api_key}" # TODO: Do we need truncate docs to avoid llama.cpp return error? From 73edcb0b3ec64c64905f9955bd3c39bd6320a83a Mon Sep 17 00:00:00 2001 From: hzlq <1018053166@qq.com> Date: Thu, 18 Sep 2025 13:50:00 +0800 Subject: [PATCH 2/6] docs: translate comments to English in rerank.py --- python/dify_plugin/interfaces/model/openai_compatible/rerank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index 8a16f767..f35fd5a5 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -58,7 +58,7 @@ def _invoke( "Content-Type": "application/json", } - # 只有当api_key不为空时才添加Authorization头 + # Only add Authorization header when api_key is not empty api_key = credentials.get('api_key') if api_key: headers["Authorization"] = f"Bearer {api_key}" From 1e71b45b07ed1deb3fc7ff9ffae68367c12079f7 Mon Sep 17 00:00:00 2001 From: xiao8 <1018053166@qq.com> Date: Fri, 19 Sep 2025 09:54:09 +0800 Subject: [PATCH 3/6] Remove whitespace from blank line Remove whitespace from blank line --- .../dify_plugin/interfaces/model/openai_compatible/rerank.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index f35fd5a5..a23f4133 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -56,8 +56,7 @@ def _invoke( url = server_url headers = { "Content-Type": "application/json", - } - + } # Only add Authorization header when api_key is not empty api_key = credentials.get('api_key') if api_key: From 283678b7808158d874e1bb2e0d972a79864c2225 Mon Sep 17 00:00:00 2001 From: hzlq <1018053166@qq.com> Date: Tue, 23 Sep 2025 09:49:16 +0800 Subject: [PATCH 4/6] Remove whitespace from blank line --- python/dify_plugin/interfaces/model/openai_compatible/rerank.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index f35fd5a5..fa29b914 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -57,7 +57,6 @@ def _invoke( headers = { "Content-Type": "application/json", } - # Only add Authorization header when api_key is not empty api_key = credentials.get('api_key') if api_key: From 5d65d4a80c4f8c3bc399619bbd4ae86e3449e6cd Mon Sep 17 00:00:00 2001 From: hzlq <1018053166@qq.com> Date: Tue, 23 Sep 2025 09:51:54 +0800 Subject: [PATCH 5/6] Fix merge conflicts and remove trailing whitespace in rerank.py --- .../interfaces/model/openai_compatible/rerank.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index 148367bf..a9061c72 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -54,15 +54,9 @@ def _invoke( raise CredentialsValidateFailedError("model_name is required") url = server_url - } ->>>>>>> 1e71b45b07ed1deb3fc7ff9ffae68367c12079f7 -======= headers = { "Content-Type": "application/json", } -======= - } ->>>>>>> 1e71b45b07ed1deb3fc7ff9ffae68367c12079f7 # Only add Authorization header when api_key is not empty api_key = credentials.get('api_key') if api_key: @@ -168,4 +162,4 @@ def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]] """ Map model invoke error to unified error """ - return {} + return {} \ No newline at end of file From eb3ac2cae885d05e1c1d5c908f71cc69dd12c72b Mon Sep 17 00:00:00 2001 From: hzlq <1018053166@qq.com> Date: Sun, 28 Sep 2025 18:01:32 +0800 Subject: [PATCH 6/6] style: standardize quote style and ensure newline at end of file in rerank.py --- .../dify_plugin/interfaces/model/openai_compatible/rerank.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py index a9061c72..81cef672 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/rerank.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/rerank.py @@ -58,7 +58,7 @@ def _invoke( "Content-Type": "application/json", } # Only add Authorization header when api_key is not empty - api_key = credentials.get('api_key') + api_key = credentials.get("api_key") if api_key: headers["Authorization"] = f"Bearer {api_key}" @@ -162,4 +162,4 @@ def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]] """ Map model invoke error to unified error """ - return {} \ No newline at end of file + return {}