Repository navigation
Expand file tree
/
Copy path04_async_usage.py
More file actions
85 lines (66 loc) · 2.09 KB
/
Copy path04_async_usage.py
File metadata and controls
85 lines (66 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Async workflow — health check, then one paid query, all async.
For agents, FastAPI handlers, and existing event loops.
Requires WALLET_PRIVATE_KEY in .env and USDC on Base mainnet.
Usage:
python 04_async_usage.py
"""
import asyncio
import sys
from neurobro_client import NeurobroClient
async def main() -> None:
try:
client = NeurobroClient()
except ValueError as e:
print(f"Setup error: {e}")
sys.exit(1)
print(f"Wallet: {client.wallet_address}")
print("=" * 50)
print("\n[1] Health Check")
print("-" * 30)
status = await client.health_async()
print(f"Status: {status.status}")
print(f"Version: {status.version}")
if not status.is_healthy:
print("API is not healthy. Exiting.")
sys.exit(1)
print("\n[2] Query (paid)")
print("-" * 30)
prompt = "What are the top crypto narratives driving the market right now?"
print(f"Prompt: {prompt}\n")
try:
result = await client.query_async(prompt)
print(f"\nResponse:\n{result.text}")
except Exception as e:
print(f"Query failed: {e}")
print("\nEnsure your wallet has USDC on Base mainnet.")
sys.exit(1)
print("\n" + "=" * 50)
print("Done.")
if __name__ == "__main__":
asyncio.run(main())
# Example output:
#
# Wallet: 0xA1b2C3d4E5F67890a1b2c3D4e5f6789012345678
# ==================================================
#
# [1] Health Check
# ------------------------------
# Status: healthy
# Version: 1.0.0
#
# [2] Query (paid)
# ------------------------------
# Prompt: What are the top crypto narratives driving the market right now?
#
# Response:
# Three narratives are pulling flows this cycle: (1) Solana and Base
# ecosystems absorbing retail activity with cheap, fast execution and a
# growing memecoin + consumer-app flywheel; (2) AI-adjacent tokens
# riding the agentic-infrastructure wave; and (3) real-world assets
# (RWAs) — tokenized treasuries and credit — attracting institutional
# desks looking for onchain yield.
#
# ==================================================
# Done.