haystack-nory 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.
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"""Haystack Nory x402 Tools - Payment tools for Haystack pipelines."""
|
|
2
|
+
from haystack_nory.tools import NoryPaymentComponent, NoryCryptoPrices, NoryWeather, NoryTranslate
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
__all__ = ["NoryPaymentComponent", "NoryCryptoPrices", "NoryWeather", "NoryTranslate"]
|
haystack_nory/tools.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Haystack components for Nory x402 payments."""
|
|
2
|
+
import os, json, requests
|
|
3
|
+
from typing import Optional, List, Any
|
|
4
|
+
from haystack import component, default_from_dict, default_to_dict
|
|
5
|
+
|
|
6
|
+
NORY_BASE_URL = "https://noryx402.com"
|
|
7
|
+
|
|
8
|
+
def _make_paid_request(url: str, wallet_key: Optional[str] = None) -> dict:
|
|
9
|
+
key = wallet_key or os.environ.get("NORY_WALLET_KEY")
|
|
10
|
+
headers = {"Accept": "application/json"}
|
|
11
|
+
response = requests.get(url, headers=headers)
|
|
12
|
+
if response.status_code == 402:
|
|
13
|
+
if not key:
|
|
14
|
+
return {"error": "Payment required but no wallet key", "requirements": response.json()}
|
|
15
|
+
requirements = response.json()
|
|
16
|
+
payment_response = requests.post(f"{NORY_BASE_URL}/api/x402/pay",
|
|
17
|
+
json={"requirements": requirements, "walletKey": key, "network": "solana-mainnet"},
|
|
18
|
+
headers={"Content-Type": "application/json"})
|
|
19
|
+
if payment_response.status_code != 200:
|
|
20
|
+
return {"error": "Payment failed"}
|
|
21
|
+
payment_data = payment_response.json()
|
|
22
|
+
headers["X-PAYMENT"] = payment_data.get("paymentHeader", "")
|
|
23
|
+
final_response = requests.get(url, headers=headers)
|
|
24
|
+
try:
|
|
25
|
+
return {"success": True, "data": final_response.json(), "payment": {"amount": payment_data.get("amount")}}
|
|
26
|
+
except:
|
|
27
|
+
return {"success": True, "data": final_response.text}
|
|
28
|
+
try:
|
|
29
|
+
return {"success": True, "data": response.json()}
|
|
30
|
+
except:
|
|
31
|
+
return {"success": True, "data": response.text}
|
|
32
|
+
|
|
33
|
+
@component
|
|
34
|
+
class NoryPaymentComponent:
|
|
35
|
+
"""Haystack component for fetching x402-protected URLs with automatic payment."""
|
|
36
|
+
def __init__(self, wallet_key: Optional[str] = None):
|
|
37
|
+
self.wallet_key = wallet_key or os.environ.get("NORY_WALLET_KEY")
|
|
38
|
+
@component.output_types(result=str)
|
|
39
|
+
def run(self, url: str) -> dict:
|
|
40
|
+
result = _make_paid_request(url, self.wallet_key)
|
|
41
|
+
return {"result": json.dumps(result)}
|
|
42
|
+
|
|
43
|
+
@component
|
|
44
|
+
class NoryCryptoPrices:
|
|
45
|
+
"""Get real-time crypto prices. $0.001 per request."""
|
|
46
|
+
def __init__(self, wallet_key: Optional[str] = None):
|
|
47
|
+
self.wallet_key = wallet_key or os.environ.get("NORY_WALLET_KEY")
|
|
48
|
+
@component.output_types(prices=str)
|
|
49
|
+
def run(self, symbols: str = "BTC,ETH,SOL") -> dict:
|
|
50
|
+
result = _make_paid_request(f"{NORY_BASE_URL}/api/paid/live-crypto?symbols={symbols}", self.wallet_key)
|
|
51
|
+
return {"prices": json.dumps(result)}
|
|
52
|
+
|
|
53
|
+
@component
|
|
54
|
+
class NoryWeather:
|
|
55
|
+
"""Get weather and forecast. $0.002 per request."""
|
|
56
|
+
def __init__(self, wallet_key: Optional[str] = None):
|
|
57
|
+
self.wallet_key = wallet_key or os.environ.get("NORY_WALLET_KEY")
|
|
58
|
+
@component.output_types(weather=str)
|
|
59
|
+
def run(self, city: str) -> dict:
|
|
60
|
+
result = _make_paid_request(f"{NORY_BASE_URL}/api/paid/weather?city={city}", self.wallet_key)
|
|
61
|
+
return {"weather": json.dumps(result)}
|
|
62
|
+
|
|
63
|
+
@component
|
|
64
|
+
class NoryTranslate:
|
|
65
|
+
"""Translate text. $0.005 per request."""
|
|
66
|
+
def __init__(self, wallet_key: Optional[str] = None):
|
|
67
|
+
self.wallet_key = wallet_key or os.environ.get("NORY_WALLET_KEY")
|
|
68
|
+
@component.output_types(translation=str)
|
|
69
|
+
def run(self, text: str, to_lang: str = "es") -> dict:
|
|
70
|
+
result = _make_paid_request(f"{NORY_BASE_URL}/api/paid/translate?text={text}&to={to_lang}", self.wallet_key)
|
|
71
|
+
return {"translation": json.dumps(result)}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: haystack-nory
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Haystack components for x402 payments - let pipelines pay for APIs
|
|
5
|
+
Author-email: Nory <hello@noryx402.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://noryx402.com
|
|
8
|
+
Project-URL: Repository, https://github.com/TheMemeBanker/haystack-nory
|
|
9
|
+
Keywords: haystack,deepset,ai-agents,payments,x402,solana
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: haystack-ai>=2.0.0
|
|
16
|
+
Requires-Dist: requests>=2.28.0
|
|
17
|
+
|
|
18
|
+
# haystack-nory
|
|
19
|
+
|
|
20
|
+
**Haystack components for x402 payments** - Let your pipelines pay for APIs.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
```bash
|
|
24
|
+
pip install haystack-nory
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
```python
|
|
29
|
+
from haystack import Pipeline
|
|
30
|
+
from haystack_nory import NoryCryptoPrices, NoryWeather
|
|
31
|
+
|
|
32
|
+
pipeline = Pipeline()
|
|
33
|
+
pipeline.add_component("crypto", NoryCryptoPrices())
|
|
34
|
+
result = pipeline.run({"crypto": {"symbols": "BTC,ETH,SOL"}})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Components
|
|
38
|
+
- `NoryPaymentComponent` - Fetch any URL with auto payment
|
|
39
|
+
- `NoryCryptoPrices` - Real-time crypto ($0.001)
|
|
40
|
+
- `NoryWeather` - Weather forecast ($0.002)
|
|
41
|
+
- `NoryTranslate` - Translation ($0.005)
|
|
42
|
+
|
|
43
|
+
Set `NORY_WALLET_KEY` env var. [Docs](https://noryx402.com)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
haystack_nory/__init__.py,sha256=Fo6MFTZiC2jU0LajZTPuAq2NLntm6swKlE44BYNltb8,279
|
|
2
|
+
haystack_nory/tools.py,sha256=C84LMH3ICj6hfzf26jjnsWh8JAf-j8lKuwtgF-O4o8w,3346
|
|
3
|
+
haystack_nory-0.1.0.dist-info/METADATA,sha256=TnNu4QJ1IO-mzxOr3enZ5AdQWajGPQ6coox9-YNBRho,1293
|
|
4
|
+
haystack_nory-0.1.0.dist-info/WHEEL,sha256=YLJXdYXQ2FQ0Uqn2J-6iEIC-3iOey8lH3xCtvFLkd8Q,91
|
|
5
|
+
haystack_nory-0.1.0.dist-info/top_level.txt,sha256=GAgUoQHmO0nSLUO0swNhiDUaGqLmmnSU73WuoUebcYw,14
|
|
6
|
+
haystack_nory-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
haystack_nory
|