langchain-huntapi 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_huntapi/__init__.py +29 -0
- langchain_huntapi/_client.py +202 -0
- langchain_huntapi/py.typed +1 -0
- langchain_huntapi/tools.py +182 -0
- langchain_huntapi-0.1.0.dist-info/METADATA +83 -0
- langchain_huntapi-0.1.0.dist-info/RECORD +8 -0
- langchain_huntapi-0.1.0.dist-info/WHEEL +4 -0
- langchain_huntapi-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""LangChain integration for HuntAPI."""
|
|
2
|
+
|
|
3
|
+
from importlib import metadata
|
|
4
|
+
|
|
5
|
+
from langchain_huntapi._client import HuntAPIError
|
|
6
|
+
from langchain_huntapi.tools import (
|
|
7
|
+
HuntAPIAudioDownload,
|
|
8
|
+
HuntAPIAudioDownloadInput,
|
|
9
|
+
HuntAPIMediaMetadata,
|
|
10
|
+
HuntAPIMediaMetadataInput,
|
|
11
|
+
HuntAPIVideoDownload,
|
|
12
|
+
HuntAPIVideoDownloadInput,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
__version__ = metadata.version(__package__)
|
|
17
|
+
except metadata.PackageNotFoundError:
|
|
18
|
+
__version__ = ""
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"HuntAPIAudioDownload",
|
|
22
|
+
"HuntAPIAudioDownloadInput",
|
|
23
|
+
"HuntAPIError",
|
|
24
|
+
"HuntAPIMediaMetadata",
|
|
25
|
+
"HuntAPIMediaMetadataInput",
|
|
26
|
+
"HuntAPIVideoDownload",
|
|
27
|
+
"HuntAPIVideoDownloadInput",
|
|
28
|
+
"__version__",
|
|
29
|
+
]
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""HTTP client for the HuntAPI API (https://www.huntapi.com)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import time
|
|
8
|
+
from typing import Any
|
|
9
|
+
from urllib.parse import quote
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
|
|
13
|
+
DEFAULT_BASE_URL = "https://api.huntapi.com"
|
|
14
|
+
DEFAULT_TIMEOUT = 60.0
|
|
15
|
+
USER_AGENT = "langchain-huntapi"
|
|
16
|
+
ENV = "HUNTAPI_API_KEY"
|
|
17
|
+
|
|
18
|
+
_ERROR_DETAIL_LIMIT = 300
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class HuntAPIError(Exception):
|
|
22
|
+
"""A HuntAPI request failed. The message never contains the API key."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, message: str, status_code: int | None = None) -> None:
|
|
25
|
+
super().__init__(message)
|
|
26
|
+
self.status_code = status_code
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def resolve_api_key(value: str | None) -> str:
|
|
30
|
+
"""Return ``value`` or ``HUNTAPI_API_KEY``, stripped. Raises if neither is set."""
|
|
31
|
+
key = (value or os.environ.get(ENV) or "").strip()
|
|
32
|
+
if not key:
|
|
33
|
+
raise HuntAPIError(f"Set {ENV} or pass api_key. Get a key at https://app.huntapi.com")
|
|
34
|
+
return key
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def required(value: Any, name: str) -> str:
|
|
38
|
+
"""Return ``value`` stripped, or raise if it is empty."""
|
|
39
|
+
text = str(value or "").strip()
|
|
40
|
+
if not text:
|
|
41
|
+
raise HuntAPIError(f"{name} is empty.")
|
|
42
|
+
return text
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def clean(values: dict[str, Any]) -> dict[str, Any]:
|
|
46
|
+
"""Drop unset values; send booleans as true/false."""
|
|
47
|
+
out: dict[str, Any] = {}
|
|
48
|
+
for key, value in values.items():
|
|
49
|
+
if value is None or value == "":
|
|
50
|
+
continue
|
|
51
|
+
out[key] = ("true" if value else "false") if isinstance(value, bool) else value
|
|
52
|
+
return out
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _redact(text: str, api_key: str) -> str:
|
|
56
|
+
return text.replace(api_key, "***") if api_key else text
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _error(response: httpx.Response, api_key: str) -> HuntAPIError:
|
|
60
|
+
detail = ""
|
|
61
|
+
try:
|
|
62
|
+
body = response.json()
|
|
63
|
+
except ValueError:
|
|
64
|
+
detail = response.text.strip()
|
|
65
|
+
else:
|
|
66
|
+
if isinstance(body, dict):
|
|
67
|
+
error = body.get("error") or body.get("message") or ""
|
|
68
|
+
if isinstance(error, dict):
|
|
69
|
+
error = error.get("message") or ""
|
|
70
|
+
detail = str(error)
|
|
71
|
+
detail = _redact(detail, api_key)[:_ERROR_DETAIL_LIMIT]
|
|
72
|
+
status = response.status_code
|
|
73
|
+
# HuntAPI answers a rate limit with HTTP 401 and a "Rate limit exceeded" message.
|
|
74
|
+
if status == 429 or (status == 401 and "rate limit" in detail.lower()):
|
|
75
|
+
label = "HuntAPI rate limit exceeded"
|
|
76
|
+
elif status == 401:
|
|
77
|
+
label = "HuntAPI rejected the API key"
|
|
78
|
+
elif status == 402:
|
|
79
|
+
label = "HuntAPI account is out of credits"
|
|
80
|
+
else:
|
|
81
|
+
label = "HuntAPI API error"
|
|
82
|
+
return HuntAPIError(f"{label} (HTTP {status})" + (f": {detail}" if detail else ""), status)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _headers(api_key: str) -> dict[str, str]:
|
|
86
|
+
headers = {"Accept": "application/json", "User-Agent": USER_AGENT}
|
|
87
|
+
headers["x-api-key"] = api_key
|
|
88
|
+
return headers
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _decode(response: httpx.Response, api_key: str) -> Any:
|
|
92
|
+
if not response.is_success:
|
|
93
|
+
raise _error(response, api_key)
|
|
94
|
+
try:
|
|
95
|
+
return response.json()
|
|
96
|
+
except ValueError as exc:
|
|
97
|
+
raise HuntAPIError("HuntAPI returned a response that is not JSON.") from exc
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def request(
|
|
101
|
+
method: str,
|
|
102
|
+
path: str,
|
|
103
|
+
*,
|
|
104
|
+
params: dict[str, Any] | None = None,
|
|
105
|
+
json: dict[str, Any] | None = None,
|
|
106
|
+
api_key: str,
|
|
107
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
108
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
109
|
+
) -> Any:
|
|
110
|
+
"""Call ``path`` and return the decoded JSON body."""
|
|
111
|
+
try:
|
|
112
|
+
with httpx.Client(timeout=timeout) as client:
|
|
113
|
+
response = client.request(
|
|
114
|
+
method, f"{base_url.rstrip('/')}{path}", params=params, json=json, headers=_headers(api_key)
|
|
115
|
+
)
|
|
116
|
+
except httpx.TimeoutException as exc:
|
|
117
|
+
raise HuntAPIError(f"HuntAPI did not answer within {timeout:g} seconds.") from exc
|
|
118
|
+
except httpx.HTTPError as exc:
|
|
119
|
+
raise HuntAPIError(f"Could not reach HuntAPI: {_redact(str(exc), api_key)}") from exc
|
|
120
|
+
return _decode(response, api_key)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
async def arequest(
|
|
124
|
+
method: str,
|
|
125
|
+
path: str,
|
|
126
|
+
*,
|
|
127
|
+
params: dict[str, Any] | None = None,
|
|
128
|
+
json: dict[str, Any] | None = None,
|
|
129
|
+
api_key: str,
|
|
130
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
131
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
132
|
+
) -> Any:
|
|
133
|
+
"""Async version of :func:`request`."""
|
|
134
|
+
try:
|
|
135
|
+
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
136
|
+
response = await client.request(
|
|
137
|
+
method, f"{base_url.rstrip('/')}{path}", params=params, json=json, headers=_headers(api_key)
|
|
138
|
+
)
|
|
139
|
+
except httpx.TimeoutException as exc:
|
|
140
|
+
raise HuntAPIError(f"HuntAPI did not answer within {timeout:g} seconds.") from exc
|
|
141
|
+
except httpx.HTTPError as exc:
|
|
142
|
+
raise HuntAPIError(f"Could not reach HuntAPI: {_redact(str(exc), api_key)}") from exc
|
|
143
|
+
return _decode(response, api_key)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
JOB_WAIT = 140.0
|
|
147
|
+
POLL_EVERY = 3.0
|
|
148
|
+
_FAILED = ("Error", "NotFound", "BadRequest")
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _job_result(job_id: str, job: Any) -> dict[str, Any]:
|
|
152
|
+
job = job if isinstance(job, dict) else {}
|
|
153
|
+
result = job.get("result") if isinstance(job.get("result"), dict) else {}
|
|
154
|
+
metadata = result.get("metadata") if isinstance(result.get("metadata"), dict) else {}
|
|
155
|
+
status = job.get("status")
|
|
156
|
+
out: dict[str, Any] = {"job_id": job_id, "status": status, "progress": job.get("progress")}
|
|
157
|
+
if status == "CompletedJob":
|
|
158
|
+
out["download_url"] = result.get("response")
|
|
159
|
+
out["title"] = metadata.get("title")
|
|
160
|
+
elif status in _FAILED:
|
|
161
|
+
out["error"] = job.get("error") or "private, deleted, age-restricted or unsupported content"
|
|
162
|
+
else:
|
|
163
|
+
out["note"] = "Still running: check it later with the job id."
|
|
164
|
+
return out
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _job_id(start: Any) -> str:
|
|
168
|
+
job_id = start.get("job_id") if isinstance(start, dict) else None
|
|
169
|
+
if not isinstance(job_id, str) or not job_id:
|
|
170
|
+
raise HuntAPIError("HuntAPI did not return a job id.")
|
|
171
|
+
return job_id
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def download(
|
|
175
|
+
path: str, params: dict[str, Any], *, api_key: str, base_url: str, timeout: float, wait: float = JOB_WAIT
|
|
176
|
+
) -> dict[str, Any]:
|
|
177
|
+
"""Start a download job and wait up to ``wait`` seconds for its link."""
|
|
178
|
+
job_id = _job_id(request("GET", path, params=params, api_key=api_key, base_url=base_url, timeout=timeout))
|
|
179
|
+
deadline = time.monotonic() + wait
|
|
180
|
+
while True:
|
|
181
|
+
job = request("GET", f"/v1/jobs/{quote(job_id, safe='')}", api_key=api_key, base_url=base_url, timeout=timeout)
|
|
182
|
+
status = job.get("status") if isinstance(job, dict) else None
|
|
183
|
+
if status == "CompletedJob" or status in _FAILED or time.monotonic() >= deadline:
|
|
184
|
+
return _job_result(job_id, job)
|
|
185
|
+
time.sleep(POLL_EVERY)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
async def adownload(
|
|
189
|
+
path: str, params: dict[str, Any], *, api_key: str, base_url: str, timeout: float, wait: float = JOB_WAIT
|
|
190
|
+
) -> dict[str, Any]:
|
|
191
|
+
"""Async version of :func:`download`."""
|
|
192
|
+
start = await arequest("GET", path, params=params, api_key=api_key, base_url=base_url, timeout=timeout)
|
|
193
|
+
job_id = _job_id(start)
|
|
194
|
+
deadline = time.monotonic() + wait
|
|
195
|
+
while True:
|
|
196
|
+
job = await arequest(
|
|
197
|
+
"GET", f"/v1/jobs/{quote(job_id, safe='')}", api_key=api_key, base_url=base_url, timeout=timeout
|
|
198
|
+
)
|
|
199
|
+
status = job.get("status") if isinstance(job, dict) else None
|
|
200
|
+
if status == "CompletedJob" or status in _FAILED or time.monotonic() >= deadline:
|
|
201
|
+
return _job_result(job_id, job)
|
|
202
|
+
await asyncio.sleep(POLL_EVERY)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""HuntAPI tools for LangChain agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Literal
|
|
6
|
+
|
|
7
|
+
from langchain_core.callbacks import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun
|
|
8
|
+
from langchain_core.tools import BaseTool, ToolException
|
|
9
|
+
from pydantic import BaseModel, Field, SecretStr
|
|
10
|
+
|
|
11
|
+
from langchain_huntapi import _client
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _HuntAPITool(BaseTool):
|
|
15
|
+
"""Shared settings and request handling for the HuntAPI tools."""
|
|
16
|
+
|
|
17
|
+
handle_tool_error: bool = True
|
|
18
|
+
api_key: SecretStr | None = Field(default=None, description="HuntAPI API key. Defaults to HUNTAPI_API_KEY.")
|
|
19
|
+
base_url: str = _client.DEFAULT_BASE_URL
|
|
20
|
+
timeout: float = _client.DEFAULT_TIMEOUT
|
|
21
|
+
|
|
22
|
+
def _key(self) -> str:
|
|
23
|
+
return _client.resolve_api_key(self.api_key.get_secret_value() if self.api_key else None)
|
|
24
|
+
|
|
25
|
+
def _output(self, data: Any) -> Any:
|
|
26
|
+
return data
|
|
27
|
+
|
|
28
|
+
def _send(self, method: str, path: str, params: dict[str, Any] | None, body: dict[str, Any] | None) -> Any:
|
|
29
|
+
if method == "DOWNLOAD":
|
|
30
|
+
return _client.download(
|
|
31
|
+
path, _client.clean(params or {}), api_key=self._key(), base_url=self.base_url, timeout=self.timeout
|
|
32
|
+
)
|
|
33
|
+
return _client.request(
|
|
34
|
+
method,
|
|
35
|
+
path,
|
|
36
|
+
params=_client.clean(params) if params else None,
|
|
37
|
+
json=body,
|
|
38
|
+
api_key=self._key(),
|
|
39
|
+
base_url=self.base_url,
|
|
40
|
+
timeout=self.timeout,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
async def _asend(self, method: str, path: str, params: dict[str, Any] | None, body: dict[str, Any] | None) -> Any:
|
|
44
|
+
if method == "DOWNLOAD":
|
|
45
|
+
return await _client.adownload(
|
|
46
|
+
path, _client.clean(params or {}), api_key=self._key(), base_url=self.base_url, timeout=self.timeout
|
|
47
|
+
)
|
|
48
|
+
return await _client.arequest(
|
|
49
|
+
method,
|
|
50
|
+
path,
|
|
51
|
+
params=_client.clean(params) if params else None,
|
|
52
|
+
json=body,
|
|
53
|
+
api_key=self._key(),
|
|
54
|
+
base_url=self.base_url,
|
|
55
|
+
timeout=self.timeout,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class HuntAPIMediaMetadataInput(BaseModel):
|
|
60
|
+
"""Arguments the model can set."""
|
|
61
|
+
|
|
62
|
+
url: str = Field(default=..., description="The public video or audio URL.")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class HuntAPIMediaMetadata(_HuntAPITool):
|
|
66
|
+
"""Read the metadata of a public video through HuntAPI.
|
|
67
|
+
|
|
68
|
+
Setup:
|
|
69
|
+
.. code-block:: bash
|
|
70
|
+
|
|
71
|
+
pip install -U langchain-huntapi
|
|
72
|
+
export HUNTAPI_API_KEY="your-api-key"
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
name: str = "huntapi_media_metadata"
|
|
76
|
+
description: str = "Get the metadata of a public video or audio URL (YouTube, TikTok, Instagram, Vimeo, X, Reddit and more) without downloading it: title, channel, duration, views, likes, upload date and thumbnail. Input is the URL."
|
|
77
|
+
args_schema: type[BaseModel] = HuntAPIMediaMetadataInput
|
|
78
|
+
|
|
79
|
+
def _request(self, url: str) -> tuple[str, str, dict[str, Any] | None, dict[str, Any] | None]:
|
|
80
|
+
return "GET", "/v1/media/metadata", {"query": _client.required(url, "url")}, None
|
|
81
|
+
|
|
82
|
+
def _run(self, url: str, run_manager: CallbackManagerForToolRun | None = None) -> Any:
|
|
83
|
+
try:
|
|
84
|
+
return self._output(self._send(*self._request(url)))
|
|
85
|
+
except _client.HuntAPIError as exc:
|
|
86
|
+
raise ToolException(str(exc)) from exc
|
|
87
|
+
|
|
88
|
+
async def _arun(self, url: str, run_manager: AsyncCallbackManagerForToolRun | None = None) -> Any:
|
|
89
|
+
try:
|
|
90
|
+
return self._output(await self._asend(*self._request(url)))
|
|
91
|
+
except _client.HuntAPIError as exc:
|
|
92
|
+
raise ToolException(str(exc)) from exc
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class HuntAPIVideoDownloadInput(BaseModel):
|
|
96
|
+
"""Arguments the model can set."""
|
|
97
|
+
|
|
98
|
+
url: str = Field(default=..., description="The public video URL.")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class HuntAPIVideoDownload(_HuntAPITool):
|
|
102
|
+
"""Download a public video through HuntAPI and return the download link.
|
|
103
|
+
|
|
104
|
+
Setup:
|
|
105
|
+
.. code-block:: bash
|
|
106
|
+
|
|
107
|
+
pip install -U langchain-huntapi
|
|
108
|
+
export HUNTAPI_API_KEY="your-api-key"
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
name: str = "huntapi_video_download"
|
|
112
|
+
description: str = "Download a public video (YouTube, TikTok, Instagram, Vimeo, X, Reddit and more) and get a download link. Waits up to 140 seconds; a longer job returns its job id. Input is the URL."
|
|
113
|
+
args_schema: type[BaseModel] = HuntAPIVideoDownloadInput
|
|
114
|
+
quality: Literal["best", "1080p", "720p", "480p", "360p"] = "best"
|
|
115
|
+
"""Video quality."""
|
|
116
|
+
video_format: Literal["mp4", "webm", "mkv"] = "mp4"
|
|
117
|
+
"""Output format."""
|
|
118
|
+
|
|
119
|
+
def _request(self, url: str) -> tuple[str, str, dict[str, Any] | None, dict[str, Any] | None]:
|
|
120
|
+
return (
|
|
121
|
+
"DOWNLOAD",
|
|
122
|
+
"/v1/video/download",
|
|
123
|
+
{"query": _client.required(url, "url"), "video_quality": self.quality, "video_format": self.video_format},
|
|
124
|
+
None,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def _run(self, url: str, run_manager: CallbackManagerForToolRun | None = None) -> Any:
|
|
128
|
+
try:
|
|
129
|
+
return self._output(self._send(*self._request(url)))
|
|
130
|
+
except _client.HuntAPIError as exc:
|
|
131
|
+
raise ToolException(str(exc)) from exc
|
|
132
|
+
|
|
133
|
+
async def _arun(self, url: str, run_manager: AsyncCallbackManagerForToolRun | None = None) -> Any:
|
|
134
|
+
try:
|
|
135
|
+
return self._output(await self._asend(*self._request(url)))
|
|
136
|
+
except _client.HuntAPIError as exc:
|
|
137
|
+
raise ToolException(str(exc)) from exc
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class HuntAPIAudioDownloadInput(BaseModel):
|
|
141
|
+
"""Arguments the model can set."""
|
|
142
|
+
|
|
143
|
+
url: str = Field(default=..., description="The public video or audio URL.")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class HuntAPIAudioDownload(_HuntAPITool):
|
|
147
|
+
"""Extract the audio of a public video through HuntAPI and return the download link.
|
|
148
|
+
|
|
149
|
+
Setup:
|
|
150
|
+
.. code-block:: bash
|
|
151
|
+
|
|
152
|
+
pip install -U langchain-huntapi
|
|
153
|
+
export HUNTAPI_API_KEY="your-api-key"
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
name: str = "huntapi_audio_download"
|
|
157
|
+
description: str = "Extract the audio of a public video or audio URL (a podcast, a talk, a song) and get a download link. Waits up to 140 seconds; a longer job returns its job id. Input is the URL."
|
|
158
|
+
args_schema: type[BaseModel] = HuntAPIAudioDownloadInput
|
|
159
|
+
audio_format: Literal["mp3", "m4a", "wav"] = "mp3"
|
|
160
|
+
"""Output format."""
|
|
161
|
+
quality: Literal["best", "320kbps", "256kbps", "128kbps"] = "best"
|
|
162
|
+
"""Audio quality."""
|
|
163
|
+
|
|
164
|
+
def _request(self, url: str) -> tuple[str, str, dict[str, Any] | None, dict[str, Any] | None]:
|
|
165
|
+
return (
|
|
166
|
+
"DOWNLOAD",
|
|
167
|
+
"/v1/audio/download",
|
|
168
|
+
{"query": _client.required(url, "url"), "audio_format": self.audio_format, "audio_quality": self.quality},
|
|
169
|
+
None,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def _run(self, url: str, run_manager: CallbackManagerForToolRun | None = None) -> Any:
|
|
173
|
+
try:
|
|
174
|
+
return self._output(self._send(*self._request(url)))
|
|
175
|
+
except _client.HuntAPIError as exc:
|
|
176
|
+
raise ToolException(str(exc)) from exc
|
|
177
|
+
|
|
178
|
+
async def _arun(self, url: str, run_manager: AsyncCallbackManagerForToolRun | None = None) -> Any:
|
|
179
|
+
try:
|
|
180
|
+
return self._output(await self._asend(*self._request(url)))
|
|
181
|
+
except _client.HuntAPIError as exc:
|
|
182
|
+
raise ToolException(str(exc)) from exc
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-huntapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for HuntAPI: read the metadata of public videos and download them as video or audio.
|
|
5
|
+
Project-URL: Homepage, https://www.huntapi.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/huntapi/langchain-huntapi#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/huntapi/langchain-huntapi
|
|
8
|
+
Project-URL: Issues, https://github.com/huntapi/langchain-huntapi/issues
|
|
9
|
+
Author-email: HuntAPI <contact@huntapi.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,audio,download,huntapi,langchain,media,tiktok,tools,video,youtube
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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 :: Internet :: WWW/HTTP
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx<1,>=0.27
|
|
24
|
+
Requires-Dist: langchain-core<2,>=0.3.15
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: langchain-tests>=0.3.5; extra == 'test'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
|
|
28
|
+
Requires-Dist: pytest>=8.3; extra == 'test'
|
|
29
|
+
Requires-Dist: ruff<1,>=0.8; extra == 'test'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# langchain-huntapi
|
|
33
|
+
|
|
34
|
+
[LangChain](https://www.langchain.com) integration for [HuntAPI](https://www.huntapi.com): read the metadata of public videos and download them as video or audio.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -U langchain-huntapi
|
|
40
|
+
export HUNTAPI_API_KEY="your-api-key"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Get an API key at [app.huntapi.com](https://app.huntapi.com).
|
|
44
|
+
|
|
45
|
+
## Tools
|
|
46
|
+
|
|
47
|
+
| Class | Tool name | What it does |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `HuntAPIMediaMetadata` | `huntapi_media_metadata` | Read the metadata of a public video through HuntAPI. |
|
|
50
|
+
| `HuntAPIVideoDownload` | `huntapi_video_download` | Download a public video through HuntAPI and return the download link. |
|
|
51
|
+
| `HuntAPIAudioDownload` | `huntapi_audio_download` | Extract the audio of a public video through HuntAPI and return the download link. |
|
|
52
|
+
|
|
53
|
+
Each tool takes `api_key` (defaults to `HUNTAPI_API_KEY`), `base_url` and `timeout`, plus the settings shown in its docstring. Errors (invalid key, no credits, rate limit, timeout) come back to the model as a `ToolException` message, without the API key. Every tool has an async version.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from langchain_huntapi import HuntAPIMediaMetadata
|
|
57
|
+
|
|
58
|
+
tool = HuntAPIMediaMetadata()
|
|
59
|
+
print(tool.invoke({"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw"}))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### In an agent
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from langchain.agents import create_agent
|
|
66
|
+
from langchain_huntapi import HuntAPIMediaMetadata, HuntAPIVideoDownload, HuntAPIAudioDownload
|
|
67
|
+
|
|
68
|
+
agent = create_agent(
|
|
69
|
+
"openai:gpt-4.1-mini", tools=[HuntAPIMediaMetadata(), HuntAPIVideoDownload(), HuntAPIAudioDownload()]
|
|
70
|
+
)
|
|
71
|
+
result = agent.invoke({"messages": [{"role": "user", "content": "..."}]})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Development
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install -e ".[test]"
|
|
78
|
+
pytest tests/unit_tests
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
langchain_huntapi/__init__.py,sha256=suYjahrKDKYswJ8JzhT_nxllrmv5b-hPlxZ23bP1qVk,686
|
|
2
|
+
langchain_huntapi/_client.py,sha256=oggZHei_uQgIN16F9avYMYmWqrroQ5WBaFGhX227Hj8,7351
|
|
3
|
+
langchain_huntapi/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
langchain_huntapi/tools.py,sha256=JSr-NBym6kd0ZX00UsBuaj2sYbVFZ_DBqU7peuv7tq4,7138
|
|
5
|
+
langchain_huntapi-0.1.0.dist-info/METADATA,sha256=pYhD-piA7C6dTpu5XLXs4FOLULW1nQdWiCh_VmMgO5A,3108
|
|
6
|
+
langchain_huntapi-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
7
|
+
langchain_huntapi-0.1.0.dist-info/licenses/LICENSE,sha256=wibVsWX7Iv5xC9QvrpexnA4dKpf9SgGeKIdEuU-cl4A,1064
|
|
8
|
+
langchain_huntapi-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HuntAPI
|
|
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.
|