Skip to content

Commit

Permalink
feat: add request_params field to jina_reader tool (langgenius#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoLey authored Jul 8, 2024
1 parent cbbe28f commit 6610b4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/core/tools/provider/builtin/jina/tools/jina_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Union

from yarl import URL
Expand Down Expand Up @@ -26,6 +27,15 @@ def _invoke(self,
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
Expand Down Expand Up @@ -53,7 +63,8 @@ def _invoke(self,
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):
Expand Down
16 changes: 16 additions & 0 deletions api/core/tools/provider/builtin/jina/tools/jina_reader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6610b4c

Please sign in to comment.