x402Hyper_Layer / utils.py
X402hyperlayer's picture
Create utils.py
ac9783e verified
# utils.py
# Helper utilities for HyperLayer demo Space
# - formatting helpers
# - placeholder functions for RPC / model calls
# - lightweight caching (in-memory)
import time
import random
from typing import Dict, Any
def nice_number(n: int) -> str:
"""Format number with commas."""
return f"{n:,}"
def mock_trading_volume() -> Dict[str, Any]:
"""Return a simulated trading volume object (used in demo)."""
vol = random.randint(30_000, 120_000)
return {
"timestamp": int(time.time()),
"volume_usd": vol,
"formatted": f"${nice_number(vol)}",
"note": "Simulated data for demo purposes"
}
def simulate_agent_response(prompt: str, mode: str = "explain") -> str:
"""Return a deterministic-ish simulated response for UI demo."""
prefix = {
"explain": "Explained:",
"summarize": "Summary:",
"detect": "Detected intent:",
"tokenize": "Tokenized:"
}.get(mode, "Response:")
time.sleep(0.25) # tiny delay to mimic processing
sample_responses = [
"Low-latency aggregation applied across shards.",
"Agent orchestrated securely via MPC endpoints.",
"Found 3 potential optimizations for throughput.",
"Simulated policy verified; no anomalies detected."
]
return f"{prefix} {random.choice(sample_responses)} (for: {prompt[:80]})"