Skip to content

Commit 7cddeb5

Browse files
authored
Merge branch 'main' into ani/langchain-changes
Signed-off-by: kukac <adambalogh@users.noreply.github.com>
2 parents 6db61b6 + 89e9d57 commit 7cddeb5

32 files changed

Lines changed: 1424 additions & 656 deletions

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ pip install opengradient
2626

2727
**Note**: > **Windows users:** See the [Windows Installation Guide](./WINDOWS_INSTALL.md) for step-by-step setup instructions.
2828

29+
### Claude Code Integration
30+
31+
If you use [Claude Code](https://claude.ai/code), you can enhance your development experience with OpenGradient:
32+
33+
- **CLAUDE.md context file**: Copy [docs/CLAUDE_SDK_USERS.md](docs/CLAUDE_SDK_USERS.md) to your project's `CLAUDE.md` to enable context-aware assistance with OpenGradient SDK development.
34+
35+
- **Claude Code Plugin**: Install the [OpenGradient Claude Plugin](https://github.com/OpenGradient/claude-plugins) for skills, commands, and agents tailored to OpenGradient development. To install, run:
36+
```bash
37+
claude plugin marketplace add https://github.com/OpenGradient/claude-plugins
38+
```
39+
2940
## Network Architecture
3041

3142
OpenGradient operates two networks:
@@ -88,10 +99,10 @@ hub = og.ModelHub(email="you@example.com", password="...")
8899

89100
### OPG Token Approval
90101

91-
Before making LLM requests, your wallet must approve OPG token spending via the [Permit2](https://github.com/Uniswap/permit2) protocol. Call this once (it's idempotent — no transaction is sent if the allowance already covers the requested amount):
102+
Before making LLM requests, your wallet must approve OPG token spending via the [Permit2](https://github.com/Uniswap/permit2) protocol. This only sends an on-chain transaction when the current allowance drops below the threshold:
92103

93104
```python
94-
llm.ensure_opg_approval(opg_amount=5)
105+
llm.ensure_opg_approval(min_allowance=5)
95106
```
96107

97108
See [Payment Settlement](#payment-settlement) for details on settlement modes.
@@ -324,10 +335,6 @@ For comprehensive documentation, API reference, and guides:
324335
- [API Reference](https://docs.opengradient.ai/api_reference/python_sdk/)
325336
- [Network Deployment](https://docs.opengradient.ai/learn/network/deployment.html)
326337

327-
### Claude Code Integration
328-
329-
If you use [Claude Code](https://claude.ai/code), copy [docs/CLAUDE_SDK_USERS.md](docs/CLAUDE_SDK_USERS.md) to your project's `CLAUDE.md` to enable context-aware assistance with OpenGradient SDK development.
330-
331338
## Model Hub
332339

333340
Browse and discover AI models on the [OpenGradient Model Hub](https://hub.opengradient.ai/). The Hub provides:

docs/CLAUDE_SDK_USERS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import os
2121
# Create an LLM client
2222
llm = og.LLM(private_key=os.environ["OG_PRIVATE_KEY"])
2323

24-
# One-time OPG token approval (idempotent — skips if allowance already sufficient)
25-
llm.ensure_opg_approval(opg_amount=0.1)
24+
# Ensure sufficient OPG allowance (only sends tx when below threshold)
25+
llm.ensure_opg_approval(min_allowance=0.1)
2626

2727
# LLM Chat (TEE-verified with x402 payments, async)
2828
result = await llm.chat(

docs/opengradient/client/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import opengradient as og
2424

2525
# LLM inference (Base Sepolia OPG tokens)
2626
llm = og.LLM(private_key="0x...")
27-
llm.ensure_opg_approval(opg_amount=5)
27+
llm.ensure_opg_approval(min_allowance=5)
2828
result = await llm.chat(model=og.TEE_LLM.CLAUDE_HAIKU_4_5, messages=[...])
2929

3030
# On-chain model inference (OpenGradient testnet gas tokens)

docs/opengradient/client/llm.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,37 @@ All request methods (``chat``, ``completion``) are async.
2222

2323
Before making LLM requests, ensure your wallet has approved sufficient
2424
OPG tokens for Permit2 spending by calling ``ensure_opg_approval``.
25-
This only sends an on-chain transaction when the current allowance is
26-
below the requested amount.
2725

2826
#### Constructor
2927

3028
```python
3129
def __init__(
3230
private_keystr,
3331
rpc_urlstr = 'https://ogevmdevnet.opengradient.ai',
34-
tee_registry_addressstr = '0x4e72238852f3c918f4E4e57AeC9280dDB0c80248',
35-
llm_server_url: Optional[str= None
32+
tee_registry_addressstr = '0x4e72238852f3c918f4E4e57AeC9280dDB0c80248'
3633
)
3734
```
3835

36+
#### Static methods
37+
38+
---
39+
40+
#### `from_url()`
41+
42+
```python
43+
static def from_url(private_keystr, llm_server_urlstr) ‑> `LLM`
44+
```
45+
**[Dev]** Create an LLM client with a hardcoded TEE endpoint URL.
46+
47+
Intended for development and self-hosted TEE servers. TLS certificate
48+
verification is disabled because these servers typically use self-signed
49+
certificates. For production use, prefer the default constructor which
50+
resolves TEEs from the on-chain registry.
51+
3952
**Arguments**
4053

41-
* **`private_key (str)`**: Ethereum private key for signing x402 payments.
42-
* **`rpc_url (str)`**: RPC URL for the OpenGradient network. Used to fetch the
43-
active TEE endpoint from the on-chain registry when ``llm_server_url``
44-
is not provided.
45-
* **`tee_registry_address (str)`**: Address of the on-chain TEE registry contract.
46-
* **`llm_server_url (str, optional)`**: Bypass the registry and connect directly
47-
to this TEE endpoint URL (e.g. ``"https://1.2.3.4"``). When set,
48-
TLS certificate verification is disabled automatically because
49-
self-hosted TEE servers typically use self-signed certificates.
50-
51-
.. warning::
52-
Using ``llm_server_url`` disables TLS certificate verification,
53-
which removes protection against man-in-the-middle attacks.
54-
Only connect to servers you trust and over secure network paths.
54+
* **`private_key`**: Ethereum private key for signing x402 payments.
55+
* **`llm_server_url`**: The TEE endpoint URL (e.g. ``"https://1.2.3.4"``).
5556

5657
#### Methods
5758

@@ -125,7 +126,7 @@ Union[TextGenerationOutput, AsyncGenerator[StreamChunk, None]]:
125126
```python
126127
async def close(self) ‑> None
127128
```
128-
Close the underlying HTTP client.
129+
Cancel the background refresh loop and close the HTTP client.
129130

130131
---
131132

@@ -190,18 +191,30 @@ TextGenerationOutput: Generated text results including:
190191
#### `ensure_opg_approval()`
191192

192193
```python
193-
def ensure_opg_approval(self, opg_amountfloat) ‑> [Permit2ApprovalResult](./opg_token)
194+
def ensure_opg_approval(
195+
self,
196+
min_allowancefloat,
197+
approve_amount: Optional[float= None
198+
) ‑> [Permit2ApprovalResult](./opg_token)
194199
```
195-
Ensure the Permit2 allowance for OPG is at least ``opg_amount``.
200+
Ensure the Permit2 allowance stays above a minimum threshold.
201+
202+
Only sends a transaction when the current allowance drops below
203+
``min_allowance``. When approval is needed, approves ``approve_amount``
204+
(defaults to ``2 * min_allowance``) to create a buffer that survives
205+
multiple service restarts without re-approving.
206+
207+
Best for backend servers that call this on startup::
196208

197-
Checks the current Permit2 allowance for the wallet. If the allowance
198-
is already >= the requested amount, returns immediately without sending
199-
a transaction. Otherwise, sends an ERC-20 approve transaction.
209+
llm.ensure_opg_approval(min_allowance=5.0, approve_amount=100.0)
200210

201211
**Arguments**
202212

203-
* **`opg_amount`**: Minimum number of OPG tokens required (e.g. ``0.1``
204-
for 0.1 OPG). Must be at least 0.1 OPG.
213+
* **`min_allowance`**: The minimum acceptable allowance in OPG. Must be
214+
at least 0.1 OPG.
215+
* **`approve_amount`**: The amount of OPG to approve when a transaction
216+
is needed. Defaults to ``2 * min_allowance``. Must be
217+
>= ``min_allowance``.
205218

206219
**Returns**
207220

@@ -211,5 +224,6 @@ Permit2ApprovalResult: Contains ``allowance_before``,
211224

212225
**Raises**
213226

214-
* **`ValueError`**: If the OPG amount is less than 0.1.
227+
* **`ValueError`**: If ``min_allowance`` is less than 0.1 or
228+
``approve_amount`` is less than ``min_allowance``.
215229
* **`RuntimeError`**: If the approval transaction fails.

docs/opengradient/client/model_hub.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ Create a new model with the given model_name and model_desc, and a specified ver
4343

4444
* **`model_name (str)`**: The name of the model.
4545
* **`model_desc (str)`**: The description of the model.
46-
* **`version (str)`**: The version identifier (default is "1.00").
46+
* **`version (str)`**: A label used in the initial version notes (default is "1.00").
47+
* **`Note`**: the actual version string is assigned by the server.
4748

4849
**Returns**
4950

50-
dict: The server response containing model details.
51+
ModelRepository: Object containing the model name and server-assigned version string.
5152

5253
**Raises**
5354

54-
* **`CreateModelError`**: If the model creation fails.
55+
* **`RuntimeError`**: If the model creation fails.
5556

5657
---
5758

@@ -125,7 +126,7 @@ Upload a model file to the server.
125126

126127
**Returns**
127128

128-
dict: The processed result.
129+
FileUploadResult: The processed result.
129130

130131
**Raises**
131132

docs/opengradient/client/opg_token.md

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)