Skip to content

Commit f7bca55

Browse files
author
balogh.adam@icloud.com
committed
cleanup
1 parent cb62ccd commit f7bca55

5 files changed

Lines changed: 37 additions & 41 deletions

File tree

src/opengradient/client/client.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__(
6060
twins_api_key: Optional[str] = None,
6161
rpc_url: str = DEFAULT_RPC_URL,
6262
api_url: str = DEFAULT_API_URL,
63-
contract_address: str = DEFAULT_INFERENCE_CONTRACT_ADDRESS,
64-
og_llm_server_url: Optional[str] = None,
63+
inference_contract_address: str = DEFAULT_INFERENCE_CONTRACT_ADDRESS,
64+
llm_server_url: Optional[str] = None,
6565
tee_registry_address: str = DEFAULT_TEE_REGISTRY_ADDRESS,
6666
):
6767
"""
@@ -76,54 +76,51 @@ def __init__(
7676
By default the LLM server endpoint and its TLS certificate are fetched from
7777
the on-chain TEE Registry, which stores certificates that were verified during
7878
enclave attestation. You can override the endpoint by passing
79-
``og_llm_server_url`` explicitly (the system CA bundle is used for that URL).
79+
``llm_server_url`` explicitly (the system CA bundle is used for that URL).
8080
8181
Args:
8282
private_key: Private key whose wallet holds **Base Sepolia OPG tokens**
8383
for x402 LLM payments.
8484
alpha_private_key: Private key whose wallet holds **OpenGradient testnet
8585
gas tokens** for on-chain inference. Optional -- falls back to
8686
``private_key`` for backward compatibility.
87-
email: Email for Model Hub authentication. Optional.
88-
password: Password for Model Hub authentication. Optional.
87+
email: Email for Model Hub authentication. Must be provided together
88+
with ``password``.
89+
password: Password for Model Hub authentication. Must be provided
90+
together with ``email``.
8991
twins_api_key: API key for digital twins chat (twin.fun). Optional.
9092
rpc_url: RPC URL for the OpenGradient Alpha Testnet.
9193
api_url: API URL for the OpenGradient API.
92-
contract_address: Inference contract address.
93-
og_llm_server_url: Override the LLM server URL instead of using the
94+
inference_contract_address: Inference contract address on the
95+
OpenGradient Alpha Testnet.
96+
llm_server_url: Override the LLM server URL instead of using the
9497
registry-discovered endpoint. When set, the TLS certificate is
9598
validated against the system CA bundle rather than the registry.
9699
tee_registry_address: Address of the TEERegistry contract used to
97100
discover active LLM proxy endpoints and their verified TLS certs.
98101
"""
99-
blockchain = Web3(Web3.HTTPProvider(rpc_url))
100-
wallet_account = blockchain.eth.account.from_key(private_key)
102+
if (email is None) != (password is None):
103+
raise ValueError("Both 'email' and 'password' must be provided together for Model Hub authentication.")
101104

102-
# Use a separate account for Alpha Testnet when provided
103-
if alpha_private_key is not None:
104-
alpha_wallet_account = blockchain.eth.account.from_key(alpha_private_key)
105-
else:
106-
alpha_wallet_account = wallet_account
105+
w3 = Web3(Web3.HTTPProvider(rpc_url))
106+
account = w3.eth.account.from_key(private_key)
107107

108-
hub_user = None
109-
if email is not None:
110-
hub_user = ModelHub._login_to_hub(email, password)
108+
# Use a separate account for Alpha Testnet when provided
109+
alpha_account = w3.eth.account.from_key(alpha_private_key) if alpha_private_key is not None else account
111110

112-
# Create namespaces
113-
self.model_hub = ModelHub(hub_user=hub_user)
114-
self.wallet_address = wallet_account.address
111+
self.model_hub = ModelHub(email=email, password=password)
115112

116113
self.llm = LLM(
117-
wallet_account=wallet_account,
118-
og_llm_server_url=og_llm_server_url,
114+
wallet_account=account,
115+
llm_server_url=llm_server_url,
119116
rpc_url=rpc_url,
120117
tee_registry_address=tee_registry_address,
121118
)
122119

123120
self.alpha = Alpha(
124-
blockchain=blockchain,
125-
wallet_account=alpha_wallet_account,
126-
inference_hub_contract_address=contract_address,
121+
blockchain=w3,
122+
wallet_account=alpha_account,
123+
inference_hub_contract_address=inference_contract_address,
127124
api_url=api_url,
128125
)
129126

src/opengradient/client/llm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def __init__(
7171
wallet_account: LocalAccount,
7272
rpc_url: Optional[str] = None,
7373
tee_registry_address: Optional[str] = None,
74-
og_llm_server_url: Optional[str] = None,
74+
llm_server_url: Optional[str] = None,
7575
):
7676
self._wallet_account = wallet_account
7777

