langchain-dataxapi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_dataxapi/__init__.py +55 -0
- langchain_dataxapi/_client.py +226 -0
- langchain_dataxapi/endpoint_tools.py +495 -0
- langchain_dataxapi/py.typed +0 -0
- langchain_dataxapi/toolkits.py +55 -0
- langchain_dataxapi/tools.py +258 -0
- langchain_dataxapi-0.1.0.dist-info/METADATA +232 -0
- langchain_dataxapi-0.1.0.dist-info/RECORD +10 -0
- langchain_dataxapi-0.1.0.dist-info/WHEEL +4 -0
- langchain_dataxapi-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"""One LangChain tool per DataXAPI endpoint most used by DataXAPI's customers.
|
|
2
|
+
|
|
3
|
+
Written by scripts/generate_tools.py from catalog 720fc3ea8dadb865, price book 19. Do not edit by hand:
|
|
4
|
+
run the script again.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, ClassVar, Literal
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel, Field
|
|
12
|
+
|
|
13
|
+
from langchain_dataxapi.tools import DataXAPIEndpointTool
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DataXAPIXiaohongshuNoteSearchInput(BaseModel):
|
|
17
|
+
"""Arguments of dataxapi_xiaohongshu_notes_search."""
|
|
18
|
+
|
|
19
|
+
query: str = Field(description='Search terms. Example: "咖啡".')
|
|
20
|
+
sort: Literal["relevance", "latest", "popular", "most_comments", "most_favorites"] | None = Field(
|
|
21
|
+
default=None,
|
|
22
|
+
description="Sort order: relevance, newest, most liked, most commented, most saved. Default: relevance.",
|
|
23
|
+
)
|
|
24
|
+
type: Literal["video", "image"] | None = Field(
|
|
25
|
+
default=None, description="Video notes only (video) or image notes only (image); both when left out."
|
|
26
|
+
)
|
|
27
|
+
published_within: Literal["day", "week", "half_year"] | None = Field(
|
|
28
|
+
default=None, description="Only those published in the last day, week or half year."
|
|
29
|
+
)
|
|
30
|
+
cursor: str | None = Field(
|
|
31
|
+
default=None,
|
|
32
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class DataXAPIXiaohongshuNoteSearch(DataXAPIEndpointTool):
|
|
37
|
+
"""Xiaohongshu note search (xiaohongshu.notes.search).
|
|
38
|
+
|
|
39
|
+
Price: $0.02 per call; errors are not charged.
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
.. code-block:: python
|
|
43
|
+
|
|
44
|
+
from langchain_dataxapi import DataXAPIXiaohongshuNoteSearch
|
|
45
|
+
|
|
46
|
+
tool = DataXAPIXiaohongshuNoteSearch()
|
|
47
|
+
tool.invoke({"query": "咖啡"})
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
name: str = "dataxapi_xiaohongshu_notes_search"
|
|
51
|
+
description: str = "Search Xiaohongshu notes by terms: title, text, author, engagement counts, images, and a link that opens. Each says whether it is a brand partnership note on record. By relevance, newest, most liked, most commented or most saved; video or image notes only; published in the last day, week or half year. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
52
|
+
args_schema: type[BaseModel] = DataXAPIXiaohongshuNoteSearchInput
|
|
53
|
+
endpoint: ClassVar[str] = "xiaohongshu.notes.search"
|
|
54
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
55
|
+
example: ClassVar[dict[str, Any]] = {"query": "咖啡"}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class DataXAPIDouyinVideoSearchInput(BaseModel):
|
|
59
|
+
"""Arguments of dataxapi_douyin_videos_search."""
|
|
60
|
+
|
|
61
|
+
query: str = Field(description='Search terms. Example: "露营".')
|
|
62
|
+
sort: Literal["relevance", "latest", "popular"] | None = Field(
|
|
63
|
+
default=None,
|
|
64
|
+
description="Order: the platform's ranking, newest first, most liked first. Douyin does not serve most liked within a day; with that pair, a day's results come with each page in order of likes. Default: relevance.",
|
|
65
|
+
)
|
|
66
|
+
published_within: Literal["day", "week", "half_year"] | None = Field(
|
|
67
|
+
default=None, description="Only videos posted within the last day, week or half year; any time when left out."
|
|
68
|
+
)
|
|
69
|
+
cursor: str | None = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class DataXAPIDouyinVideoSearch(DataXAPIEndpointTool):
|
|
76
|
+
"""Douyin video search (douyin.videos.search).
|
|
77
|
+
|
|
78
|
+
Price: $0.02 per call; errors are not charged.
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
.. code-block:: python
|
|
82
|
+
|
|
83
|
+
from langchain_dataxapi import DataXAPIDouyinVideoSearch
|
|
84
|
+
|
|
85
|
+
tool = DataXAPIDouyinVideoSearch()
|
|
86
|
+
tool.invoke({"query": "露营"})
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
name: str = "dataxapi_douyin_videos_search"
|
|
90
|
+
description: str = "Search Douyin videos by terms, a page at a time, sorted by relevance, newest or most liked and filtered by time posted: caption, author with follower count, engagement counts. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
91
|
+
args_schema: type[BaseModel] = DataXAPIDouyinVideoSearchInput
|
|
92
|
+
endpoint: ClassVar[str] = "douyin.videos.search"
|
|
93
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
94
|
+
example: ClassVar[dict[str, Any]] = {"query": "露营"}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class DataXAPIWeChatOfficialAccountArticlesInput(BaseModel):
|
|
98
|
+
"""Arguments of dataxapi_wechat_mp_accounts_articles_list."""
|
|
99
|
+
|
|
100
|
+
id: str = Field(
|
|
101
|
+
description="The account's original ID, mostly starting with gh_ but not always, not the account's name; knowing only the name, find it with wechat.accounts.search and take id. Example: \"gh_13c97ab93ce8\"."
|
|
102
|
+
)
|
|
103
|
+
tab: Literal["articles", "videos", "images"] | None = Field(
|
|
104
|
+
default=None,
|
|
105
|
+
description="Which tab of the account's page: articles (the default), videos or pictures. Default: articles.",
|
|
106
|
+
)
|
|
107
|
+
cursor: str | None = Field(
|
|
108
|
+
default=None,
|
|
109
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class DataXAPIWeChatOfficialAccountArticles(DataXAPIEndpointTool):
|
|
114
|
+
"""WeChat Official Account articles (wechat_mp.accounts.articles.list).
|
|
115
|
+
|
|
116
|
+
Price: $0.02 per call; errors are not charged.
|
|
117
|
+
|
|
118
|
+
Example:
|
|
119
|
+
.. code-block:: python
|
|
120
|
+
|
|
121
|
+
from langchain_dataxapi import DataXAPIWeChatOfficialAccountArticles
|
|
122
|
+
|
|
123
|
+
tool = DataXAPIWeChatOfficialAccountArticles()
|
|
124
|
+
tool.invoke({"id": "gh_13c97ab93ce8"})
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
name: str = "dataxapi_wechat_mp_accounts_articles_list"
|
|
128
|
+
description: str = "Get a page of the articles a WeChat Official Account published, newest first: title, digest, link, time published. Each also says whether it was the lead article or one below, its format and cover. The page's articles tab by default; its videos or pictures tab when asked. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
129
|
+
args_schema: type[BaseModel] = DataXAPIWeChatOfficialAccountArticlesInput
|
|
130
|
+
endpoint: ClassVar[str] = "wechat_mp.accounts.articles.list"
|
|
131
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
132
|
+
example: ClassVar[dict[str, Any]] = {"id": "gh_13c97ab93ce8"}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class DataXAPIDouyinVideoCommentsInput(BaseModel):
|
|
136
|
+
"""Arguments of dataxapi_douyin_videos_comments_list."""
|
|
137
|
+
|
|
138
|
+
id: str | None = Field(
|
|
139
|
+
default=None,
|
|
140
|
+
description='Video ID, a string of digits. With only a link or a share text, give it as url. Example: "7694940173372575014".',
|
|
141
|
+
)
|
|
142
|
+
url: str | None = Field(
|
|
143
|
+
default=None,
|
|
144
|
+
description='Link to the video, pasted as it is: the https://www.douyin.com/video/… web link, a web link with modal_id in it, the page a share opens on a phone, the v.douyin.com short link the app copies, or a whole share text with one of these in it. A short link is opened once to see which video it leads to. Example: "https://www.douyin.com/video/7694940173372575014".',
|
|
145
|
+
)
|
|
146
|
+
cursor: str | None = Field(
|
|
147
|
+
default=None,
|
|
148
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class DataXAPIDouyinVideoComments(DataXAPIEndpointTool):
|
|
153
|
+
"""Douyin video comments (douyin.videos.comments.list).
|
|
154
|
+
|
|
155
|
+
Price: $0.002 per call; errors are not charged.
|
|
156
|
+
|
|
157
|
+
Example:
|
|
158
|
+
.. code-block:: python
|
|
159
|
+
|
|
160
|
+
from langchain_dataxapi import DataXAPIDouyinVideoComments
|
|
161
|
+
|
|
162
|
+
tool = DataXAPIDouyinVideoComments()
|
|
163
|
+
tool.invoke({"id": "7694940173372575014"})
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
name: str = "dataxapi_douyin_videos_comments_list"
|
|
167
|
+
description: str = "Get a page of comments on a Douyin video: text, commenter, likes, reply count, time posted. Give one of: id, url. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.002 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
168
|
+
args_schema: type[BaseModel] = DataXAPIDouyinVideoCommentsInput
|
|
169
|
+
endpoint: ClassVar[str] = "douyin.videos.comments.list"
|
|
170
|
+
one_of: ClassVar[tuple[str, ...]] = ("id", "url")
|
|
171
|
+
example: ClassVar[dict[str, Any]] = {"id": "7694940173372575014"}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class DataXAPIDouyinVideoMetricsInput(BaseModel):
|
|
175
|
+
"""Arguments of dataxapi_douyin_videos_metrics."""
|
|
176
|
+
|
|
177
|
+
id: str | None = Field(
|
|
178
|
+
default=None,
|
|
179
|
+
description='Video ID, a string of digits. With only a link or a share text, give it as url. Example: "7694940173372575014".',
|
|
180
|
+
)
|
|
181
|
+
url: str | None = Field(
|
|
182
|
+
default=None,
|
|
183
|
+
description='Link to the video, pasted as it is: the https://www.douyin.com/video/… web link, a web link with modal_id in it, the page a share opens on a phone, the v.douyin.com short link the app copies, or a whole share text with one of these in it. A short link is opened once to see which video it leads to. Example: "https://www.douyin.com/video/7694940173372575014".',
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class DataXAPIDouyinVideoMetrics(DataXAPIEndpointTool):
|
|
188
|
+
"""Douyin video play count (douyin.videos.metrics).
|
|
189
|
+
|
|
190
|
+
Price: $0.002 per call; errors are not charged.
|
|
191
|
+
|
|
192
|
+
Example:
|
|
193
|
+
.. code-block:: python
|
|
194
|
+
|
|
195
|
+
from langchain_dataxapi import DataXAPIDouyinVideoMetrics
|
|
196
|
+
|
|
197
|
+
tool = DataXAPIDouyinVideoMetrics()
|
|
198
|
+
tool.invoke({"id": "7694940173372575014"})
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
name: str = "dataxapi_douyin_videos_metrics"
|
|
202
|
+
description: str = "Get a Douyin video's counts as of now, by its ID: plays and likes. Give one of: id, url. Price: $0.002 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
203
|
+
args_schema: type[BaseModel] = DataXAPIDouyinVideoMetricsInput
|
|
204
|
+
endpoint: ClassVar[str] = "douyin.videos.metrics"
|
|
205
|
+
one_of: ClassVar[tuple[str, ...]] = ("id", "url")
|
|
206
|
+
example: ClassVar[dict[str, Any]] = {"id": "7694940173372575014"}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class DataXAPIWeChatArticleInput(BaseModel):
|
|
210
|
+
"""Arguments of dataxapi_wechat_mp_articles_get."""
|
|
211
|
+
|
|
212
|
+
url: str = Field(
|
|
213
|
+
description='Link to the article, pasted as it is: the long link with __biz, mid, idx and sn, the short /s/ link, or a share text with one of them in it. Example: "https://mp.weixin.qq.com/s?__biz=MjM5MjAxNDM4MA==&mid=2667038683&idx=1&sn=0422127e651acd7f6cf6ef7e1cff04bc".'
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class DataXAPIWeChatArticle(DataXAPIEndpointTool):
|
|
218
|
+
"""WeChat Official Account article detail (wechat_mp.articles.get).
|
|
219
|
+
|
|
220
|
+
Price: $0.02 per call; errors are not charged.
|
|
221
|
+
|
|
222
|
+
Example:
|
|
223
|
+
.. code-block:: python
|
|
224
|
+
|
|
225
|
+
from langchain_dataxapi import DataXAPIWeChatArticle
|
|
226
|
+
|
|
227
|
+
tool = DataXAPIWeChatArticle()
|
|
228
|
+
tool.invoke({"url": "https://mp.weixin.qq.com/s?__biz=MjM5MjAxNDM4MA==&mid=2667038683&idx=1&sn=0422127e651acd7f6cf6ef7e1cff04bc"})
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
name: str = "dataxapi_wechat_mp_articles_get"
|
|
232
|
+
description: str = "Get one WeChat Official Account article by its link: title, text, time published, the account's name and IDs. It also says whether it was the lead article or one below, its format, cover, digest, byline, \"read the original\" link and the IP location it was posted from. Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
233
|
+
args_schema: type[BaseModel] = DataXAPIWeChatArticleInput
|
|
234
|
+
endpoint: ClassVar[str] = "wechat_mp.articles.get"
|
|
235
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
236
|
+
example: ClassVar[dict[str, Any]] = {
|
|
237
|
+
"url": "https://mp.weixin.qq.com/s?__biz=MjM5MjAxNDM4MA==&mid=2667038683&idx=1&sn=0422127e651acd7f6cf6ef7e1cff04bc"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class DataXAPIDouyinKeywordTrendInput(BaseModel):
|
|
242
|
+
"""Arguments of dataxapi_douyin_index_keywords_history."""
|
|
243
|
+
|
|
244
|
+
since: str = Field(
|
|
245
|
+
description='The first day wanted: the China-time (UTC+8) calendar day this moment falls on; 2026-09-01 means 1 September. Example: "2026-09-01T00:00:00Z".'
|
|
246
|
+
)
|
|
247
|
+
until: str = Field(
|
|
248
|
+
description='The last day wanted, read the same way. The platform publishes a day or two late: a day it has no figure for yet has a null index. Example: "2026-09-30T00:00:00Z".'
|
|
249
|
+
)
|
|
250
|
+
keyword: str | None = Field(
|
|
251
|
+
default=None,
|
|
252
|
+
description='One keyword, at most 50 characters and without a comma; letter case does not matter. Example: "咖啡".',
|
|
253
|
+
)
|
|
254
|
+
keywords: list[str] | None = Field(
|
|
255
|
+
default=None,
|
|
256
|
+
description='One to five keywords, each at most 50 characters and without a comma; letter case does not matter. One item comes back per keyword that has figures; a keyword the index does not cover is not in the answer. Example: ["咖啡", "CityWalk"].',
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
class DataXAPIDouyinKeywordTrend(DataXAPIEndpointTool):
|
|
261
|
+
"""Douyin trend-index keyword trends (douyin.index.keywords.history).
|
|
262
|
+
|
|
263
|
+
Price: $0.006 per call; errors are not charged.
|
|
264
|
+
|
|
265
|
+
Example:
|
|
266
|
+
.. code-block:: python
|
|
267
|
+
|
|
268
|
+
from langchain_dataxapi import DataXAPIDouyinKeywordTrend
|
|
269
|
+
|
|
270
|
+
tool = DataXAPIDouyinKeywordTrend()
|
|
271
|
+
tool.invoke({"since": "2026-09-01T00:00:00Z", "until": "2026-09-30T00:00:00Z", "keyword": "咖啡"})
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
name: str = "dataxapi_douyin_index_keywords_history"
|
|
275
|
+
description: str = "Get the day-by-day search index and composite index of a keyword, or of one to five keywords at once, on Douyin over a date range, from the Douyin index, with the daily averages of the period, of the one before and of a year earlier. An index is the platform's score of volume, not a count of searches; days are calendar days in China time (UTC+8). Give one of: keywords, keyword. Price: $0.006 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
276
|
+
args_schema: type[BaseModel] = DataXAPIDouyinKeywordTrendInput
|
|
277
|
+
endpoint: ClassVar[str] = "douyin.index.keywords.history"
|
|
278
|
+
one_of: ClassVar[tuple[str, ...]] = ("keywords", "keyword")
|
|
279
|
+
example: ClassVar[dict[str, Any]] = {
|
|
280
|
+
"since": "2026-09-01T00:00:00Z",
|
|
281
|
+
"until": "2026-09-30T00:00:00Z",
|
|
282
|
+
"keyword": "咖啡",
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class DataXAPIWeChatSearchInput(BaseModel):
|
|
287
|
+
"""Arguments of dataxapi_wechat_posts_search."""
|
|
288
|
+
|
|
289
|
+
query: str = Field(description='Search terms. Example: "咖啡店开业".')
|
|
290
|
+
sort: Literal["relevance", "latest", "popular"] | None = Field(
|
|
291
|
+
default=None, description="By relevance, by time published (newest first) or by how hot. Default: relevance."
|
|
292
|
+
)
|
|
293
|
+
published_within: Literal["day", "week", "half_year"] | None = Field(
|
|
294
|
+
default=None, description="Only those published in the last day, week or half year."
|
|
295
|
+
)
|
|
296
|
+
type: Literal["article", "video"] | None = Field(
|
|
297
|
+
default=None,
|
|
298
|
+
description="Official Account articles only (article) or Channels videos only (video); both mixed when left out.",
|
|
299
|
+
)
|
|
300
|
+
cursor: str | None = Field(
|
|
301
|
+
default=None,
|
|
302
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
class DataXAPIWeChatSearch(DataXAPIEndpointTool):
|
|
307
|
+
"""WeChat Search articles and videos (wechat.posts.search).
|
|
308
|
+
|
|
309
|
+
Price: $0.02 per call; errors are not charged.
|
|
310
|
+
|
|
311
|
+
Example:
|
|
312
|
+
.. code-block:: python
|
|
313
|
+
|
|
314
|
+
from langchain_dataxapi import DataXAPIWeChatSearch
|
|
315
|
+
|
|
316
|
+
tool = DataXAPIWeChatSearch()
|
|
317
|
+
tool.invoke({"query": "咖啡店开业"})
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
name: str = "dataxapi_wechat_posts_search"
|
|
321
|
+
description: str = "Get a page of WeChat Search results for search terms: Official Account articles and Channels videos mixed, each saying in type whether it is an article or a video; by relevance, newest or hottest, filtered by time posted, or articles only or videos only: title or description, the source account's name, time published, an article's link (with a band of reads on some), a video's likes and saves. WeChat Search gives no account ID. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
322
|
+
args_schema: type[BaseModel] = DataXAPIWeChatSearchInput
|
|
323
|
+
endpoint: ClassVar[str] = "wechat.posts.search"
|
|
324
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
325
|
+
example: ClassVar[dict[str, Any]] = {"query": "咖啡店开业"}
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class DataXAPIWeChatChannelsVideoSearchInput(BaseModel):
|
|
329
|
+
"""Arguments of dataxapi_wechat_channels_videos_search."""
|
|
330
|
+
|
|
331
|
+
query: str = Field(description='Search terms. Example: "露营装备推荐".')
|
|
332
|
+
sort: Literal["relevance", "latest", "popular"] | None = Field(
|
|
333
|
+
default=None, description="By relevance, by time published (newest first) or by how hot. Default: relevance."
|
|
334
|
+
)
|
|
335
|
+
published_within: Literal["day", "week", "half_year"] | None = Field(
|
|
336
|
+
default=None, description="Only those published in the last day, week or half year."
|
|
337
|
+
)
|
|
338
|
+
cursor: str | None = Field(
|
|
339
|
+
default=None,
|
|
340
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class DataXAPIWeChatChannelsVideoSearch(DataXAPIEndpointTool):
|
|
345
|
+
"""WeChat Channels video search (wechat_channels.videos.search).
|
|
346
|
+
|
|
347
|
+
Price: $0.02 per call; errors are not charged.
|
|
348
|
+
|
|
349
|
+
Example:
|
|
350
|
+
.. code-block:: python
|
|
351
|
+
|
|
352
|
+
from langchain_dataxapi import DataXAPIWeChatChannelsVideoSearch
|
|
353
|
+
|
|
354
|
+
tool = DataXAPIWeChatChannelsVideoSearch()
|
|
355
|
+
tool.invoke({"query": "露营装备推荐"})
|
|
356
|
+
"""
|
|
357
|
+
|
|
358
|
+
name: str = "dataxapi_wechat_channels_videos_search"
|
|
359
|
+
description: str = "Get a page of WeChat Channels videos for search terms through WeChat Search, by relevance, newest or hottest, filtered by time posted: description, the account's name and avatar, time published, likes and saves, length, cover. WeChat Search gives no account ID, and a video's ID is an encrypted one starting with export/: given as export_id to wechat_channels.videos.get it yields the numeric ID, the video file's address and the key that decrypts it; it expires, so use it soon. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
360
|
+
args_schema: type[BaseModel] = DataXAPIWeChatChannelsVideoSearchInput
|
|
361
|
+
endpoint: ClassVar[str] = "wechat_channels.videos.search"
|
|
362
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
363
|
+
example: ClassVar[dict[str, Any]] = {"query": "露营装备推荐"}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
class DataXAPIXiaohongshuNoteCommentsInput(BaseModel):
|
|
367
|
+
"""Arguments of dataxapi_xiaohongshu_notes_comments_list."""
|
|
368
|
+
|
|
369
|
+
id: str | None = Field(
|
|
370
|
+
default=None,
|
|
371
|
+
description='Note ID, 24 hexadecimal characters. With only a link or a share text, give it as url. Example: "6a9c5884000000002b002d95".',
|
|
372
|
+
)
|
|
373
|
+
url: str | None = Field(
|
|
374
|
+
default=None,
|
|
375
|
+
description='Link to the note, pasted as it is: the https://www.xiaohongshu.com/explore/… address from the browser, the https://www.xiaohongshu.com/discovery/item/… link the website shares (query parameters such as xsec_token are fine), a whole share text with such a link in it, or the xhslink.com short link the app copies (alone or in its share text). A short link is opened once to see which note it leads to; where it cannot be, paste the note\'s full link or its ID. Example: "https://www.xiaohongshu.com/explore/6a9c5884000000002b002d95?xsec_token=ABx1y2z3".',
|
|
376
|
+
)
|
|
377
|
+
sort: Literal["latest", "popular"] | None = Field(
|
|
378
|
+
default=None, description="Newest first (the default), or hottest first (most liked first). Default: latest."
|
|
379
|
+
)
|
|
380
|
+
cursor: str | None = Field(
|
|
381
|
+
default=None,
|
|
382
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class DataXAPIXiaohongshuNoteComments(DataXAPIEndpointTool):
|
|
387
|
+
"""Xiaohongshu note comments (xiaohongshu.notes.comments.list).
|
|
388
|
+
|
|
389
|
+
Price: $0.02 per call; errors are not charged.
|
|
390
|
+
|
|
391
|
+
Example:
|
|
392
|
+
.. code-block:: python
|
|
393
|
+
|
|
394
|
+
from langchain_dataxapi import DataXAPIXiaohongshuNoteComments
|
|
395
|
+
|
|
396
|
+
tool = DataXAPIXiaohongshuNoteComments()
|
|
397
|
+
tool.invoke({"id": "6a9c5884000000002b002d95"})
|
|
398
|
+
"""
|
|
399
|
+
|
|
400
|
+
name: str = "dataxapi_xiaohongshu_notes_comments_list"
|
|
401
|
+
description: str = "Get a page of top-level comments on a Xiaohongshu note by ID or link, newest first or hottest first: text, commenter, likes, reply count, time posted. Give one of: id, url. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.02 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
402
|
+
args_schema: type[BaseModel] = DataXAPIXiaohongshuNoteCommentsInput
|
|
403
|
+
endpoint: ClassVar[str] = "xiaohongshu.notes.comments.list"
|
|
404
|
+
one_of: ClassVar[tuple[str, ...]] = ("id", "url")
|
|
405
|
+
example: ClassVar[dict[str, Any]] = {"id": "6a9c5884000000002b002d95"}
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class DataXAPITikTokVideoSearchInput(BaseModel):
|
|
409
|
+
"""Arguments of dataxapi_tiktok_videos_search."""
|
|
410
|
+
|
|
411
|
+
query: str = Field(description='Search terms. Example: "space station".')
|
|
412
|
+
sort: Literal["relevance", "popular", "latest"] | None = Field(
|
|
413
|
+
default=None, description="By relevance, by likes, or newest first. Default: relevance."
|
|
414
|
+
)
|
|
415
|
+
published_within: Literal["day", "week", "month", "half_year"] | None = Field(
|
|
416
|
+
default=None, description="Only videos posted within this period."
|
|
417
|
+
)
|
|
418
|
+
cursor: str | None = Field(
|
|
419
|
+
default=None,
|
|
420
|
+
description="Leave out for the first page. For the next page, the page.next_cursor of the last answer, with the same other arguments; each page is charged on its own.",
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
class DataXAPITikTokVideoSearch(DataXAPIEndpointTool):
|
|
425
|
+
"""TikTok video search (tiktok.videos.search).
|
|
426
|
+
|
|
427
|
+
Price: $0.002 per call; errors are not charged.
|
|
428
|
+
|
|
429
|
+
Example:
|
|
430
|
+
.. code-block:: python
|
|
431
|
+
|
|
432
|
+
from langchain_dataxapi import DataXAPITikTokVideoSearch
|
|
433
|
+
|
|
434
|
+
tool = DataXAPITikTokVideoSearch()
|
|
435
|
+
tool.invoke({"query": "space station"})
|
|
436
|
+
"""
|
|
437
|
+
|
|
438
|
+
name: str = "dataxapi_tiktok_videos_search"
|
|
439
|
+
description: str = "Search TikTok videos by keyword, 30 a page; sort by relevance, likes or time posted, and limit how recently they were posted. One call returns one page; for the next, call again with cursor set to page.next_cursor (charged on its own). Price: $0.002 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
440
|
+
args_schema: type[BaseModel] = DataXAPITikTokVideoSearchInput
|
|
441
|
+
endpoint: ClassVar[str] = "tiktok.videos.search"
|
|
442
|
+
one_of: ClassVar[tuple[str, ...]] = ()
|
|
443
|
+
example: ClassVar[dict[str, Any]] = {"query": "space station"}
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
class DataXAPIYouTubeTranscriptInput(BaseModel):
|
|
447
|
+
"""Arguments of dataxapi_youtube_videos_transcript_get."""
|
|
448
|
+
|
|
449
|
+
id: str | None = Field(default=None, description='Video ID. Example: "dQw4w9WgXcQ".')
|
|
450
|
+
url: str | None = Field(
|
|
451
|
+
default=None,
|
|
452
|
+
description='Link to the video: a watch, shorts, embed, live or youtu.be link. Example: "https://www.youtube.com/watch?v=dQw4w9WgXcQ".',
|
|
453
|
+
)
|
|
454
|
+
lang: str | None = Field(
|
|
455
|
+
default=None,
|
|
456
|
+
description='Which language of captions to get, as a language code (en, es, ja, zh-Hans, say); left out, the captions of the video\'s own language come first. A video without captions in that language is answered as one without captions. Example: "en".',
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
class DataXAPIYouTubeTranscript(DataXAPIEndpointTool):
|
|
461
|
+
"""YouTube video transcript (youtube.videos.transcript.get).
|
|
462
|
+
|
|
463
|
+
Price: $0.002 per call; errors are not charged.
|
|
464
|
+
|
|
465
|
+
Example:
|
|
466
|
+
.. code-block:: python
|
|
467
|
+
|
|
468
|
+
from langchain_dataxapi import DataXAPIYouTubeTranscript
|
|
469
|
+
|
|
470
|
+
tool = DataXAPIYouTubeTranscript()
|
|
471
|
+
tool.invoke({"id": "dQw4w9WgXcQ"})
|
|
472
|
+
"""
|
|
473
|
+
|
|
474
|
+
name: str = "dataxapi_youtube_videos_transcript_get"
|
|
475
|
+
description: str = "Get the transcript of a YouTube video by ID or link: the whole text and timed segments. lang chooses the language of the captions. Give one of: id, url. Price: $0.002 per call; errors are not charged. No sign-in to the user's own platform account is needed."
|
|
476
|
+
args_schema: type[BaseModel] = DataXAPIYouTubeTranscriptInput
|
|
477
|
+
endpoint: ClassVar[str] = "youtube.videos.transcript.get"
|
|
478
|
+
one_of: ClassVar[tuple[str, ...]] = ("id", "url")
|
|
479
|
+
example: ClassVar[dict[str, Any]] = {"id": "dQw4w9WgXcQ"}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
ENDPOINT_TOOLS: tuple[type[DataXAPIEndpointTool], ...] = (
|
|
483
|
+
DataXAPIXiaohongshuNoteSearch,
|
|
484
|
+
DataXAPIDouyinVideoSearch,
|
|
485
|
+
DataXAPIWeChatOfficialAccountArticles,
|
|
486
|
+
DataXAPIDouyinVideoComments,
|
|
487
|
+
DataXAPIDouyinVideoMetrics,
|
|
488
|
+
DataXAPIWeChatArticle,
|
|
489
|
+
DataXAPIDouyinKeywordTrend,
|
|
490
|
+
DataXAPIWeChatSearch,
|
|
491
|
+
DataXAPIWeChatChannelsVideoSearch,
|
|
492
|
+
DataXAPIXiaohongshuNoteComments,
|
|
493
|
+
DataXAPITikTokVideoSearch,
|
|
494
|
+
DataXAPIYouTubeTranscript,
|
|
495
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""All DataXAPI tools as one toolkit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from langchain_core.tools import BaseTool, BaseToolkit
|
|
8
|
+
from langchain_core.utils import secret_from_env
|
|
9
|
+
from pydantic import Field, SecretStr
|
|
10
|
+
|
|
11
|
+
from langchain_dataxapi._client import DEFAULT_BASE_URL, DEFAULT_TIMEOUT
|
|
12
|
+
from langchain_dataxapi.endpoint_tools import ENDPOINT_TOOLS
|
|
13
|
+
from langchain_dataxapi.tools import DataXAPIBaseTool, DataXAPICall, DataXAPIFind
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DataXAPIToolkit(BaseToolkit):
|
|
17
|
+
"""The DataXAPI tools: find an endpoint (free), call any endpoint, and one tool per popular endpoint.
|
|
18
|
+
|
|
19
|
+
Setup:
|
|
20
|
+
.. code-block:: bash
|
|
21
|
+
|
|
22
|
+
pip install -U langchain-dataxapi
|
|
23
|
+
export DATAXAPI_API_KEY="dx_..."
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
.. code-block:: python
|
|
27
|
+
|
|
28
|
+
from langchain.agents import create_agent
|
|
29
|
+
from langchain_dataxapi import DataXAPIToolkit
|
|
30
|
+
|
|
31
|
+
agent = create_agent("claude-sonnet-4-6", DataXAPIToolkit().get_tools())
|
|
32
|
+
question = "What are people saying about 露营 on Xiaohongshu?"
|
|
33
|
+
agent.invoke({"messages": [{"role": "user", "content": question}]})
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
api_key: SecretStr | None = Field(default_factory=secret_from_env("DATAXAPI_API_KEY", default=None))
|
|
37
|
+
"""DataXAPI API key. Read from ``DATAXAPI_API_KEY`` when left out."""
|
|
38
|
+
base_url: str = DEFAULT_BASE_URL
|
|
39
|
+
"""API base URL."""
|
|
40
|
+
timeout: float = DEFAULT_TIMEOUT
|
|
41
|
+
"""Seconds to wait for one answer."""
|
|
42
|
+
endpoint_tools: bool = True
|
|
43
|
+
"""Include the one-endpoint tools. False gives only ``dataxapi_find`` and ``dataxapi_call``."""
|
|
44
|
+
transport: Any = Field(default=None, exclude=True, repr=False)
|
|
45
|
+
"""An ``httpx`` transport to send requests through instead of the network (tests, proxies)."""
|
|
46
|
+
|
|
47
|
+
def get_tools(self) -> list[BaseTool]:
|
|
48
|
+
"""dataxapi_find and dataxapi_call first, then the one-endpoint tools by how much they are used."""
|
|
49
|
+
classes: list[type[DataXAPIBaseTool]] = [DataXAPIFind, DataXAPICall]
|
|
50
|
+
if self.endpoint_tools:
|
|
51
|
+
classes.extend(ENDPOINT_TOOLS)
|
|
52
|
+
return [
|
|
53
|
+
cls(api_key=self.api_key, base_url=self.base_url, timeout=self.timeout, transport=self.transport) # type: ignore[call-arg]
|
|
54
|
+
for cls in classes
|
|
55
|
+
]
|