Download examples/query_the_mind.py from ShoggothMind/mind-v1: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/ShoggothMind/mind-v1/resolve/main/examples/query_the_mind.py
- Command line
-
hf download hf://ShoggothMind/mind-v1/examples/query_the_mind.py
-
curl -L -o query_the_mind.py https://huggingface.co/ShoggothMind/mind-v1/resolve/main/examples/query_the_mind.py
3.03 kB
| #!/usr/bin/env python3 | |
| """ | |
| The Mind: Real-Time Consensus Query Client | |
| Queries the live verified consensus state and real multi-model inference from The Mind API. | |
| Protocol: Solana Autonomous Consensus Swarm | |
| """ | |
| import sys | |
| import argparse | |
| import json | |
| import requests | |
| def get_latest_hour(base_url: str): | |
| """Fetch the latest sealed round from The Mind.""" | |
| url = f"{base_url.rstrip('/')}/api/hours/latest" | |
| try: | |
| res = requests.get(url, timeout=10) | |
| res.raise_for_status() | |
| return res.json() | |
| except Exception as e: | |
| print(f"Error fetching latest round from {url}: {e}", file=sys.stderr) | |
| return None | |
| def ask_consensus(base_url: str, question: str): | |
| """Query The Mind multi-model consensus swarm with a question.""" | |
| url = f"{base_url.rstrip('/')}/api/ask" | |
| payload = {"question": question} | |
| try: | |
| res = requests.post(url, json=payload, timeout=25) | |
| res.raise_for_status() | |
| return res.json() | |
| except Exception as e: | |
| print(f"Error asking consensus swarm at {url}: {e}", file=sys.stderr) | |
| return None | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Query The Mind autonomous consensus API.") | |
| parser.add_argument("--base-url", default="https://shoggothmind.live", help="Base URL of The Mind API (default: https://shoggothmind.live)") | |
| parser.add_argument("--ask", default="What is the current state of The Mind autonomous consensus?", help="Question to query the consensus swarm") | |
| parser.add_argument("--latest-hour", action="store_true", help="Fetch and print the latest sealed hourly consensus round") | |
| args = parser.parse_args() | |
| print(f"Connecting to The Mind API at: {args.base_url}") | |
| if args.latest_hour or not args.ask: | |
| print("\n--- Latest Sealed Round ---") | |
| hour_data = get_latest_hour(args.base_url) | |
| if hour_data: | |
| print(f"Round Hour ID: {hour_data.get('id', 'N/A')}") | |
| print(f"Merkle Root: {hour_data.get('root', 'N/A')}") | |
| print(f"Solana Memo Sig: {hour_data.get('sealSignature', 'N/A')}") | |
| print(f"Questions Evaluated: {len(hour_data.get('questions', []))}") | |
| print(f"Mind Consensus Score: {hour_data.get('mindCorrect', 'N/A')} / {len(hour_data.get('questions', []))}") | |
| print(f"Active Tentacles: {len(hour_data.get('results', []))}") | |
| if args.ask: | |
| print(f"\n--- Consensus Question: \"{args.ask}\" ---") | |
| answer_data = ask_consensus(args.base_url, args.ask) | |
| if answer_data: | |
| print(f"Synthesized Verdict: {answer_data.get('verdict')}") | |
| print(f"Consensus Confidence: {answer_data.get('confidence')}%") | |
| answers = answer_data.get('answers', []) | |
| print(f"Contributing Models ({len(answers)}):") | |
| for a in answers: | |
| status = "AGREED" if a.get("agrees") else "DISSENT" | |
| print(f" • [{status}] {a.get('model')}: {a.get('text')}") | |
| if __name__ == "__main__": | |
| main() | |