7878
endpoint, tls_cert_der, tee_id, tee_payment_address = self._resolve_tee(
79-
og_llm_server_url,
79+
llm_server_url,
8080
rpc_url,
8181
tee_registry_address,
8282
)
@@ -113,7 +113,7 @@ def _resolve_tee(
113113
return tee_endpoint_override, None, None, None
114114

115115
if og_rpc_url is None or tee_registry_address is None:
116-
raise ValueError("Either og_llm_server_url or both og_rpc_url and tee_registry_address must be provided.")
116+
raise ValueError("Either llm_server_url or both rpc_url and tee_registry_address must be provided.")
117117

118118
try:
119119
registry = TEERegistry(rpc_url=og_rpc_url, registry_address=tee_registry_address)
@@ -122,7 +122,7 @@ def _resolve_tee(
122122
raise RuntimeError(f"Failed to fetch LLM TEE endpoint from registry ({tee_registry_address} on {og_rpc_url}): {e}. ") from e
123123

124124
if tee is None:
125-
raise ValueError("No active LLM proxy TEE found in the registry. Pass og_llm_server_url explicitly to override.")
125+
raise ValueError("No active LLM proxy TEE found in the registry. Pass llm_server_url explicitly to override.")
126126

127127
logger.info("Using TEE endpoint from registry: %s (teeId=%s)", tee.endpoint, tee.tee_id)
128128
return tee.endpoint, tee.tls_cert_der, tee.tee_id, tee.payment_address

src/opengradient/client/model_hub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class ModelHub:
3333
client.model_hub.upload("model.onnx", repo.name, repo.version)
3434
"""
3535

36-
def __init__(self, hub_user: Optional[Dict] = None):
37-
self._hub_user = hub_user
36+
def __init__(self, email: Optional[str] = None, password: Optional[str] = None):
37+
self._hub_user = self._login(email, password) if email is not None else None
3838

3939
@staticmethod
40-
def _login_to_hub(email, password):
40+
def _login(email: str, password: Optional[str]):
4141
if not _FIREBASE_CONFIG.get("apiKey"):
4242
raise ValueError("Firebase API Key is missing in environment variables")
4343

tests/client_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
x402SettlementMode,
1414
)
1515

16-
1716
# --- Fixtures ---
1817

1918

@@ -71,7 +70,7 @@ def test_client_initialization_without_auth(self, mock_web3, mock_abi_files):
7170
private_key="0x" + "a" * 64,
7271
rpc_url="https://test.rpc.url",
7372
api_url="https://test.api.url",
74-
contract_address="0x" + "b" * 40,
73+
inference_contract_address="0x" + "b" * 40,
7574
)
7675

7776
assert client.model_hub._hub_user is None
@@ -93,7 +92,7 @@ def test_client_initialization_with_auth(self, mock_web3, mock_abi_files):
9392
private_key="0x" + "a" * 64,
9493
rpc_url="https://test.rpc.url",
9594
api_url="https://test.api.url",
96-
contract_address="0x" + "b" * 40,
95+
inference_contract_address="0x" + "b" * 40,
9796
email="test@test.com",
9897
password="test_password",
9998
)
@@ -109,8 +108,8 @@ def test_client_initialization_custom_llm_urls(self, mock_web3, mock_abi_files):
109108
private_key="0x" + "a" * 64,
110109
rpc_url="https://test.rpc.url",
111110
api_url="https://test.api.url",
112-
contract_address="0x" + "b" * 40,
113-
og_llm_server_url=custom_llm_url,
111+
inference_contract_address="0x" + "b" * 40,
112+
llm_server_url=custom_llm_url,
114113
)
115114

116115
assert client.llm._tee_endpoint == custom_llm_url
@@ -137,7 +136,7 @@ def test_login_to_hub_success(self, mock_web3, mock_abi_files):
137136
private_key="0x" + "a" * 64,
138137
rpc_url="https://test.rpc.url",
139138
api_url="https://test.api.url",
140-
contract_address="0x" + "b" * 40,
139+
inference_contract_address="0x" + "b" * 40,
141140
email="user@test.com",
142141
password="password123",
143142
)
@@ -160,7 +159,7 @@ def test_login_to_hub_failure(self, mock_web3, mock_abi_files):
160159
private_key="0x" + "a" * 64,
161160
rpc_url="https://test.rpc.url",
162161
api_url="https://test.api.url",
163-
contract_address="0x" + "b" * 40,
162+
inference_contract_address="0x" + "b" * 40,
164163
email="user@test.com",
165164
password="wrong_password",
166165
)

tests/llm_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def _make_llm(
119119
"""Build an LLM with an explicit server URL (skips registry lookup)."""
120120
wallet = MagicMock()
121121
wallet.address = "0x" + "ab" * 20
122-
llm = LLM(wallet_account=wallet, og_llm_server_url=endpoint)
123-
# og_llm_server_url path sets tee_id/payment_address to None; set them for assertions.
122+
llm = LLM(wallet_account=wallet, llm_server_url=endpoint)
123+
# llm_server_url path sets tee_id/payment_address to None; set them for assertions.
124124
llm._tee_id = "test-tee-id"
125125
llm._tee_payment_address = "0xTestPayment"
126126
return llm

0 commit comments

Comments
 (0)