|
70 | 70 | # Standalone Functions (no wallet required) |
71 | 71 | # ============================================================================= |
72 | 72 |
|
| 73 | + |
73 | 74 | def list_models(api_url: str = "https://blockrun.ai/api") -> List[Dict[str, Any]]: |
74 | 75 | """ |
75 | 76 | List available LLM models with pricing (no wallet required). |
@@ -140,6 +141,7 @@ def list_image_models(api_url: str = "https://blockrun.ai/api") -> List[Dict[str |
140 | 141 | # LLM Client Class (requires wallet) |
141 | 142 | # ============================================================================= |
142 | 143 |
|
| 144 | + |
143 | 145 | class LLMClient: |
144 | 146 | """ |
145 | 147 | BlockRun LLM Gateway Client. |
@@ -189,6 +191,7 @@ def __init__( |
189 | 191 | if not key: |
190 | 192 | # Auto-create wallet if none exists |
191 | 193 | import sys |
| 194 | + |
192 | 195 | address, key, is_new = get_or_create_wallet() |
193 | 196 | if is_new: |
194 | 197 | print(format_wallet_created_message(address), file=sys.stderr) |
@@ -442,7 +445,11 @@ def _handle_payment_and_retry( |
442 | 445 | details = extract_payment_details(payment_required) |
443 | 446 |
|
444 | 447 | # Get the cost being paid |
445 | | - cost_usd = float(price_info.get("amount", 0)) if price_info else float(details.get("amount", 0)) / 1e6 |
| 448 | + cost_usd = ( |
| 449 | + float(price_info.get("amount", 0)) |
| 450 | + if price_info |
| 451 | + else float(details.get("amount", 0)) / 1e6 |
| 452 | + ) |
446 | 453 |
|
447 | 454 | # Create signed payment payload (v2 format) |
448 | 455 | # SECURITY: Signing happens locally - only the signature is sent to server |
@@ -595,11 +602,8 @@ def get_balance(self) -> float: |
595 | 602 | payload = { |
596 | 603 | "jsonrpc": "2.0", |
597 | 604 | "method": "eth_call", |
598 | | - "params": [ |
599 | | - {"to": usdc_contract, "data": data}, |
600 | | - "latest" |
601 | | - ], |
602 | | - "id": 1 |
| 605 | + "params": [{"to": usdc_contract, "data": data}, "latest"], |
| 606 | + "id": 1, |
603 | 607 | } |
604 | 608 |
|
605 | 609 | # Use public Base RPC |
@@ -657,6 +661,7 @@ def __init__( |
657 | 661 | if not key: |
658 | 662 | # Auto-create wallet if none exists |
659 | 663 | import sys |
| 664 | + |
660 | 665 | address, key, is_new = get_or_create_wallet() |
661 | 666 | if is_new: |
662 | 667 | print(format_wallet_created_message(address), file=sys.stderr) |
@@ -924,11 +929,8 @@ async def get_balance(self) -> float: |
924 | 929 | payload = { |
925 | 930 | "jsonrpc": "2.0", |
926 | 931 | "method": "eth_call", |
927 | | - "params": [ |
928 | | - {"to": usdc_contract, "data": data}, |
929 | | - "latest" |
930 | | - ], |
931 | | - "id": 1 |
| 932 | + "params": [{"to": usdc_contract, "data": data}, "latest"], |
| 933 | + "id": 1, |
932 | 934 | } |
933 | 935 |
|
934 | 936 | # Use public Base RPC |
|
0 commit comments