X402hyperlayer commited on
Commit
ac9783e
·
verified ·
1 Parent(s): adef846

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +40 -0
utils.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils.py
2
+ # Helper utilities for HyperLayer demo Space
3
+ # - formatting helpers
4
+ # - placeholder functions for RPC / model calls
5
+ # - lightweight caching (in-memory)
6
+
7
+ import time
8
+ import random
9
+ from typing import Dict, Any
10
+
11
+ def nice_number(n: int) -> str:
12
+ """Format number with commas."""
13
+ return f"{n:,}"
14
+
15
+ def mock_trading_volume() -> Dict[str, Any]:
16
+ """Return a simulated trading volume object (used in demo)."""
17
+ vol = random.randint(30_000, 120_000)
18
+ return {
19
+ "timestamp": int(time.time()),
20
+ "volume_usd": vol,
21
+ "formatted": f"${nice_number(vol)}",
22
+ "note": "Simulated data for demo purposes"
23
+ }
24
+
25
+ def simulate_agent_response(prompt: str, mode: str = "explain") -> str:
26
+ """Return a deterministic-ish simulated response for UI demo."""
27
+ prefix = {
28
+ "explain": "Explained:",
29
+ "summarize": "Summary:",
30
+ "detect": "Detected intent:",
31
+ "tokenize": "Tokenized:"
32
+ }.get(mode, "Response:")
33
+ time.sleep(0.25) # tiny delay to mimic processing
34
+ sample_responses = [
35
+ "Low-latency aggregation applied across shards.",
36
+ "Agent orchestrated securely via MPC endpoints.",
37
+ "Found 3 potential optimizations for throughput.",
38
+ "Simulated policy verified; no anomalies detected."
39
+ ]
40
+ return f"{prefix} {random.choice(sample_responses)} (for: {prompt[:80]})"