Skip to content

Commit fd83957

Browse files
doraemonlovewangjiaju
andauthored
feat(tools): add link_reader tool (#277)
Co-authored-by: wangjiaju <[email protected]>
1 parent b4b0a37 commit fd83957

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from volcenginesdkarkruntime._models import BaseModel
16+
from volcenginesdkarkruntime import AsyncArk
17+
from veadk.utils.logger import get_logger
18+
from httpx import Timeout
19+
from veadk.config import getenv, settings
20+
21+
logger = get_logger(__name__)
22+
23+
24+
async def link_reader(url_list: list[str]) -> dict:
25+
"""
26+
Use this tool when you need to fetch content from web pages, PDFs, or Douyin videos.
27+
It retrieves the title and main content from the provided URLs.
28+
29+
Examples: {"url_list": ["abc.com", "xyz.com"]}
30+
Args:
31+
url_list (list[str]): A list of URLs to parse (maximum 3).
32+
Returns:
33+
list[dict]: A list of dictionaries, each containing the title and content of the corresponding URL.
34+
"""
35+
logger.debug(f"link_reader url_list: {url_list}")
36+
try:
37+
client = AsyncArk(
38+
api_key=getenv("MODEL_AGENT_API_KEY", settings.model.api_key),
39+
timeout=Timeout(connect=1.0, timeout=60.0),
40+
)
41+
except Exception as e:
42+
logger.error(f"link_reader client init failed:{e}")
43+
return []
44+
45+
body = {
46+
"action_name": "LinkReader",
47+
"tool_name": "LinkReader",
48+
"parameters": {"url_list": url_list},
49+
}
50+
51+
response = None
52+
try:
53+
response = await client.post(
54+
path="/tools/execute", body=body, cast_to=BaseModel
55+
)
56+
response = response.model_dump()
57+
logger.debug(f"link_reader response: {response}")
58+
59+
if response["status_code"] != 200:
60+
logger.error(f"link_reader failed: {response}")
61+
return []
62+
else:
63+
return response["data"]["ark_web_data_list"]
64+
except Exception as e:
65+
logger.error(f"link_reader failed: {e}, response: {response}")
66+
return []

0 commit comments

Comments
 (0)