llm-scrapingrabbit 0.1.0__tar.gz
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.
- llm_scrapingrabbit-0.1.0/LICENSE +21 -0
- llm_scrapingrabbit-0.1.0/PKG-INFO +91 -0
- llm_scrapingrabbit-0.1.0/README.md +61 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/PKG-INFO +91 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/SOURCES.txt +11 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/dependency_links.txt +1 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/entry_points.txt +2 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/requires.txt +6 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.egg-info/top_level.txt +1 -0
- llm_scrapingrabbit-0.1.0/llm_scrapingrabbit.py +180 -0
- llm_scrapingrabbit-0.1.0/pyproject.toml +44 -0
- llm_scrapingrabbit-0.1.0/setup.cfg +4 -0
- llm_scrapingrabbit-0.1.0/tests/test_scrapingrabbit.py +171 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ScrapingRabbit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-scrapingrabbit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ScrapingRabbit for LLM: load YouTube, TikTok and X transcripts as fragments, give models 31 web data tools (social profiles, Amazon and Walmart products, Google results, SEO data) and call any endpoint from the command line.
|
|
5
|
+
Author: ScrapingRabbit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://scrapingrabbit.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/scrapingrabbit/llm-scrapingrabbit#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/scrapingrabbit/llm-scrapingrabbit
|
|
10
|
+
Project-URL: Issues, https://github.com/scrapingrabbit/llm-scrapingrabbit/issues
|
|
11
|
+
Project-URL: API reference, https://scrapingrabbit.com/docs
|
|
12
|
+
Keywords: llm,llm-plugin,fragments,tools,web-data,youtube-transcript,tiktok,instagram,amazon,serp,scrapingrabbit
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: llm>=0.26
|
|
25
|
+
Requires-Dist: scrapingrabbit<1.0.0,>=0.2.0
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Requires-Dist: llm-echo>=0.3; extra == "test"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# llm-scrapingrabbit
|
|
32
|
+
|
|
33
|
+
[ScrapingRabbit](https://scrapingrabbit.com) for Simon Willison's [LLM](https://llm.datasette.io) command-line tool:
|
|
34
|
+
|
|
35
|
+
- **Fragments**: load a YouTube, TikTok or X video transcript straight into a prompt.
|
|
36
|
+
- **Tools**: 31 `scrapingrabbit_*` tools a model can call. They cover video transcripts, YouTube comments and channels, Instagram, TikTok and Snapchat profiles, Amazon and Walmart products, Google News, Maps, Trends and autocomplete, App Store, SEO data and email verification.
|
|
37
|
+
- **Command**: `llm scrapingrabbit ENDPOINT key=value` prints any endpoint's JSON.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
llm install llm-scrapingrabbit
|
|
43
|
+
llm keys set scrapingrabbit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Get a key at [scrapingrabbit.com/login](https://scrapingrabbit.com/login) (100 free credits, no card). `SCRAPINGRABBIT_API_KEY` works too.
|
|
47
|
+
|
|
48
|
+
## Fragments
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
llm -f sr-youtube:https://www.youtube.com/watch?v=dQw4w9WgXcQ "Summarise this in five bullets"
|
|
52
|
+
llm -f sr-tiktok:https://www.tiktok.com/@nasa/video/7360000000000000000 "What is announced here?"
|
|
53
|
+
llm -f sr-x:https://x.com/NASA/status/1800000000000000000 "Quote the key claim"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Each fragment costs 1 credit when the video has a transcript. Videos without captions fail, and failures are free. LLM caches fragments, so asking more questions about the same video doesn't call the API again.
|
|
57
|
+
|
|
58
|
+
## Tools
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
llm -T scrapingrabbit_tiktok_profile_viewer "Is @nasa growing on TikTok? Show the numbers." --td
|
|
62
|
+
llm -T scrapingrabbit_youtube_transcript -T scrapingrabbit_youtube_comment_extractor \
|
|
63
|
+
"What do viewers think of https://youtu.be/dQw4w9WgXcQ compared with what the video says?"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`llm tools list` shows them all. Pass only the tools a task needs: fewer tools means better picks and shorter prompts. Results longer than 60,000 characters are cut, with a note telling the model. When the API refuses a call, the model gets the reason and the note that failed calls are not charged.
|
|
67
|
+
|
|
68
|
+
## Command
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
llm scrapingrabbit # list endpoints and their parameters
|
|
72
|
+
llm scrapingrabbit domain_authority_checker domain=example.com
|
|
73
|
+
llm scrapingrabbit google_news_search query="open source llm"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Also available
|
|
77
|
+
|
|
78
|
+
[Python client](https://github.com/scrapingrabbit/scrapingrabbit-python) · [MCP server and CLI](https://github.com/scrapingrabbit/scrapingrabbit-mcp) · [LangChain](https://github.com/scrapingrabbit/langchain-scrapingrabbit) · [Haystack](https://github.com/scrapingrabbit/scrapingrabbit-haystack) · [Vercel AI SDK](https://github.com/scrapingrabbit/ai-sdk-scrapingrabbit) · [API docs](https://scrapingrabbit.com/docs)
|
|
79
|
+
|
|
80
|
+
## Develop
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install -e '.[test]'
|
|
84
|
+
pytest # runs fragments, tools (through LLM's echo model) and the command against a local fake API
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Release: bump `version` in pyproject.toml and push a matching tag (`v0.1.0`). The publish workflow uses PyPI trusted publishing.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# llm-scrapingrabbit
|
|
2
|
+
|
|
3
|
+
[ScrapingRabbit](https://scrapingrabbit.com) for Simon Willison's [LLM](https://llm.datasette.io) command-line tool:
|
|
4
|
+
|
|
5
|
+
- **Fragments**: load a YouTube, TikTok or X video transcript straight into a prompt.
|
|
6
|
+
- **Tools**: 31 `scrapingrabbit_*` tools a model can call. They cover video transcripts, YouTube comments and channels, Instagram, TikTok and Snapchat profiles, Amazon and Walmart products, Google News, Maps, Trends and autocomplete, App Store, SEO data and email verification.
|
|
7
|
+
- **Command**: `llm scrapingrabbit ENDPOINT key=value` prints any endpoint's JSON.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
llm install llm-scrapingrabbit
|
|
13
|
+
llm keys set scrapingrabbit
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Get a key at [scrapingrabbit.com/login](https://scrapingrabbit.com/login) (100 free credits, no card). `SCRAPINGRABBIT_API_KEY` works too.
|
|
17
|
+
|
|
18
|
+
## Fragments
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
llm -f sr-youtube:https://www.youtube.com/watch?v=dQw4w9WgXcQ "Summarise this in five bullets"
|
|
22
|
+
llm -f sr-tiktok:https://www.tiktok.com/@nasa/video/7360000000000000000 "What is announced here?"
|
|
23
|
+
llm -f sr-x:https://x.com/NASA/status/1800000000000000000 "Quote the key claim"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Each fragment costs 1 credit when the video has a transcript. Videos without captions fail, and failures are free. LLM caches fragments, so asking more questions about the same video doesn't call the API again.
|
|
27
|
+
|
|
28
|
+
## Tools
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
llm -T scrapingrabbit_tiktok_profile_viewer "Is @nasa growing on TikTok? Show the numbers." --td
|
|
32
|
+
llm -T scrapingrabbit_youtube_transcript -T scrapingrabbit_youtube_comment_extractor \
|
|
33
|
+
"What do viewers think of https://youtu.be/dQw4w9WgXcQ compared with what the video says?"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`llm tools list` shows them all. Pass only the tools a task needs: fewer tools means better picks and shorter prompts. Results longer than 60,000 characters are cut, with a note telling the model. When the API refuses a call, the model gets the reason and the note that failed calls are not charged.
|
|
37
|
+
|
|
38
|
+
## Command
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
llm scrapingrabbit # list endpoints and their parameters
|
|
42
|
+
llm scrapingrabbit domain_authority_checker domain=example.com
|
|
43
|
+
llm scrapingrabbit google_news_search query="open source llm"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Also available
|
|
47
|
+
|
|
48
|
+
[Python client](https://github.com/scrapingrabbit/scrapingrabbit-python) · [MCP server and CLI](https://github.com/scrapingrabbit/scrapingrabbit-mcp) · [LangChain](https://github.com/scrapingrabbit/langchain-scrapingrabbit) · [Haystack](https://github.com/scrapingrabbit/scrapingrabbit-haystack) · [Vercel AI SDK](https://github.com/scrapingrabbit/ai-sdk-scrapingrabbit) · [API docs](https://scrapingrabbit.com/docs)
|
|
49
|
+
|
|
50
|
+
## Develop
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install -e '.[test]'
|
|
54
|
+
pytest # runs fragments, tools (through LLM's echo model) and the command against a local fake API
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Release: bump `version` in pyproject.toml and push a matching tag (`v0.1.0`). The publish workflow uses PyPI trusted publishing.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-scrapingrabbit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ScrapingRabbit for LLM: load YouTube, TikTok and X transcripts as fragments, give models 31 web data tools (social profiles, Amazon and Walmart products, Google results, SEO data) and call any endpoint from the command line.
|
|
5
|
+
Author: ScrapingRabbit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://scrapingrabbit.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/scrapingrabbit/llm-scrapingrabbit#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/scrapingrabbit/llm-scrapingrabbit
|
|
10
|
+
Project-URL: Issues, https://github.com/scrapingrabbit/llm-scrapingrabbit/issues
|
|
11
|
+
Project-URL: API reference, https://scrapingrabbit.com/docs
|
|
12
|
+
Keywords: llm,llm-plugin,fragments,tools,web-data,youtube-transcript,tiktok,instagram,amazon,serp,scrapingrabbit
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: llm>=0.26
|
|
25
|
+
Requires-Dist: scrapingrabbit<1.0.0,>=0.2.0
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Requires-Dist: llm-echo>=0.3; extra == "test"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# llm-scrapingrabbit
|
|
32
|
+
|
|
33
|
+
[ScrapingRabbit](https://scrapingrabbit.com) for Simon Willison's [LLM](https://llm.datasette.io) command-line tool:
|
|
34
|
+
|
|
35
|
+
- **Fragments**: load a YouTube, TikTok or X video transcript straight into a prompt.
|
|
36
|
+
- **Tools**: 31 `scrapingrabbit_*` tools a model can call. They cover video transcripts, YouTube comments and channels, Instagram, TikTok and Snapchat profiles, Amazon and Walmart products, Google News, Maps, Trends and autocomplete, App Store, SEO data and email verification.
|
|
37
|
+
- **Command**: `llm scrapingrabbit ENDPOINT key=value` prints any endpoint's JSON.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
llm install llm-scrapingrabbit
|
|
43
|
+
llm keys set scrapingrabbit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Get a key at [scrapingrabbit.com/login](https://scrapingrabbit.com/login) (100 free credits, no card). `SCRAPINGRABBIT_API_KEY` works too.
|
|
47
|
+
|
|
48
|
+
## Fragments
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
llm -f sr-youtube:https://www.youtube.com/watch?v=dQw4w9WgXcQ "Summarise this in five bullets"
|
|
52
|
+
llm -f sr-tiktok:https://www.tiktok.com/@nasa/video/7360000000000000000 "What is announced here?"
|
|
53
|
+
llm -f sr-x:https://x.com/NASA/status/1800000000000000000 "Quote the key claim"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Each fragment costs 1 credit when the video has a transcript. Videos without captions fail, and failures are free. LLM caches fragments, so asking more questions about the same video doesn't call the API again.
|
|
57
|
+
|
|
58
|
+
## Tools
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
llm -T scrapingrabbit_tiktok_profile_viewer "Is @nasa growing on TikTok? Show the numbers." --td
|
|
62
|
+
llm -T scrapingrabbit_youtube_transcript -T scrapingrabbit_youtube_comment_extractor \
|
|
63
|
+
"What do viewers think of https://youtu.be/dQw4w9WgXcQ compared with what the video says?"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`llm tools list` shows them all. Pass only the tools a task needs: fewer tools means better picks and shorter prompts. Results longer than 60,000 characters are cut, with a note telling the model. When the API refuses a call, the model gets the reason and the note that failed calls are not charged.
|
|
67
|
+
|
|
68
|
+
## Command
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
llm scrapingrabbit # list endpoints and their parameters
|
|
72
|
+
llm scrapingrabbit domain_authority_checker domain=example.com
|
|
73
|
+
llm scrapingrabbit google_news_search query="open source llm"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Also available
|
|
77
|
+
|
|
78
|
+
[Python client](https://github.com/scrapingrabbit/scrapingrabbit-python) · [MCP server and CLI](https://github.com/scrapingrabbit/scrapingrabbit-mcp) · [LangChain](https://github.com/scrapingrabbit/langchain-scrapingrabbit) · [Haystack](https://github.com/scrapingrabbit/scrapingrabbit-haystack) · [Vercel AI SDK](https://github.com/scrapingrabbit/ai-sdk-scrapingrabbit) · [API docs](https://scrapingrabbit.com/docs)
|
|
79
|
+
|
|
80
|
+
## Develop
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install -e '.[test]'
|
|
84
|
+
pytest # runs fragments, tools (through LLM's echo model) and the command against a local fake API
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Release: bump `version` in pyproject.toml and push a matching tag (`v0.1.0`). The publish workflow uses PyPI trusted publishing.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
llm_scrapingrabbit.py
|
|
4
|
+
pyproject.toml
|
|
5
|
+
llm_scrapingrabbit.egg-info/PKG-INFO
|
|
6
|
+
llm_scrapingrabbit.egg-info/SOURCES.txt
|
|
7
|
+
llm_scrapingrabbit.egg-info/dependency_links.txt
|
|
8
|
+
llm_scrapingrabbit.egg-info/entry_points.txt
|
|
9
|
+
llm_scrapingrabbit.egg-info/requires.txt
|
|
10
|
+
llm_scrapingrabbit.egg-info/top_level.txt
|
|
11
|
+
tests/test_scrapingrabbit.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
llm_scrapingrabbit
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""ScrapingRabbit for LLM (https://llm.datasette.io): web data as fragments, tools and a command.
|
|
2
|
+
|
|
3
|
+
Hooks:
|
|
4
|
+
|
|
5
|
+
* ``register_fragment_loaders``: ``llm -f sr-youtube:URL``, ``sr-tiktok:URL`` and ``sr-x:URL`` load a video transcript
|
|
6
|
+
* ``register_tools``: one ``scrapingrabbit_<endpoint>`` tool per API endpoint, for ``llm -T ...``
|
|
7
|
+
* ``register_commands``: ``llm scrapingrabbit ENDPOINT key=value ...`` prints an endpoint's JSON
|
|
8
|
+
"""
|
|
9
|
+
import json
|
|
10
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
11
|
+
|
|
12
|
+
import click
|
|
13
|
+
import llm
|
|
14
|
+
from scrapingrabbit import ENDPOINTS, ScrapingRabbit, ScrapingRabbitError
|
|
15
|
+
|
|
16
|
+
KEY_ALIAS = "scrapingrabbit"
|
|
17
|
+
KEY_ENV_VAR = "SCRAPINGRABBIT_API_KEY"
|
|
18
|
+
LOGIN_URL = "https://scrapingrabbit.com/login"
|
|
19
|
+
TOOL_PREFIX = "scrapingrabbit_"
|
|
20
|
+
MAX_TOOL_CHARS = 60_000
|
|
21
|
+
MAX_ARGUMENT_LENGTH = 2_000
|
|
22
|
+
BY_NAME = {endpoint["name"]: endpoint for endpoint in ENDPOINTS}
|
|
23
|
+
|
|
24
|
+
# Fix hints keyed by API error code; anything else uses the API's own message.
|
|
25
|
+
HINTS = {
|
|
26
|
+
"MISSING_API_KEY": f"Set a key with: llm keys set {KEY_ALIAS}",
|
|
27
|
+
"INVALID_API_KEY": f"Replace it with: llm keys set {KEY_ALIAS}",
|
|
28
|
+
"PAYMENT_REQUIRED": "Out of credits. Top up at https://scrapingrabbit.com/pricing",
|
|
29
|
+
"RATE_LIMITED": "Rate limited. Wait a moment and try again.",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Fragment prefix -> (endpoint, what the argument is).
|
|
33
|
+
FRAGMENT_SOURCES = {
|
|
34
|
+
"sr-youtube": ("youtube_transcript", "a YouTube video URL or ID"),
|
|
35
|
+
"sr-tiktok": ("tiktok_transcript", "a TikTok video URL"),
|
|
36
|
+
"sr-x": ("x_video_transcript", "an X (Twitter) post URL with a video"),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ScrapingRabbitPluginError(ValueError):
|
|
41
|
+
"""A problem the user or model can act on."""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_client() -> ScrapingRabbit:
|
|
45
|
+
api_key = llm.get_key(alias=KEY_ALIAS, env=KEY_ENV_VAR)
|
|
46
|
+
if not api_key:
|
|
47
|
+
raise ScrapingRabbitPluginError(
|
|
48
|
+
f"No ScrapingRabbit API key found. Set one with `llm keys set {KEY_ALIAS}` or export {KEY_ENV_VAR}. "
|
|
49
|
+
f"Get one (100 free credits, no card) at {LOGIN_URL}"
|
|
50
|
+
)
|
|
51
|
+
return ScrapingRabbit(api_key=api_key)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def call(name: str, params: Dict[str, Any]) -> Any:
|
|
55
|
+
"""Call one endpoint and turn SDK errors into short messages that say what to do."""
|
|
56
|
+
endpoint = BY_NAME[name]
|
|
57
|
+
known = {p["name"] for p in endpoint["params"]}
|
|
58
|
+
unknown = sorted(set(params) - known)
|
|
59
|
+
if unknown:
|
|
60
|
+
raise ScrapingRabbitPluginError(f"Unknown argument(s): {', '.join(unknown)}. Allowed: {', '.join(sorted(known)) or 'none'}.")
|
|
61
|
+
# Every API parameter is a string; models sometimes send ids as numbers.
|
|
62
|
+
clean = {k: str(v) for k, v in params.items() if v is not None and str(v) != ""}
|
|
63
|
+
missing = [p["name"] for p in endpoint["params"] if p["required"] and p["name"] not in clean]
|
|
64
|
+
if missing:
|
|
65
|
+
raise ScrapingRabbitPluginError(f"Missing required argument(s): {', '.join(missing)}.")
|
|
66
|
+
try:
|
|
67
|
+
return getattr(get_client(), name)(**clean)
|
|
68
|
+
except ScrapingRabbitError as error:
|
|
69
|
+
hint = HINTS.get(error.code)
|
|
70
|
+
# Only a refusal from the API (it has an HTTP status) is known to be free; a client-side timeout may still be charged.
|
|
71
|
+
free = " Failed calls are not charged." if error.status is not None else ""
|
|
72
|
+
raise ScrapingRabbitPluginError(f"{str(error).rstrip('.')}.{free}{' ' + hint if hint else ''}") from None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def transcript_text(data: Dict[str, Any]) -> str:
|
|
76
|
+
if isinstance(data.get("text"), str) and data["text"].strip():
|
|
77
|
+
return data["text"]
|
|
78
|
+
lines = data.get("transcript") or []
|
|
79
|
+
return " ".join(line.get("text", "") for line in lines if isinstance(line, dict) and line.get("text"))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def make_loader(prefix: str) -> Callable[[str], llm.Fragment]:
|
|
83
|
+
endpoint, what = FRAGMENT_SOURCES[prefix]
|
|
84
|
+
|
|
85
|
+
def loader(argument: str) -> llm.Fragment:
|
|
86
|
+
argument = (argument or "").strip()
|
|
87
|
+
if not argument:
|
|
88
|
+
raise ScrapingRabbitPluginError(f"Give {what} after {prefix}:")
|
|
89
|
+
if len(argument) > MAX_ARGUMENT_LENGTH:
|
|
90
|
+
raise ScrapingRabbitPluginError("That link is too long.")
|
|
91
|
+
data = call(endpoint, {"url": argument})
|
|
92
|
+
body = transcript_text(data)
|
|
93
|
+
if not body.strip():
|
|
94
|
+
raise ScrapingRabbitPluginError("The video has no transcript text.")
|
|
95
|
+
header = [f"Transcript of {argument}"]
|
|
96
|
+
if data.get("author"):
|
|
97
|
+
header.append(f"Author: {data['author']}")
|
|
98
|
+
if data.get("language"):
|
|
99
|
+
header.append(f"Language: {data['language']}{' (auto-generated)' if data.get('isAutoGenerated') else ''}")
|
|
100
|
+
return llm.Fragment("\n".join(header) + "\n\n" + body, argument)
|
|
101
|
+
|
|
102
|
+
loader.__doc__ = f"Transcript of {what} via ScrapingRabbit (1 credit). Example: llm -f {prefix}:URL 'summarize this'"
|
|
103
|
+
return loader
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def fit(data: Any, max_chars: int = MAX_TOOL_CHARS) -> str:
|
|
107
|
+
"""JSON text, cut to max_chars with a note so one call can't flood the model's context."""
|
|
108
|
+
text = json.dumps(data, ensure_ascii=False)
|
|
109
|
+
if len(text) <= max_chars:
|
|
110
|
+
return text
|
|
111
|
+
note = f"\n[Cut: showing {max_chars} of {len(text)} characters of JSON. The last record is incomplete. Ask for less to see the rest.]"
|
|
112
|
+
return text[: max_chars - len(note)] + note
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def make_tool(endpoint: Dict[str, Any]) -> llm.Tool:
|
|
116
|
+
name = endpoint["name"]
|
|
117
|
+
|
|
118
|
+
def run(**kwargs: Any) -> str:
|
|
119
|
+
return fit(call(name, kwargs))
|
|
120
|
+
|
|
121
|
+
return llm.Tool(
|
|
122
|
+
name=TOOL_PREFIX + name,
|
|
123
|
+
# The API's description already says what a call costs.
|
|
124
|
+
description=endpoint["description"] or endpoint["summary"],
|
|
125
|
+
input_schema={
|
|
126
|
+
"type": "object",
|
|
127
|
+
"properties": {p["name"]: {"type": "string", "description": p["description"]} for p in endpoint["params"]},
|
|
128
|
+
"required": [p["name"] for p in endpoint["params"] if p["required"]],
|
|
129
|
+
"additionalProperties": False,
|
|
130
|
+
},
|
|
131
|
+
implementation=run,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@llm.hookimpl
|
|
136
|
+
def register_fragment_loaders(register):
|
|
137
|
+
for prefix in FRAGMENT_SOURCES:
|
|
138
|
+
register(prefix, make_loader(prefix))
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@llm.hookimpl
|
|
142
|
+
def register_tools(register):
|
|
143
|
+
for endpoint in ENDPOINTS:
|
|
144
|
+
register(make_tool(endpoint))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def parse_pairs(pairs: List[str]) -> Dict[str, str]:
|
|
148
|
+
params: Dict[str, str] = {}
|
|
149
|
+
for pair in pairs:
|
|
150
|
+
key, sep, value = pair.partition("=")
|
|
151
|
+
if not sep or not key:
|
|
152
|
+
raise click.UsageError(f"Expected key=value, got {pair!r}")
|
|
153
|
+
params[key] = value
|
|
154
|
+
return params
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@llm.hookimpl
|
|
158
|
+
def register_commands(cli):
|
|
159
|
+
@cli.command(name="scrapingrabbit")
|
|
160
|
+
@click.argument("endpoint", required=False)
|
|
161
|
+
@click.argument("pairs", nargs=-1)
|
|
162
|
+
def scrapingrabbit_command(endpoint: Optional[str], pairs: List[str]):
|
|
163
|
+
"""Call a ScrapingRabbit endpoint and print its JSON.
|
|
164
|
+
|
|
165
|
+
Run with no arguments to list endpoints. Example:
|
|
166
|
+
|
|
167
|
+
llm scrapingrabbit tiktok_profile_viewer username=nasa
|
|
168
|
+
"""
|
|
169
|
+
if not endpoint:
|
|
170
|
+
for e in ENDPOINTS:
|
|
171
|
+
params = " ".join(f"{p['name']}=" + ("..." if p["required"] else "[...]") for p in e["params"])
|
|
172
|
+
click.echo(f"{e['name']} {params}".rstrip())
|
|
173
|
+
return
|
|
174
|
+
if endpoint not in BY_NAME:
|
|
175
|
+
raise click.UsageError(f"Unknown endpoint {endpoint!r}. Run `llm scrapingrabbit` to list them.")
|
|
176
|
+
try:
|
|
177
|
+
data = call(endpoint, parse_pairs(list(pairs)))
|
|
178
|
+
except ScrapingRabbitPluginError as error:
|
|
179
|
+
raise click.ClickException(str(error))
|
|
180
|
+
click.echo(json.dumps(data, indent=2, ensure_ascii=False))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "llm-scrapingrabbit"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "ScrapingRabbit for LLM: load YouTube, TikTok and X transcripts as fragments, give models 31 web data tools (social profiles, Amazon and Walmart products, Google results, SEO data) and call any endpoint from the command line."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "ScrapingRabbit" }]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
keywords = ["llm", "llm-plugin", "fragments", "tools", "web-data", "youtube-transcript", "tiktok", "instagram", "amazon", "serp", "scrapingrabbit"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"llm>=0.26",
|
|
23
|
+
"scrapingrabbit>=0.2.0,<1.0.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
test = ["pytest", "llm-echo>=0.3"]
|
|
28
|
+
|
|
29
|
+
[project.entry-points.llm]
|
|
30
|
+
scrapingrabbit = "llm_scrapingrabbit"
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://scrapingrabbit.com"
|
|
34
|
+
Documentation = "https://github.com/scrapingrabbit/llm-scrapingrabbit#readme"
|
|
35
|
+
Repository = "https://github.com/scrapingrabbit/llm-scrapingrabbit"
|
|
36
|
+
Issues = "https://github.com/scrapingrabbit/llm-scrapingrabbit/issues"
|
|
37
|
+
"API reference" = "https://scrapingrabbit.com/docs"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["setuptools>=77"]
|
|
41
|
+
build-backend = "setuptools.build_meta"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
py-modules = ["llm_scrapingrabbit"]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Runs the plugin through LLM itself (fragments, tools via the echo model, the CLI command) against a local fake API."""
|
|
2
|
+
import functools
|
|
3
|
+
import json
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
7
|
+
from urllib.parse import parse_qs, urlparse
|
|
8
|
+
|
|
9
|
+
import llm
|
|
10
|
+
import pytest
|
|
11
|
+
from click.testing import CliRunner
|
|
12
|
+
from llm.cli import cli
|
|
13
|
+
from scrapingrabbit import ENDPOINTS, ScrapingRabbit
|
|
14
|
+
|
|
15
|
+
import llm_scrapingrabbit
|
|
16
|
+
|
|
17
|
+
REQUESTS = []
|
|
18
|
+
HOLD = {"seconds": 0.0}
|
|
19
|
+
YOUTUBE = {"videoId": "abc", "language": "en", "isAutoGenerated": True, "transcript": [{"text": "hello"}, {"text": "world"}]}
|
|
20
|
+
TIKTOK = {"videoId": "1", "author": "nasa", "language": "en", "isAutoGenerated": False, "transcript": [], "text": "liftoff"}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Handler(BaseHTTPRequestHandler):
|
|
24
|
+
def do_GET(self):
|
|
25
|
+
url = urlparse(self.path)
|
|
26
|
+
query = parse_qs(url.query)
|
|
27
|
+
REQUESTS.append({"path": url.path, "query": query, "key": self.headers.get("x-api-key")})
|
|
28
|
+
time.sleep(HOLD["seconds"])
|
|
29
|
+
if query.get("url") == ["nocaptions"]:
|
|
30
|
+
status, body = 404, {"success": False, "code": "UPSTREAM_NOT_FOUND", "message": "This video has no captions"}
|
|
31
|
+
elif url.path == "/v1/youtube/transcript":
|
|
32
|
+
status, body = 200, {"success": True, "data": YOUTUBE}
|
|
33
|
+
elif url.path == "/v1/tiktok/transcript":
|
|
34
|
+
status, body = 200, {"success": True, "data": TIKTOK}
|
|
35
|
+
elif url.path == "/v1/account/credits":
|
|
36
|
+
status, body = 200, {"success": True, "data": {"credits": 7}}
|
|
37
|
+
else:
|
|
38
|
+
status, body = 200, {"success": True, "data": {"path": url.path, "items": ["x" * 100] * 1000}}
|
|
39
|
+
payload = json.dumps(body).encode()
|
|
40
|
+
try:
|
|
41
|
+
self.send_response(status)
|
|
42
|
+
self.send_header("content-type", "application/json")
|
|
43
|
+
self.send_header("content-length", str(len(payload)))
|
|
44
|
+
self.end_headers()
|
|
45
|
+
self.wfile.write(payload)
|
|
46
|
+
except (BrokenPipeError, ConnectionResetError):
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
def log_message(self, *args):
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.fixture(scope="session")
|
|
54
|
+
def base_url():
|
|
55
|
+
server = HTTPServer(("127.0.0.1", 0), Handler)
|
|
56
|
+
threading.Thread(target=server.serve_forever, daemon=True).start()
|
|
57
|
+
yield f"http://127.0.0.1:{server.server_port}/v1"
|
|
58
|
+
server.shutdown()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.fixture(autouse=True)
|
|
62
|
+
def fake_api(base_url, monkeypatch, tmp_path):
|
|
63
|
+
REQUESTS.clear()
|
|
64
|
+
HOLD["seconds"] = 0.0
|
|
65
|
+
monkeypatch.setenv("LLM_USER_PATH", str(tmp_path)) # isolate llm keys and logs
|
|
66
|
+
monkeypatch.setenv("SCRAPINGRABBIT_API_KEY", "sr_live_testkey")
|
|
67
|
+
monkeypatch.setattr(llm_scrapingrabbit, "ScrapingRabbit", functools.partial(ScrapingRabbit, base_url=base_url, max_retries=0))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_registers_one_prefixed_tool_per_endpoint():
|
|
71
|
+
tools = llm.get_tools()
|
|
72
|
+
names = [llm_scrapingrabbit.TOOL_PREFIX + e["name"] for e in ENDPOINTS]
|
|
73
|
+
for name in names:
|
|
74
|
+
assert name in tools
|
|
75
|
+
schema = tools["scrapingrabbit_youtube_transcript"].input_schema
|
|
76
|
+
assert schema["required"] == ["url"] and schema["additionalProperties"] is False
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_registers_three_fragment_loaders():
|
|
80
|
+
loaders = llm.get_fragment_loaders()
|
|
81
|
+
assert {"sr-youtube", "sr-tiktok", "sr-x"} <= set(loaders)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_youtube_fragment_joins_segments_with_a_header():
|
|
85
|
+
fragment = llm.get_fragment_loaders()["sr-youtube"]("https://youtu.be/abc")
|
|
86
|
+
assert "hello world" in fragment
|
|
87
|
+
assert "Language: en (auto-generated)" in fragment
|
|
88
|
+
assert fragment.source == "https://youtu.be/abc"
|
|
89
|
+
assert REQUESTS[0]["key"] == "sr_live_testkey"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_tiktok_fragment_uses_the_text_field():
|
|
93
|
+
fragment = llm.get_fragment_loaders()["sr-tiktok"]("https://www.tiktok.com/@nasa/video/1")
|
|
94
|
+
assert "liftoff" in fragment and "Author: nasa" in fragment
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_fragment_refusal_explains_and_says_not_charged():
|
|
98
|
+
with pytest.raises(ValueError) as caught:
|
|
99
|
+
llm.get_fragment_loaders()["sr-youtube"]("nocaptions")
|
|
100
|
+
assert "UPSTREAM_NOT_FOUND: This video has no captions. Failed calls are not charged." in str(caught.value)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_missing_key_says_how_to_set_one(monkeypatch):
|
|
104
|
+
monkeypatch.delenv("SCRAPINGRABBIT_API_KEY")
|
|
105
|
+
with pytest.raises(ValueError) as caught:
|
|
106
|
+
llm.get_fragment_loaders()["sr-youtube"]("abc")
|
|
107
|
+
assert "llm keys set scrapingrabbit" in str(caught.value)
|
|
108
|
+
assert REQUESTS == []
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_client_timeout_does_not_claim_the_call_was_free(monkeypatch, base_url):
|
|
112
|
+
monkeypatch.setattr(llm_scrapingrabbit, "ScrapingRabbit", functools.partial(ScrapingRabbit, base_url=base_url, max_retries=0, timeout=0.2))
|
|
113
|
+
HOLD["seconds"] = 1.0
|
|
114
|
+
with pytest.raises(ValueError) as caught:
|
|
115
|
+
llm_scrapingrabbit.call("account_credits", {})
|
|
116
|
+
assert "not charged" not in str(caught.value)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_tool_rejects_unknown_and_missing_arguments_without_a_call():
|
|
120
|
+
run = llm.get_tools()["scrapingrabbit_youtube_transcript"].implementation
|
|
121
|
+
with pytest.raises(ValueError, match="Unknown argument"):
|
|
122
|
+
run(url="x", nope="1")
|
|
123
|
+
with pytest.raises(ValueError, match="Missing required"):
|
|
124
|
+
run()
|
|
125
|
+
assert REQUESTS == []
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_tool_output_is_capped_with_a_note():
|
|
129
|
+
out = llm.get_tools()["scrapingrabbit_amazon_best_sellers_viewer"].implementation(category_id=172282)
|
|
130
|
+
assert len(out) <= llm_scrapingrabbit.MAX_TOOL_CHARS
|
|
131
|
+
assert "[Cut: showing 60000 of" in out
|
|
132
|
+
assert REQUESTS[0]["query"]["category_id"] == ["172282"]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_tool_runs_inside_an_llm_chain_with_the_echo_model():
|
|
136
|
+
model = llm.get_model("echo")
|
|
137
|
+
prompt = json.dumps({"prompt": "credits?", "tool_calls": [{"name": "scrapingrabbit_account_credits", "arguments": {}}]})
|
|
138
|
+
chain = model.chain(prompt, tools=[llm.get_tools()["scrapingrabbit_account_credits"]])
|
|
139
|
+
text = chain.text()
|
|
140
|
+
assert '{\\"credits\\": 7}' in text or '{"credits": 7}' in text
|
|
141
|
+
assert REQUESTS[0]["path"] == "/v1/account/credits"
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_tool_refusal_reaches_the_model_as_an_error_result():
|
|
145
|
+
model = llm.get_model("echo")
|
|
146
|
+
prompt = json.dumps({"prompt": "go", "tool_calls": [{"name": "scrapingrabbit_youtube_transcript", "arguments": {"url": "nocaptions"}}]})
|
|
147
|
+
text = model.chain(prompt, tools=[llm.get_tools()["scrapingrabbit_youtube_transcript"]]).text()
|
|
148
|
+
assert "UPSTREAM_NOT_FOUND" in text and "not charged" in text
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_cli_fragment_through_llm_prompt():
|
|
152
|
+
result = CliRunner().invoke(cli, ["-m", "echo", "-f", "sr-youtube:https://youtu.be/abc", "summarize", "--no-log"])
|
|
153
|
+
assert result.exit_code == 0, result.output
|
|
154
|
+
assert "hello world" in result.output
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_command_lists_endpoints_and_calls_one():
|
|
158
|
+
runner = CliRunner()
|
|
159
|
+
listing = runner.invoke(cli, ["scrapingrabbit"])
|
|
160
|
+
assert listing.exit_code == 0 and "youtube_transcript url=..." in listing.output
|
|
161
|
+
result = runner.invoke(cli, ["scrapingrabbit", "account_credits"])
|
|
162
|
+
assert result.exit_code == 0, result.output
|
|
163
|
+
assert json.loads(result.output) == {"credits": 7}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_command_errors_are_clean():
|
|
167
|
+
runner = CliRunner()
|
|
168
|
+
assert "Unknown endpoint" in runner.invoke(cli, ["scrapingrabbit", "nope"]).output
|
|
169
|
+
assert "Expected key=value" in runner.invoke(cli, ["scrapingrabbit", "youtube_transcript", "oops"]).output
|
|
170
|
+
refused = runner.invoke(cli, ["scrapingrabbit", "youtube_transcript", "url=nocaptions"])
|
|
171
|
+
assert refused.exit_code == 1 and "UPSTREAM_NOT_FOUND" in refused.output
|