Skip to content

Commit a99f725

Browse files
balogh.adam@icloud.combalogh.adam@icloud.com
authored andcommitted
alpha private key
1 parent a245fc7 commit a99f725

7 files changed

Lines changed: 39 additions & 14 deletions

File tree

examples/run_x402_llm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,5 @@
2626
{"role": "user", "content": "What makes it good for beginners?"},
2727
]
2828

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

src/opengradient/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999

100100
def init(
101101
private_key: str,
102+
alpha_private_key: Optional[str] = None,
102103
email: Optional[str] = None,
103104
password: Optional[str] = None,
104105
**kwargs,
@@ -109,7 +110,9 @@ def init(
109110
and stores it as the global client for convenience.
110111
111112
Args:
112-
private_key: Private key for OpenGradient transactions.
113+
private_key: Private key for LLM inference (Base Sepolia, x402 payments).
114+
alpha_private_key: Private key for Alpha Testnet features (on-chain inference).
115+
When omitted, falls back to ``private_key`` for backward compatibility.
113116
email: Email for Model Hub authentication. Optional.
114117
password: Password for Model Hub authentication. Optional.
115118
**kwargs: Additional arguments forwarded to `Client`.
@@ -123,7 +126,13 @@ def init(
123126
response = client.llm.chat(model=og.TEE_LLM.GPT_4O, messages=[...])
124127
"""
125128
global global_client
126-
global_client = Client(private_key=private_key, email=email, password=password, **kwargs)
129+
global_client = Client(
130+
private_key=private_key,
131+
alpha_private_key=alpha_private_key,
132+
email=email,
133+
password=password,
134+
**kwargs,
135+
)
127136
return global_client
128137

129138

src/opengradient/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ def initialize_config(ctx):
9696
else:
9797
ctx.obj["private_key"] = click.prompt("Enter your OpenGradient private key", type=str)
9898

99+
# Optional separate private key for Alpha Testnet
100+
alpha_pk = click.prompt(
101+
"Enter a separate Alpha Testnet private key (optional, press Enter to reuse the main key)",
102+
type=str,
103+
default="",
104+
show_default=False,
105+
)
106+
ctx.obj["alpha_private_key"] = alpha_pk if alpha_pk else None
107+
99108
# Make email and password optional
100109
email = click.prompt(
101110
"Enter your OpenGradient Hub email address (optional, press Enter to skip)", type=str, default="", show_default=False
@@ -132,6 +141,7 @@ def cli(ctx):
132141
try:
133142
ctx.obj["client"] = Client(
134143
private_key=ctx.obj["private_key"],
144+
alpha_private_key=ctx.obj.get("alpha_private_key"),
135145
rpc_url=DEFAULT_RPC_URL,
136146
api_url=DEFAULT_API_URL,
137147
contract_address=DEFAULT_INFERENCE_CONTRACT_ADDRESS,
@@ -173,7 +183,7 @@ def show(ctx):
173183
click.echo("Current config:")
174184
for key, value in ctx.obj.items():
175185
if key != "client": # Don't display the client object
176-
if (key == "password" or key == "private_key") and value is not None:
186+
if key in ("password", "private_key", "alpha_private_key") and value is not None:
177187
click.echo(f"{key}: {'*' * len(value)}") # Mask the password
178188
elif value is None:
179189
click.echo(f"{key}: Not set")

src/opengradient/client/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
1818
client = og.init(private_key="0x...")
1919
20+
# Use separate keys for LLM (Base Sepolia) and Alpha Testnet
21+
client = og.init(private_key="0xLLM_KEY...", alpha_private_key="0xALPHA_KEY...")
22+
2023
# LLM chat (TEE-verified, streamed)
2124
for chunk in client.llm.chat(
2225
model=og.TEE_LLM.CLAUDE_3_5_HAIKU,

src/opengradient/client/client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Client:
4747
def __init__(
4848
self,
4949
private_key: str,
50+
alpha_private_key: Optional[str] = None,
5051
email: Optional[str] = None,
5152
password: Optional[str] = None,
5253
twins_api_key: Optional[str] = None,
@@ -61,11 +62,13 @@ def __init__(
6162
Initialize the OpenGradient client.
6263
6364
Args:
64-
private_key: Private key for OpenGradient transactions.
65+
private_key: Private key for LLM inference (Base Sepolia, x402 payments).
66+
alpha_private_key: Private key for Alpha Testnet features (on-chain inference).
67+
When omitted, falls back to ``private_key`` for backward compatibility.
6568
email: Email for Model Hub authentication. Optional.
6669
password: Password for Model Hub authentication. Optional.
6770
twins_api_key: API key for digital twins chat (twin.fun). Optional.
68-
rpc_url: RPC URL for the blockchain network.
71+
rpc_url: RPC URL for the Alpha Testnet blockchain network.
6972
api_url: API URL for the OpenGradient API.
7073
contract_address: Inference contract address.
7174
og_llm_server_url: OpenGradient LLM server URL.
@@ -74,6 +77,12 @@ def __init__(
7477
blockchain = Web3(Web3.HTTPProvider(rpc_url))
7578
wallet_account = blockchain.eth.account.from_key(private_key)
7679

80+
# Use a separate account for Alpha Testnet when provided
81+
if alpha_private_key is not None:
82+
alpha_wallet_account = blockchain.eth.account.from_key(alpha_private_key)
83+
else:
84+
alpha_wallet_account = wallet_account
85+
7786
hub_user = None
7887
if email is not None:
7988
hub_user = ModelHub._login_to_hub(email, password)
@@ -90,7 +99,7 @@ def __init__(
9099

91100
self.alpha = Alpha(
92101
blockchain=blockchain,
93-
wallet_account=wallet_account,
102+
wallet_account=alpha_wallet_account,
94103
inference_hub_contract_address=contract_address,
95104
api_url=api_url,
96105
)

src/opengradient/client/llm.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ async def make_request_v2():
264264
try:
265265
# Non-streaming with x402
266266
endpoint = "/v1/chat/completions"
267-
response = await client.post(
268-
self._og_llm_server_url + endpoint, json=payload, headers=headers, timeout=60
269-
)
267+
response = await client.post(self._og_llm_server_url + endpoint, json=payload, headers=headers, timeout=60)
270268

271269
content = await response.aread()
272270
result = json.loads(content.decode())
@@ -464,4 +462,3 @@ async def _parse_sse_response(response) -> AsyncGenerator[StreamChunk, None]:
464462
) as response:
465463
async for parsed_chunk in _parse_sse_response(response):
466464
yield parsed_chunk
467-

src/opengradient/defaults.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
DEFAULT_BLOCKCHAIN_EXPLORER = "https://explorer.opengradient.ai/tx/"
99
DEFAULT_OPENGRADIENT_LLM_SERVER_URL = "https://llm.opengradient.ai"
1010
DEFAULT_OPENGRADIENT_LLM_STREAMING_SERVER_URL = "https://llm.opengradient.ai"
11-

0 commit comments

Comments
 (0)