Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: Add Optional API Key, Proxy Server, and Bypass Cache Parameters to Jina Tools (#5197)

Jaxon Ley337bad852518
diff --git a/api/core/tools/provider/builtin/jina/jina.py b/api/core/tools/provider/builtin/jina/jina.py
index b1a8d621380..12e5058cdc9 100644
--- a/api/core/tools/provider/builtin/jina/jina.py
+++ b/api/core/tools/provider/builtin/jina/jina.py
@@ -1,14 +1,32 @@
+import json
from typing import Any
from core.tools.entities.values import ToolLabelEnum
from core.tools.errors import ToolProviderCredentialValidationError
+from core.tools.provider.builtin.jina.tools.jina_reader import JinaReaderTool
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
class GoogleProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
- pass
+ if credentials['api_key'] is None:
+ credentials['api_key'] = ''
+ else:
+ result = JinaReaderTool().fork_tool_runtime(
+ runtime={
+ "credentials": credentials,
+ }
+ ).invoke(
+ user_id='',
+ tool_parameters={
+ "url": "https://example.com",
+ },
+ )[0]
+
+ message = json.loads(result.message)
+ if message['code'] != 200:
+ raise ToolProviderCredentialValidationError(message['message'])
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))
diff --git a/api/core/tools/provider/builtin/jina/jina.yaml b/api/core/tools/provider/builtin/jina/jina.yaml
index 67ad32a47a1..06f23382d92 100644
--- a/api/core/tools/provider/builtin/jina/jina.yaml
+++ b/api/core/tools/provider/builtin/jina/jina.yaml
@@ -14,3 +14,19 @@ identity:
- search
- productivity
credentials_for_provider:
+ api_key:
+ type: secret-input
+ required: false
+ label:
+ en_US: API Key (leave empty if you don't have one)
+ zh_Hans: API 密钥(可留空)
+ pt_BR: Chave API (deixe vazio se você não tiver uma)
+ placeholder:
+ en_US: Please enter your Jina API key
+ zh_Hans: 请输入你的 Jina API 密钥
+ pt_BR: Por favor, insira sua chave de API do Jina
+ help:
+ en_US: Get your Jina API key from Jina (optional, but you can get a higher rate)
+ zh_Hans: 从 Jina 获取您的 Jina API 密钥(非必须,能得到更高的速率)
+ pt_BR: Obtenha sua chave de API do Jina na Jina (opcional, mas você pode obter uma taxa mais alta)
+ url: https://jina.ai
diff --git a/api/core/tools/provider/builtin/jina/tools/jina_reader.py b/api/core/tools/provider/builtin/jina/tools/jina_reader.py
index beb05717ea1..b0bd4788466 100644
--- a/api/core/tools/provider/builtin/jina/tools/jina_reader.py
+++ b/api/core/tools/provider/builtin/jina/tools/jina_reader.py
@@ -23,14 +23,24 @@ class JinaReaderTool(BuiltinTool):
'Accept': 'application/json'
}
+ if 'api_key' in self.runtime.credentials and self.runtime.credentials.get('api_key'):
+ headers['Authorization'] = "Bearer " + self.runtime.credentials.get('api_key')
+
target_selector = tool_parameters.get('target_selector', None)
- if target_selector is not None:
+ if target_selector is not None and target_selector != '':
headers['X-Target-Selector'] = target_selector
wait_for_selector = tool_parameters.get('wait_for_selector', None)
- if wait_for_selector is not None:
+ if wait_for_selector is not None and wait_for_selector != '':
headers['X-Wait-For-Selector'] = wait_for_selector
+ proxy_server = tool_parameters.get('proxy_server', None)
+ if proxy_server is not None and proxy_server != '':
+ headers['X-Proxy-Url'] = proxy_server
+
+ if tool_parameters.get('no_cache', False):
+ headers['X-No-Cache'] = 'true'
+
response = ssrf_proxy.get(
str(URL(self._jina_reader_endpoint + url)),
headers=headers,
diff --git a/api/core/tools/provider/builtin/jina/tools/jina_reader.yaml b/api/core/tools/provider/builtin/jina/tools/jina_reader.yaml
index 73cacb7fde1..703fa3d389a 100644
--- a/api/core/tools/provider/builtin/jina/tools/jina_reader.yaml
+++ b/api/core/tools/provider/builtin/jina/tools/jina_reader.yaml
@@ -51,6 +51,33 @@ parameters:
pt_BR: css selector for waiting for specific elements
llm_description: css selector of the target element to wait for
form: form
+ - name: proxy_server
+ type: string
+ required: false
+ label:
+ en_US: Proxy server
+ zh_Hans: 代理服务器
+ pt_BR: Servidor de proxy
+ human_description:
+ en_US: Use proxy to access URLs
+ zh_Hans: 利用代理访问 URL
+ pt_BR: Use proxy to access URLs
+ llm_description: Use proxy to access URLs
+ form: form
+ - name: no_cache
+ type: boolean
+ required: false
+ default: false
+ label:
+ en_US: Bypass the Cache
+ zh_Hans: 绕过缓存
+ pt_BR: Ignorar o cache
+ human_description:
+ en_US: Bypass the Cache
+ zh_Hans: 是否绕过缓存
+ pt_BR: Ignorar o cache
+ llm_description: bypass the cache
+ form: form
- name: summary
type: boolean
required: false
diff --git a/api/core/tools/provider/builtin/jina/tools/jina_search.py b/api/core/tools/provider/builtin/jina/tools/jina_search.py
index cfe36e6a3ce..c13f58d0cd1 100644
--- a/api/core/tools/provider/builtin/jina/tools/jina_search.py
+++ b/api/core/tools/provider/builtin/jina/tools/jina_search.py
@@ -21,6 +21,16 @@ class JinaSearchTool(BuiltinTool):
'Accept': 'application/json'
}
+ if 'api_key' in self.runtime.credentials and self.runtime.credentials.get('api_key'):
+ headers['Authorization'] = "Bearer " + self.runtime.credentials.get('api_key')
+
+ proxy_server = tool_parameters.get('proxy_server', None)
+ if proxy_server is not None and proxy_server != '':
+ headers['X-Proxy-Url'] = proxy_server
+
+ if tool_parameters.get('no_cache', False):
+ headers['X-No-Cache'] = 'true'
+
response = ssrf_proxy.get(
str(URL(self._jina_search_endpoint + query)),
headers=headers,
diff --git a/api/core/tools/provider/builtin/jina/tools/jina_search.yaml b/api/core/tools/provider/builtin/jina/tools/jina_search.yaml
index 5ad70c03f3b..f3b6c0737a9 100644
--- a/api/core/tools/provider/builtin/jina/tools/jina_search.yaml
+++ b/api/core/tools/provider/builtin/jina/tools/jina_search.yaml
@@ -8,6 +8,7 @@ identity:
description:
human:
en_US: Search on the web and get the top 5 results. Useful for grounding using information from the web.
+ zh_Hans: 在网络上搜索返回前 5 个结果。
llm: A tool for searching results on the web for grounding. Input should be a simple question.
parameters:
- name: query
@@ -15,7 +16,36 @@ parameters:
required: true
label:
en_US: Question (Query)
+ zh_Hans: 信息查询
human_description:
en_US: used to find information on the web
+ zh_Hans: 在网络上搜索信息
llm_description: simple question to ask on the web
form: llm
+ - name: proxy_server
+ type: string
+ required: false
+ label:
+ en_US: Proxy server
+ zh_Hans: 代理服务器
+ pt_BR: Servidor de proxy
+ human_description:
+ en_US: Use proxy to access URLs
+ zh_Hans: 利用代理访问 URL
+ pt_BR: Use proxy to access URLs
+ llm_description: Use proxy to access URLs
+ form: form
+ - name: no_cache
+ type: boolean
+ required: false
+ default: false
+ label:
+ en_US: Bypass the Cache
+ zh_Hans: 绕过缓存
+ pt_BR: Ignorar o cache
+ human_description:
+ en_US: Bypass the Cache
+ zh_Hans: 是否绕过缓存
+ pt_BR: Ignorar o cache
+ llm_description: bypass the cache
+ form: form