|
6 | 6 | from typing import AsyncGenerator, Awaitable, Callable, Dict, List, Optional, TypeVar, Union |
7 | 7 | import httpx |
8 | 8 | import asyncio |
| 9 | +import os |
9 | 10 |
|
10 | 11 | from eth_account import Account |
11 | 12 | from eth_account.account import LocalAccount |
|
28 | 29 | X402_PROCESSING_HASH_HEADER = "x-processing-hash" |
29 | 30 | X402_PLACEHOLDER_API_KEY = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" |
30 | 31 | BASE_TESTNET_NETWORK = "eip155:84532" |
| 32 | +BASE_TESTNET_RPC = os.getenv("BASE_TESTNET_RPC", "https://sepolia.base.org") |
31 | 33 |
|
32 | 34 | _CHAT_ENDPOINT = "/v1/chat/completions" |
33 | 35 | _COMPLETION_ENDPOINT = "/v1/completions" |
@@ -84,7 +86,7 @@ def __init__( |
84 | 86 | raise ValueError("A private key is required to use the LLM client. Pass a valid private_key to the constructor.") |
85 | 87 | self._wallet_account: LocalAccount = Account.from_key(private_key) |
86 | 88 |
|
87 | | - x402_client = LLM._build_x402_client(private_key) |
| 89 | + x402_client = LLM._build_x402_client(private_key, rpc_url=BASE_TESTNET_RPC) |
88 | 90 | onchain_registry = TEERegistry(rpc_url=rpc_url, registry_address=tee_registry_address) |
89 | 91 | self._tee: TEEConnectionInterface = RegistryTEEConnection(x402_client=x402_client, registry=onchain_registry) |
90 | 92 |
|
@@ -114,13 +116,18 @@ def from_url( |
114 | 116 | return instance |
115 | 117 |
|
116 | 118 | @staticmethod |
117 | | - def _build_x402_client(private_key: str) -> x402Client: |
| 119 | + def _build_x402_client(private_key: str, rpc_url: str = BASE_TESTNET_RPC) -> x402Client: |
118 | 120 | """Build the x402 payment stack from a private key.""" |
119 | 121 | account = Account.from_key(private_key) |
120 | 122 | signer = EthAccountSigner(account) |
121 | 123 | client = x402Client() |
122 | 124 | register_exact_evm_client(client, signer, networks=[BASE_TESTNET_NETWORK]) |
123 | | - register_upto_evm_client(client, signer, networks=[BASE_TESTNET_NETWORK]) |
| 125 | + register_upto_evm_client( |
| 126 | + client, |
| 127 | + signer, |
| 128 | + networks=[BASE_TESTNET_NETWORK], |
| 129 | + rpc_url=rpc_url, |
| 130 | + ) |
124 | 131 | return client |
125 | 132 |
|
126 | 133 | # ── Lifecycle ─────────────────────────────────────────────────────── |
|
0 commit comments