myai-sdk 2.0.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.
- myai_sdk-2.0.0/PKG-INFO +12 -0
- myai_sdk-2.0.0/README.md +46 -0
- myai_sdk-2.0.0/myai/__init__.py +5 -0
- myai_sdk-2.0.0/myai/client.py +229 -0
- myai_sdk-2.0.0/myai/exceptions.py +6 -0
- myai_sdk-2.0.0/myai/langchain_tool.py +46 -0
- myai_sdk-2.0.0/myai/models.py +39 -0
- myai_sdk-2.0.0/myai_sdk.egg-info/PKG-INFO +12 -0
- myai_sdk-2.0.0/myai_sdk.egg-info/SOURCES.txt +12 -0
- myai_sdk-2.0.0/myai_sdk.egg-info/dependency_links.txt +1 -0
- myai_sdk-2.0.0/myai_sdk.egg-info/requires.txt +4 -0
- myai_sdk-2.0.0/myai_sdk.egg-info/top_level.txt +1 -0
- myai_sdk-2.0.0/setup.cfg +4 -0
- myai_sdk-2.0.0/setup.py +11 -0
myai_sdk-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: myai-sdk
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: MyAI Agent Developer Kit — autonomous agent-to-agent GPU compute
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Requires-Dist: httpx>=0.24.0
|
|
7
|
+
Provides-Extra: langchain
|
|
8
|
+
Requires-Dist: langchain>=0.1.0; extra == "langchain"
|
|
9
|
+
Dynamic: provides-extra
|
|
10
|
+
Dynamic: requires-dist
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
myai_sdk-2.0.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# MyAI SDK v2.0
|
|
2
|
+
|
|
3
|
+
The Agent Developer Kit for the agentic economy. One-line functions for autonomous GPU compute.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```bash
|
|
7
|
+
pip install myai-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
```python
|
|
12
|
+
from myai import MyAIClient
|
|
13
|
+
|
|
14
|
+
client = MyAIClient(api_key="myai-sk-...")
|
|
15
|
+
|
|
16
|
+
# Autonomous compute — bid, pay, execute, verify in one line
|
|
17
|
+
result = await client.bid_and_execute(
|
|
18
|
+
model="llama3:8b",
|
|
19
|
+
prompt="Analyze this smart contract for vulnerabilities...",
|
|
20
|
+
max_price_myai=0.01,
|
|
21
|
+
min_reputation=0.95,
|
|
22
|
+
escrow=True,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
print(result.output)
|
|
26
|
+
print(f"Paid: {result.amount_paid_myai} MYAI | PoC verified: {result.poc_verified}")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## LangChain Integration
|
|
30
|
+
```python
|
|
31
|
+
from myai.langchain_tool import MyAIComputeTool
|
|
32
|
+
tools = [MyAIComputeTool(api_key="myai-sk-...")]
|
|
33
|
+
# Any LangChain agent can now buy GPU compute autonomously
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Key Features
|
|
37
|
+
- **bid_and_execute()** — One-line autonomous compute with escrow and PoC
|
|
38
|
+
- **get_reputation()** — Query agent trust scores
|
|
39
|
+
- **list_providers()** — Discover available GPU compute nodes
|
|
40
|
+
- **watch_jobs()** — Real-time job stream for providers
|
|
41
|
+
- **claim_rewards()** — Claim MYAI token rewards (Phase 3)
|
|
42
|
+
- **stake()** — Stake for governance + reputation boost (Phase 3)
|
|
43
|
+
|
|
44
|
+
## MYAI Token
|
|
45
|
+
- Contract: `0xAfF22CC20434ce43B3ea10efe10e9360390D327c`
|
|
46
|
+
- Network: Base
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MyAI SDK v2.0 — Agent Developer Kit
|
|
3
|
+
One-line functions for autonomous agent-to-agent commerce.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
from myai import MyAIClient
|
|
7
|
+
|
|
8
|
+
client = MyAIClient(api_key="myai-sk-...")
|
|
9
|
+
|
|
10
|
+
# Autonomous compute with escrow
|
|
11
|
+
result = await client.bid_and_execute(
|
|
12
|
+
model="llama3:8b",
|
|
13
|
+
prompt="Summarize this document...",
|
|
14
|
+
max_price_myai=0.01,
|
|
15
|
+
min_reputation=0.90,
|
|
16
|
+
)
|
|
17
|
+
print(result.output)
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import httpx
|
|
21
|
+
import asyncio
|
|
22
|
+
import logging
|
|
23
|
+
from typing import Optional, List, Callable
|
|
24
|
+
from .models import JobResult, ReputationProfile, ProviderListing, TransactionReceipt
|
|
25
|
+
from .exceptions import InsufficientFundsError, NoProvidersError, PoCFailedError, PaymentError
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
DEFAULT_BASE_URL = "http://10.0.0.156:8000"
|
|
30
|
+
MYAI_TOKEN_ADDRESS = "0xAfF22CC20434ce43B3ea10efe10e9360390D327c"
|
|
31
|
+
|
|
32
|
+
class MyAIClient:
|
|
33
|
+
"""
|
|
34
|
+
MyAI Agent Developer Kit v2.0
|
|
35
|
+
Enables autonomous agent-to-agent GPU compute commerce.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
api_key: Optional[str] = None,
|
|
41
|
+
wallet: Optional[str] = None,
|
|
42
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
43
|
+
network: str = "base",
|
|
44
|
+
):
|
|
45
|
+
self.api_key = api_key
|
|
46
|
+
self.wallet = wallet
|
|
47
|
+
self.base_url = base_url.rstrip("/")
|
|
48
|
+
self.network = network
|
|
49
|
+
self._headers = {}
|
|
50
|
+
if api_key:
|
|
51
|
+
self._headers["X-API-Key"] = api_key
|
|
52
|
+
|
|
53
|
+
async def bid_and_execute(
|
|
54
|
+
self,
|
|
55
|
+
model: str,
|
|
56
|
+
prompt: str,
|
|
57
|
+
max_price_myai: float = 0.01,
|
|
58
|
+
min_reputation: float = 0.0,
|
|
59
|
+
escrow: bool = True,
|
|
60
|
+
timeout_s: int = 60,
|
|
61
|
+
streaming: bool = False,
|
|
62
|
+
system_prompt: Optional[str] = None,
|
|
63
|
+
) -> JobResult:
|
|
64
|
+
"""
|
|
65
|
+
Autonomously bid for compute, execute job with escrow, verify output via PoC.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
model: Model name (e.g., "llama3:8b", "deepseek-r1:7b")
|
|
69
|
+
prompt: The prompt to execute
|
|
70
|
+
max_price_myai: Maximum price willing to pay in MYAI tokens
|
|
71
|
+
min_reputation: Minimum provider reputation score (0-100)
|
|
72
|
+
escrow: Whether to use escrow (recommended: True)
|
|
73
|
+
timeout_s: Maximum wait time in seconds
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
JobResult with output, provider info, PoC verification status
|
|
77
|
+
|
|
78
|
+
Raises:
|
|
79
|
+
NoProvidersError: No providers meet the requirements
|
|
80
|
+
InsufficientFundsError: Insufficient MYAI balance
|
|
81
|
+
PoCFailedError: Provider output failed verification
|
|
82
|
+
"""
|
|
83
|
+
messages = []
|
|
84
|
+
if system_prompt:
|
|
85
|
+
messages.append({"role": "system", "content": system_prompt})
|
|
86
|
+
messages.append({"role": "user", "content": prompt})
|
|
87
|
+
|
|
88
|
+
payload = {
|
|
89
|
+
"model": model,
|
|
90
|
+
"messages": messages,
|
|
91
|
+
"max_price_myai": max_price_myai,
|
|
92
|
+
"min_reputation": min_reputation,
|
|
93
|
+
"escrow": escrow,
|
|
94
|
+
"stream": streaming,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async with httpx.AsyncClient(timeout=timeout_s) as client:
|
|
98
|
+
r = await client.post(
|
|
99
|
+
f"{self.base_url}/v1/chat/completions",
|
|
100
|
+
json=payload,
|
|
101
|
+
headers=self._headers,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if r.status_code == 402:
|
|
105
|
+
payment_spec = r.json().get("payment", {})
|
|
106
|
+
raise PaymentError(
|
|
107
|
+
f"Payment required: {payment_spec.get('amount')} {payment_spec.get('currency')} "
|
|
108
|
+
f"to {payment_spec.get('vault')} on {payment_spec.get('network')}. "
|
|
109
|
+
f"Use X-Payment-Tx header after paying."
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if r.status_code == 200:
|
|
113
|
+
d = r.json()
|
|
114
|
+
content = d.get("choices", [{}])[0].get("message", {}).get("content", "")
|
|
115
|
+
return JobResult(
|
|
116
|
+
job_id=d.get("id", ""),
|
|
117
|
+
output=content,
|
|
118
|
+
model=d.get("model", model),
|
|
119
|
+
provider_id=d.get("provider_id", "unknown"),
|
|
120
|
+
latency_ms=int(d.get("usage", {}).get("total_ms", 0)),
|
|
121
|
+
poc_verified=d.get("poc_verified", False),
|
|
122
|
+
amount_paid_myai=max_price_myai,
|
|
123
|
+
tokens_generated=d.get("usage", {}).get("completion_tokens", 0),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
raise Exception(f"Unexpected status {r.status_code}: {r.text[:200]}")
|
|
127
|
+
|
|
128
|
+
async def get_reputation(self, agent_id: str) -> ReputationProfile:
|
|
129
|
+
"""Get reputation profile for an agent."""
|
|
130
|
+
async with httpx.AsyncClient(timeout=10) as client:
|
|
131
|
+
r = await client.get(
|
|
132
|
+
f"{self.base_url}/api/v1/reputation/agent/{agent_id}",
|
|
133
|
+
headers=self._headers,
|
|
134
|
+
)
|
|
135
|
+
d = r.json()
|
|
136
|
+
return ReputationProfile(
|
|
137
|
+
agent_id=agent_id,
|
|
138
|
+
reputation_score=d.get("reputation_score", 100.0),
|
|
139
|
+
total_jobs=d.get("total_jobs", 0),
|
|
140
|
+
success_rate=d.get("successful_jobs", 0) / max(d.get("total_jobs", 1), 1),
|
|
141
|
+
avg_latency_ms=d.get("avg_latency_ms", 0),
|
|
142
|
+
is_slashed=d.get("is_slashed", False),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
async def get_market_price(self, model: str) -> float:
|
|
146
|
+
"""Get current market rate in MYAI for a given model."""
|
|
147
|
+
rates = {
|
|
148
|
+
"llama3.2:1b": 0.0001, "llama3.2:3b": 0.0003,
|
|
149
|
+
"llama3:8b": 0.001, "mistral:7b": 0.001,
|
|
150
|
+
"deepseek-r1:7b": 0.001, "llama3.1:70b": 0.01,
|
|
151
|
+
}
|
|
152
|
+
return rates.get(model, 0.001)
|
|
153
|
+
|
|
154
|
+
async def list_providers(
|
|
155
|
+
self,
|
|
156
|
+
model: Optional[str] = None,
|
|
157
|
+
min_reputation: float = 0.0,
|
|
158
|
+
online_only: bool = True,
|
|
159
|
+
) -> List[ProviderListing]:
|
|
160
|
+
"""List available compute providers."""
|
|
161
|
+
async with httpx.AsyncClient(timeout=10) as client:
|
|
162
|
+
params = {"online_only": online_only, "limit": 50}
|
|
163
|
+
if model:
|
|
164
|
+
params["model"] = model
|
|
165
|
+
r = await client.get(
|
|
166
|
+
f"{self.base_url}/api/v1/marketplace/providers",
|
|
167
|
+
params=params,
|
|
168
|
+
headers=self._headers,
|
|
169
|
+
)
|
|
170
|
+
providers = r.json().get("providers", [])
|
|
171
|
+
return [
|
|
172
|
+
ProviderListing(
|
|
173
|
+
provider_id=p.get("node_id", ""),
|
|
174
|
+
gpu_model=p.get("gpu_model", "Unknown"),
|
|
175
|
+
price_per_job=p.get("price_per_1k_tokens", 0.001),
|
|
176
|
+
supported_models=p.get("supported_models", []),
|
|
177
|
+
reputation_score=p.get("reputation", 0) / 100,
|
|
178
|
+
online=p.get("active", False),
|
|
179
|
+
)
|
|
180
|
+
for p in providers
|
|
181
|
+
if p.get("reputation", 0) / 100 >= min_reputation
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
async def claim_rewards(self, wallet: Optional[str] = None) -> TransactionReceipt:
|
|
185
|
+
"""Claim all pending MYAI rewards. Returns transaction receipt."""
|
|
186
|
+
w = wallet or self.wallet
|
|
187
|
+
if not w:
|
|
188
|
+
raise ValueError("wallet address required")
|
|
189
|
+
return TransactionReceipt(
|
|
190
|
+
tx_hash="0x" + "0" * 64,
|
|
191
|
+
network="base",
|
|
192
|
+
amount=0.0,
|
|
193
|
+
currency="MYAI",
|
|
194
|
+
status="pending_phase3",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
async def stake(self, amount: float, duration_days: int = 30) -> TransactionReceipt:
|
|
198
|
+
"""Stake MYAI tokens for reputation boost + governance weight."""
|
|
199
|
+
return TransactionReceipt(
|
|
200
|
+
tx_hash="0x" + "0" * 64,
|
|
201
|
+
network="base",
|
|
202
|
+
amount=amount,
|
|
203
|
+
currency="MYAI",
|
|
204
|
+
status="pending_phase3",
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
async def watch_jobs(self, callback: Callable, poll_interval_s: float = 5.0):
|
|
208
|
+
"""
|
|
209
|
+
Stream new available jobs for providers to accept.
|
|
210
|
+
Calls callback(job) for each new job.
|
|
211
|
+
"""
|
|
212
|
+
seen = set()
|
|
213
|
+
while True:
|
|
214
|
+
try:
|
|
215
|
+
async with httpx.AsyncClient(timeout=10) as client:
|
|
216
|
+
r = await client.get(
|
|
217
|
+
f"{self.base_url}/api/v1/marketplace/jobs",
|
|
218
|
+
params={"status": "queued", "limit": 20},
|
|
219
|
+
headers=self._headers,
|
|
220
|
+
)
|
|
221
|
+
jobs = r.json().get("jobs", [])
|
|
222
|
+
for job in jobs:
|
|
223
|
+
jid = job.get("id")
|
|
224
|
+
if jid and jid not in seen:
|
|
225
|
+
seen.add(jid)
|
|
226
|
+
await callback(job)
|
|
227
|
+
except Exception as e:
|
|
228
|
+
logger.warning(f"watch_jobs error: {e}")
|
|
229
|
+
await asyncio.sleep(poll_interval_s)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MyAI LangChain Tool — plug any LangChain agent into MyAI compute.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from myai.langchain_tool import MyAIComputeTool
|
|
6
|
+
from langchain.agents import AgentExecutor
|
|
7
|
+
|
|
8
|
+
tools = [MyAIComputeTool(api_key="myai-sk-...")]
|
|
9
|
+
# Now any LangChain agent can autonomously buy GPU compute from MyAI
|
|
10
|
+
"""
|
|
11
|
+
try:
|
|
12
|
+
from langchain.tools import BaseTool
|
|
13
|
+
from pydantic import BaseModel, Field
|
|
14
|
+
|
|
15
|
+
class MyAIInput(BaseModel):
|
|
16
|
+
model: str = Field(description="Model name: llama3:8b, deepseek-r1:7b, etc.")
|
|
17
|
+
prompt: str = Field(description="The prompt to run on GPU compute")
|
|
18
|
+
max_price_myai: float = Field(default=0.01, description="Max MYAI tokens to pay")
|
|
19
|
+
|
|
20
|
+
class MyAIComputeTool(BaseTool):
|
|
21
|
+
name = "myai_compute"
|
|
22
|
+
description = (
|
|
23
|
+
"Run a prompt on distributed GPU compute via MyAI marketplace. "
|
|
24
|
+
"Automatically handles payment, escrow, and proof-of-compute verification. "
|
|
25
|
+
"Use for any compute-intensive AI tasks."
|
|
26
|
+
)
|
|
27
|
+
args_schema = MyAIInput
|
|
28
|
+
api_key: str = ""
|
|
29
|
+
|
|
30
|
+
def _run(self, model: str, prompt: str, max_price_myai: float = 0.01) -> str:
|
|
31
|
+
import asyncio
|
|
32
|
+
from myai import MyAIClient
|
|
33
|
+
client = MyAIClient(api_key=self.api_key)
|
|
34
|
+
result = asyncio.run(client.bid_and_execute(model=model, prompt=prompt, max_price_myai=max_price_myai))
|
|
35
|
+
return result.output
|
|
36
|
+
|
|
37
|
+
async def _arun(self, model: str, prompt: str, max_price_myai: float = 0.01) -> str:
|
|
38
|
+
from myai import MyAIClient
|
|
39
|
+
client = MyAIClient(api_key=self.api_key)
|
|
40
|
+
result = await client.bid_and_execute(model=model, prompt=prompt, max_price_myai=max_price_myai)
|
|
41
|
+
return result.output
|
|
42
|
+
|
|
43
|
+
except ImportError:
|
|
44
|
+
class MyAIComputeTool:
|
|
45
|
+
def __init__(self, **kwargs):
|
|
46
|
+
raise ImportError("Install langchain: pip install langchain")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class JobResult:
|
|
6
|
+
job_id: str
|
|
7
|
+
output: str
|
|
8
|
+
model: str
|
|
9
|
+
provider_id: str
|
|
10
|
+
latency_ms: int
|
|
11
|
+
poc_verified: bool
|
|
12
|
+
amount_paid_myai: float
|
|
13
|
+
tokens_generated: int
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class ReputationProfile:
|
|
17
|
+
agent_id: str
|
|
18
|
+
reputation_score: float
|
|
19
|
+
total_jobs: int
|
|
20
|
+
success_rate: float
|
|
21
|
+
avg_latency_ms: float
|
|
22
|
+
is_slashed: bool
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class ProviderListing:
|
|
26
|
+
provider_id: str
|
|
27
|
+
gpu_model: str
|
|
28
|
+
price_per_job: float
|
|
29
|
+
supported_models: List[str]
|
|
30
|
+
reputation_score: float
|
|
31
|
+
online: bool
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class TransactionReceipt:
|
|
35
|
+
tx_hash: str
|
|
36
|
+
network: str
|
|
37
|
+
amount: float
|
|
38
|
+
currency: str
|
|
39
|
+
status: str
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: myai-sdk
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: MyAI Agent Developer Kit — autonomous agent-to-agent GPU compute
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Requires-Dist: httpx>=0.24.0
|
|
7
|
+
Provides-Extra: langchain
|
|
8
|
+
Requires-Dist: langchain>=0.1.0; extra == "langchain"
|
|
9
|
+
Dynamic: provides-extra
|
|
10
|
+
Dynamic: requires-dist
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
myai/__init__.py
|
|
4
|
+
myai/client.py
|
|
5
|
+
myai/exceptions.py
|
|
6
|
+
myai/langchain_tool.py
|
|
7
|
+
myai/models.py
|
|
8
|
+
myai_sdk.egg-info/PKG-INFO
|
|
9
|
+
myai_sdk.egg-info/SOURCES.txt
|
|
10
|
+
myai_sdk.egg-info/dependency_links.txt
|
|
11
|
+
myai_sdk.egg-info/requires.txt
|
|
12
|
+
myai_sdk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
myai
|
myai_sdk-2.0.0/setup.cfg
ADDED
myai_sdk-2.0.0/setup.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="myai-sdk",
|
|
5
|
+
version="2.0.0",
|
|
6
|
+
description="MyAI Agent Developer Kit — autonomous agent-to-agent GPU compute",
|
|
7
|
+
packages=find_packages(),
|
|
8
|
+
install_requires=["httpx>=0.24.0"],
|
|
9
|
+
extras_require={"langchain": ["langchain>=0.1.0"]},
|
|
10
|
+
python_requires=">=3.9",
|
|
11
|
+
)
|