langchain-moneytools 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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MoneyTools
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-moneytools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for MoneyTools: pay-per-file speech-to-text (Transcripts, 0.005 USDC/min) and x402 spend controls (Settle), paid with x402 USDC on Base. No API keys.
|
|
5
|
+
Project-URL: Homepage, https://speech.moneytools.dev
|
|
6
|
+
Project-URL: Documentation, https://speech.moneytools.dev/docs/migrate-from-dtelecom
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: agents,base,langchain,speech-to-text,transcription,usdc,x402
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: langchain-core>=0.3
|
|
12
|
+
Requires-Dist: moneytools-transcripts>=0.1.0
|
|
13
|
+
Requires-Dist: pydantic>=2
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# langchain-moneytools
|
|
17
|
+
|
|
18
|
+
LangChain tools for MoneyTools, paid per use with x402 USDC on Base (no API key, no account, no prepaid credits).
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install langchain-moneytools
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from eth_account import Account
|
|
26
|
+
from langchain_moneytools import MoneyToolsToolkit
|
|
27
|
+
|
|
28
|
+
tools = MoneyToolsToolkit.from_account(Account.from_key(KEY), max_usd_per_request=0.5).get_tools()
|
|
29
|
+
# moneytools_transcribe_audio (0.005 USDC/min), moneytools_get_transcription (free),
|
|
30
|
+
# moneytools_spend_check (0.002 USDC), moneytools_verify_payment (0.003 USDC)
|
|
31
|
+
|
|
32
|
+
from langchain.agents import create_agent
|
|
33
|
+
agent = create_agent("openai:gpt-5-mini", tools)
|
|
34
|
+
agent.invoke({"messages": [{"role": "user", "content": "Transcribe https://example.com/standup.mp3 and list action items"}]})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Payments above `max_usd_per_request` are refused before signing. The key stays in your process.
|
|
38
|
+
|
|
39
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# langchain-moneytools
|
|
2
|
+
|
|
3
|
+
LangChain tools for MoneyTools, paid per use with x402 USDC on Base (no API key, no account, no prepaid credits).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install langchain-moneytools
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from eth_account import Account
|
|
11
|
+
from langchain_moneytools import MoneyToolsToolkit
|
|
12
|
+
|
|
13
|
+
tools = MoneyToolsToolkit.from_account(Account.from_key(KEY), max_usd_per_request=0.5).get_tools()
|
|
14
|
+
# moneytools_transcribe_audio (0.005 USDC/min), moneytools_get_transcription (free),
|
|
15
|
+
# moneytools_spend_check (0.002 USDC), moneytools_verify_payment (0.003 USDC)
|
|
16
|
+
|
|
17
|
+
from langchain.agents import create_agent
|
|
18
|
+
agent = create_agent("openai:gpt-5-mini", tools)
|
|
19
|
+
agent.invoke({"messages": [{"role": "user", "content": "Transcribe https://example.com/standup.mp3 and list action items"}]})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Payments above `max_usd_per_request` are refused before signing. The key stays in your process.
|
|
23
|
+
|
|
24
|
+
MIT
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""LangChain tools for MoneyTools Transcripts (speech-to-text) and Settle (x402 spend controls).
|
|
2
|
+
|
|
3
|
+
Every call is paid with x402 USDC on Base by the given eth_account LocalAccount; payments above
|
|
4
|
+
``max_usd_per_request`` are refused before signing. The key never leaves the process.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import time
|
|
9
|
+
from typing import Any, List, Literal, Optional, Type
|
|
10
|
+
|
|
11
|
+
from langchain_core.tools import BaseTool, BaseToolkit
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
13
|
+
|
|
14
|
+
from moneytools_transcripts import SETTLE_URL, TRANSCRIPTS_URL, SettleClient, TranscriptsClient, TranscriptsError
|
|
15
|
+
|
|
16
|
+
__all__ = ["MoneyToolsToolkit", "TranscribeAudioTool", "GetTranscriptionTool", "SpendCheckTool", "VerifyPaymentTool"]
|
|
17
|
+
_DONE = ("completed", "failed")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _Base(BaseTool):
|
|
21
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
22
|
+
transcripts: Any = None
|
|
23
|
+
settle: Any = None
|
|
24
|
+
payer: str = ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TranscribeAudioInput(BaseModel):
|
|
28
|
+
url: str = Field(description="Public https URL of an audio/video file (mp3, wav, m4a, ogg, webm, flac, mp4); up to 3 hours")
|
|
29
|
+
language: Optional[str] = Field(default=None, description="ISO-639-1 code like 'en'; omit to auto-detect")
|
|
30
|
+
summary: bool = Field(default=False, description="Also return a short summary")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TranscribeAudioTool(_Base):
|
|
34
|
+
name: str = "moneytools_transcribe_audio"
|
|
35
|
+
description: str = ("Transcribe speech in a public audio/video URL. Costs 0.005 USDC per started minute, paid automatically via x402 on Base. "
|
|
36
|
+
"Returns text, language and timestamped segments, or a job_id to check later with moneytools_get_transcription.")
|
|
37
|
+
args_schema: Type[BaseModel] = TranscribeAudioInput
|
|
38
|
+
max_wait_seconds: int = 120
|
|
39
|
+
poll_seconds: float = 3.0
|
|
40
|
+
|
|
41
|
+
def _run(self, url: str, language: Optional[str] = None, summary: bool = False, run_manager: Any = None) -> dict:
|
|
42
|
+
try:
|
|
43
|
+
job = self.transcripts.transcribe_url(url, language=language, summary=summary)
|
|
44
|
+
cur, end = job, time.time() + self.max_wait_seconds
|
|
45
|
+
while cur.get("status") not in _DONE:
|
|
46
|
+
cur = self.transcripts.get_file_transcription(job["id"])
|
|
47
|
+
if cur.get("status") in _DONE or time.time() >= end:
|
|
48
|
+
break
|
|
49
|
+
time.sleep(self.poll_seconds)
|
|
50
|
+
res = cur.get("result") or {}
|
|
51
|
+
return {"job_id": job["id"], "status": cur.get("status"), "duration_seconds": cur.get("duration_seconds", job.get("duration_seconds")),
|
|
52
|
+
"paid_usd": (job.get("payment") or {}).get("amountUsd"), "text": res.get("text"), "language": res.get("language"),
|
|
53
|
+
"segments": (res.get("segments") or [])[:200], "error": cur.get("error")}
|
|
54
|
+
except Exception as e: # surfaced to the model as a tool result
|
|
55
|
+
return {"error": str(e), "status": getattr(e, "status", None)}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class GetTranscriptionInput(BaseModel):
|
|
59
|
+
job_id: str = Field(description="job_… id returned by moneytools_transcribe_audio")
|
|
60
|
+
format: Literal["json", "srt", "vtt", "txt"] = Field(default="json", description="json, or srt/vtt subtitles, or plain txt")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class GetTranscriptionTool(_Base):
|
|
64
|
+
name: str = "moneytools_get_transcription"
|
|
65
|
+
description: str = "Get the status/result of a MoneyTools transcription job (free; only the paying wallet can read it)."
|
|
66
|
+
args_schema: Type[BaseModel] = GetTranscriptionInput
|
|
67
|
+
|
|
68
|
+
def _run(self, job_id: str, format: str = "json", run_manager: Any = None) -> Any:
|
|
69
|
+
try:
|
|
70
|
+
if format != "json":
|
|
71
|
+
return {"job_id": job_id, "format": format, "content": self.transcripts.get_file_transcription_text(job_id, format)}
|
|
72
|
+
return self.transcripts.get_file_transcription(job_id)
|
|
73
|
+
except Exception as e:
|
|
74
|
+
return {"error": str(e), "status": getattr(e, "status", None)}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class SpendCheckInput(BaseModel):
|
|
78
|
+
amount_usd: str = Field(description="Amount about to be paid in USD, e.g. '0.25'")
|
|
79
|
+
host: str = Field(description="Host asking for the payment, e.g. 'api.example.com'")
|
|
80
|
+
pay_to: Optional[str] = Field(default=None, description="Recipient address from the 402, if known")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class SpendCheckTool(_Base):
|
|
84
|
+
name: str = "moneytools_spend_check"
|
|
85
|
+
description: str = ("Before paying an x402 402, check the amount and host against this wallet's spend caps (per call / per day / allowed hosts). "
|
|
86
|
+
"Costs 0.002 USDC. Returns decision allow|deny with reasons.")
|
|
87
|
+
args_schema: Type[BaseModel] = SpendCheckInput
|
|
88
|
+
|
|
89
|
+
def _run(self, amount_usd: str, host: str, pay_to: Optional[str] = None, run_manager: Any = None) -> Any:
|
|
90
|
+
try:
|
|
91
|
+
return self.settle.spend_check(payer=self.payer, amount_usd=amount_usd, host=host, pay_to=pay_to)
|
|
92
|
+
except Exception as e:
|
|
93
|
+
return {"error": str(e), "status": getattr(e, "status", None)}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class VerifyPaymentInput(BaseModel):
|
|
97
|
+
tx: Optional[str] = Field(default=None, description="Base transaction hash of an x402 USDC payment")
|
|
98
|
+
nonce: Optional[str] = Field(default=None, description="EIP-3009 authorization nonce, if no tx hash")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class VerifyPaymentTool(_Base):
|
|
102
|
+
name: str = "moneytools_verify_payment"
|
|
103
|
+
description: str = "Verify an x402 USDC payment on Base by tx hash or nonce (who paid whom, how much, settled or not). Costs 0.003 USDC."
|
|
104
|
+
args_schema: Type[BaseModel] = VerifyPaymentInput
|
|
105
|
+
|
|
106
|
+
def _run(self, tx: Optional[str] = None, nonce: Optional[str] = None, run_manager: Any = None) -> Any:
|
|
107
|
+
if not tx and not nonce:
|
|
108
|
+
return {"error": "provide tx or nonce"}
|
|
109
|
+
try:
|
|
110
|
+
return self.settle.verify(tx=tx, nonce=nonce)
|
|
111
|
+
except Exception as e:
|
|
112
|
+
return {"error": str(e), "status": getattr(e, "status", None)}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class MoneyToolsToolkit(BaseToolkit):
|
|
116
|
+
"""All MoneyTools tools, paid by one Base wallet.
|
|
117
|
+
|
|
118
|
+
>>> from eth_account import Account
|
|
119
|
+
>>> tools = MoneyToolsToolkit.from_account(Account.from_key(KEY), max_usd_per_request=0.5).get_tools()
|
|
120
|
+
"""
|
|
121
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
122
|
+
transcripts: Any = None
|
|
123
|
+
settle: Any = None
|
|
124
|
+
payer: str = ""
|
|
125
|
+
max_wait_seconds: int = 120
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def from_account(cls, account, max_usd_per_request: float = 1.0, transcripts_url: str = TRANSCRIPTS_URL, settle_url: str = SETTLE_URL, max_wait_seconds: int = 120) -> "MoneyToolsToolkit":
|
|
129
|
+
return cls(transcripts=TranscriptsClient(account, base_url=transcripts_url, max_usd_per_request=max_usd_per_request),
|
|
130
|
+
settle=SettleClient(account, base_url=settle_url, max_usd_per_request=min(max_usd_per_request, 0.05)),
|
|
131
|
+
payer=account.address, max_wait_seconds=max_wait_seconds)
|
|
132
|
+
|
|
133
|
+
def get_tools(self) -> List[BaseTool]:
|
|
134
|
+
kw = dict(transcripts=self.transcripts, settle=self.settle, payer=self.payer)
|
|
135
|
+
return [TranscribeAudioTool(max_wait_seconds=self.max_wait_seconds, **kw), GetTranscriptionTool(**kw), SpendCheckTool(**kw), VerifyPaymentTool(**kw)]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langchain-moneytools"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "LangChain tools for MoneyTools: pay-per-file speech-to-text (Transcripts, 0.005 USDC/min) and x402 spend controls (Settle), paid with x402 USDC on Base. No API keys."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
keywords = ["langchain", "x402", "speech-to-text", "transcription", "agents", "base", "usdc"]
|
|
13
|
+
dependencies = ["langchain-core>=0.3", "moneytools-transcripts>=0.1.0", "pydantic>=2"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://speech.moneytools.dev"
|
|
17
|
+
Documentation = "https://speech.moneytools.dev/docs/migrate-from-dtelecom"
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.wheel]
|
|
20
|
+
packages = ["langchain_moneytools"]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.sdist]
|
|
23
|
+
include = ["langchain_moneytools", "README.md", "LICENSE"]
|