Skip to content

Commit b173281

Browse files
author
wangjiaju
committed
Add link_reader tool
1 parent b4b0a37 commit b173281

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
import asyncio
19+
from httpx import Timeout
20+
from veadk.config import getenv
21+
22+
logger = get_logger(__name__)
23+
24+
25+
async def link_reader(url_list: list[str]) -> dict:
26+
"""
27+
当你需要获取网页、pdf、抖音视频内容时,使用此工具。可以获取url链接下的标题和内容。
28+
29+
30+
examples: {"url_list":["abc.com", "xyz.com"]}
31+
Args:
32+
url_list (list[str]): 需要解析网页链接,最多3个
33+
Returns:
34+
list[dict]: 每个url链接下的标题和内容
35+
"""
36+
logger.debug(f"link_reader url_list: {url_list}")
37+
try:
38+
client = AsyncArk(
39+
api_key=getenv("ARK_API_KEY"), 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+
try:
52+
response = await client.post(
53+
path="/tools/execute", body=body, cast_to=BaseModel
54+
)
55+
response = response.model_dump()
56+
logger.debug(f"link_reader response: {response}")
57+
58+
if response["status_code"] != 200:
59+
logger.error(f"link_reader failed: {response}")
60+
return []
61+
else:
62+
return response["data"]["ark_web_data_list"]
63+
except Exception as e:
64+
logger.error(f"link_reader failed: {e}")
65+
return []
66+
67+
68+
if __name__ == "__main__":
69+
result = asyncio.run(
70+
link_reader(
71+
["https://www.baidu.com", "https://www.baidu.com", "https://www.baidu.com"]
72+
)
73+
)
74+
print(len(result), result)

0 commit comments

Comments
 (0)