Skip to content

Commit a245fc7

Browse files
dixitaniketadambaloghCopilot
authored
x402 base payment cleanup (#160)
* updates * Delete uv.lock * Update src/opengradient/client/llm.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: kukac <adambalogh@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8dcdef3 commit a245fc7

14 files changed

Lines changed: 42 additions & 272 deletions

File tree

Makefile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,22 @@ completion:
6868
--prompt "Hello, how are you?" \
6969
--max-tokens 50
7070

71-
chat-og-evm:
71+
chat:
7272
python -m opengradient.cli chat \
7373
--model $(MODEL) \
7474
--messages '[{"role":"user","content":"Tell me a fun fact"}]' \
75-
--max-tokens 150 --network og-evm
76-
77-
chat-base-testnet:
78-
python -m opengradient.cli chat \
79-
--model $(MODEL) \
80-
--messages '[{"role":"user","content":"Tell me a fun fact"}]' \
81-
--max-tokens 150 --network base-testnet
75+
--max-tokens 150
8276

8377
chat-stream:
8478
python -m opengradient.cli chat \
85-
--model $(MODEL) --mode TEE \
79+
--model $(MODEL) \
8680
--messages '[{"role":"user","content":"Tell me a short story"}]' \
8781
--max-tokens 250 \
8882
--stream
8983

9084
chat-tool:
9185
python -m opengradient.cli chat \
92-
--model $(MODEL) --mode TEE \
86+
--model $(MODEL) \
9387
--messages '[{"role":"user","content":"What is the weather in Tokyo?"}]' \
9488
--tools '[{"type":"function","function":{"name":"get_weather","description":"Get weather for a location","parameters":{"type":"object","properties":{"location":{"type":"string"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}]' \
9589
--max-tokens 100 \

docs/opengradient/client/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ blockchain private key and optional Model Hub credentials.
2121
#### Constructor
2222

2323
```python
24-
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llmogevm.opengradient.ai')
24+
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llm.opengradient.ai')
2525
```
2626

2727
**Arguments**

docs/opengradient/client/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ blockchain private key and optional Model Hub credentials.
6868
#### Constructor
6969

7070
```python
71-
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llmogevm.opengradient.ai')
71+
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llm.opengradient.ai')
7272
```
7373

7474
**Arguments**

docs/opengradient/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ blockchain private key and optional Model Hub credentials.
127127
#### Constructor
128128

129129
```python
130-
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llmogevm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llmogevm.opengradient.ai')
130+
def __init__(private_keystr, email: Optional[str= None, password: Optional[str= None, twins_api_key: Optional[str= None, wallet_addressstr = None, rpc_urlstr = 'https://ogevmdevnet.opengradient.ai', api_urlstr = 'https://sdk-devnet.opengradient.ai', contract_addressstr = '0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE', og_llm_server_url: Optional[str= 'https://llm.opengradient.ai', og_llm_streaming_server_url: Optional[str= 'https://llm.opengradient.ai')
131131
```
132132

133133
**Arguments**

examples/run_x402_llm.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import opengradient as og
1515
from x402_permit2 import check_permit2_approval
1616

17-
network = "base-testnet"
18-
1917
client = og.Client(
2018
private_key=os.environ.get("OG_PRIVATE_KEY"),
2119
)
2220

23-
check_permit2_approval(client.wallet_address, network)
21+
check_permit2_approval(client.wallet_address)
2422

2523
messages = [
2624
{"role": "user", "content": "What is Python?"},
@@ -29,6 +27,6 @@
2927
]
3028

3129
result = client.llm.chat(
32-
model=og.TEE_LLM.GPT_4_1_2025_04_14, messages=messages, x402_settlement_mode=og.x402SettlementMode.SETTLE_METADATA, network=network
30+
model=og.TEE_LLM.GPT_4_1_2025_04_14, messages=messages, x402_settlement_mode=og.x402SettlementMode.SETTLE_METADATA
3331
)
3432
print(f"Response: {result.chat_output['content']}")

examples/run_x402_llm_stream.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import opengradient as og
44
from x402_permit2 import check_permit2_approval
55

6-
network = "base-testnet"
7-
86
client = og.Client(
97
private_key=os.environ.get("OG_PRIVATE_KEY"),
108
)
119

12-
check_permit2_approval(client.wallet_address, network)
10+
check_permit2_approval(client.wallet_address)
1311

1412
messages = [
1513
{"role": "user", "content": "What is Python?"},
@@ -23,7 +21,6 @@
2321
x402_settlement_mode=og.x402SettlementMode.SETTLE_METADATA,
2422
stream=True,
2523
max_tokens=300,
26-
network=network,
2724
)
2825

2926
for chunk in stream:

examples/x402_permit2.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
BASE_OPG_ADDRESS = "0x240b09731D96979f50B2C649C9CE10FcF9C7987F"
1010
BASE_SEPOLIA_RPC = "https://sepolia.base.org"
11-
BASE_TESTNET = "base-testnet"
1211
MAX_UINT256 = (1 << 256) - 1
1312

1413
ERC20_ABI = [
@@ -48,11 +47,8 @@ def get_permit2_allowance(client_address: str) -> int:
4847
).call()
4948

5049

51-
def check_permit2_approval(client_address: str, network: str) -> None:
50+
def check_permit2_approval(client_address: str) -> None:
5251
"""Raise an error if Permit2 approval is missing for base-testnet."""
53-
if network != BASE_TESTNET:
54-
return
55-
5652
allowance = get_permit2_allowance(client_address)
5753
print(f"Current OPG Permit2 allowance: {allowance}")
5854

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ dependencies = [
2727
"langchain>=0.3.7",
2828
"openai>=1.58.1",
2929
"pydantic>=2.9.2",
30-
"og-test-x402==0.0.9",
31-
"og-test-v2-x402==0.0.6"
30+
"og-test-v2-x402==0.0.9"
3231
]
3332

3433
[project.scripts]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ requests>=2.32.3
77
langchain>=0.3.7
88
openai>=1.58.1
99
pydantic>=2.9.2
10-
og-test-x402==0.0.9
11-
og-test-v2-x402==0.0.6
10+
og-test-v2-x402==0.0.9

src/opengradient/cli.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
DEFAULT_OG_FAUCET_URL,
2121
DEFAULT_RPC_URL,
2222
)
23-
from .types import InferenceMode, x402Network, x402SettlementMode
23+
from .types import InferenceMode, x402SettlementMode
2424

