feat: add request_params field to jina_reader tool (#5610)

This commit is contained in:
Xiao Ley 2024-07-08 18:11:50 +08:00 committed by GitHub
parent cbbe28f40d
commit 6610b4cee5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import json
from typing import Any, Union
from yarl import URL
@ -26,6 +27,15 @@ class JinaReaderTool(BuiltinTool):
if 'api_key' in self.runtime.credentials and self.runtime.credentials.get('api_key'):
headers['Authorization'] = "Bearer " + self.runtime.credentials.get('api_key')
request_params = tool_parameters.get('request_params')
if request_params is not None and request_params != '':
try:
request_params = json.loads(request_params)
if not isinstance(request_params, dict):
raise ValueError("request_params must be a JSON object")
except (json.JSONDecodeError, ValueError) as e:
raise ValueError(f"Invalid request_params: {e}")
target_selector = tool_parameters.get('target_selector')
if target_selector is not None and target_selector != '':
headers['X-Target-Selector'] = target_selector
@ -53,7 +63,8 @@ class JinaReaderTool(BuiltinTool):
response = ssrf_proxy.get(
str(URL(self._jina_reader_endpoint + url)),
headers=headers,
timeout=(10, 60)
params=request_params,
timeout=(10, 60),
)
if tool_parameters.get('summary', False):

View File

@ -25,6 +25,22 @@ parameters:
pt_BR: used for linking to webpages
llm_description: url for scraping
form: llm
- name: request_params
type: string
required: false
label:
en_US: Request params
zh_Hans: 请求参数
pt_BR: Request params
human_description:
en_US: |
request parameters, format: {"key1": "value1", "key2": "value2"}
zh_Hans: |
请求参数,格式:{"key1": "value1", "key2": "value2"}
pt_BR: |
request parameters, format: {"key1": "value1", "key2": "value2"}
llm_description: request parameters
form: llm
- name: target_selector
type: string
required: false