2525
OG_CONFIG_FILE = Path.home() / ".opengradient_config.json"
2626

@@ -74,11 +74,6 @@ def convert(self, value, param, ctx):
7474
"settle-metadata": x402SettlementMode.SETTLE_METADATA,
7575
}
7676

77-
x402Networks = {
78-
"og-evm": x402Network.OG_EVM,
79-
"base-testnet": x402Network.BASE_TESTNET,
80-
}
81-
8277

8378
def initialize_config(ctx):
8479
"""Interactively initialize OpenGradient config"""
@@ -466,12 +461,6 @@ def print_llm_completion_result(model_cid, tx_hash, llm_output, is_vanilla=True)
466461
default="settle-batch",
467462
help="Settlement mode for x402 payments: settle (hashes only), settle-batch (batched, default), settle-metadata (full data)",
468463
)
469-
@click.option(
470-
"--network",
471-
type=click.Choice(x402Networks.keys()),
472-
default="og-evm",
473-
help="x402 network to use for TEE chat payments: og-evm (default) or base-testnet",
474-
)
475464
@click.option("--stream", is_flag=True, default=False, help="Stream the output from the LLM")
476465
@click.pass_context
477466
def chat(
@@ -486,7 +475,6 @@ def chat(
486475
tools_file: Optional[Path],
487476
tool_choice: Optional[str],
488477
x402_settlement_mode: Optional[str],
489-
network: str,
490478
stream: bool,
491479
):
492480
"""
@@ -573,7 +561,6 @@ def chat(
573561
tools=parsed_tools,
574562
tool_choice=tool_choice,
575563
x402_settlement_mode=x402SettlementModes[x402_settlement_mode],
576-
network=x402Networks[network],
577564
stream=stream,
578565
)
579566

0 commit comments

Comments
 (0)