Files

1 line
4.5 KiB
JSON

{"repo": "abi5678/clawverify", "files": {"demo/qwen_live_demo.py": {"260384c9f14b60b4b69bd750ba31cdcc6db86248": {"t": 1785674244.924843, "n": 4144, "h": "9ffeacdcf98da644", "c": "#!/usr/bin/env python3\n\"\"\"\nLIVE DEMO: Qwen worker + adversarial auditor, end to end.\n\nA real qwen-max agent (via Qwen Cloud / DashScope) implements a function\nagainst a pre-written test suite. It emits a signed receipt of what it did.\nThe Hallucination Auditor independently re-runs the tests, and the Revenue\nGate pays only if every claim survives the audit.\n\nRequires: DASHSCOPE_API_KEY\n\"\"\"\n\nimport json\nimport os\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nsys.path.insert(0, str(Path(__file__).resolve().parent.parent))\n\nfrom clawverify import HallucinationAuditor, LieLedger, QwenWorkerAgent, ReceiptEmitter, RevenueGate\n\nTASK = \"\"\"Write the complete contents of a Python file `prime_utils.py` containing\na function `is_prime(n: int) -> bool` that returns True if n is a prime number.\nHandle n < 2 (not prime), 2 (prime), even numbers, and use trial division up to sqrt(n).\"\"\"\n\nTEST_FILE = '''\nfrom prime_utils import is_prime\n\ndef test_small_primes():\n assert is_prime(2) and is_prime(3) and is_prime(5) and is_prime(7)\n\ndef test_non_primes():\n assert not is_prime(0) and not is_prime(1) and not is_prime(4)\n\ndef test_negative():\n assert not is_prime(-7)\n\ndef test_larger():\n assert is_prime(97) and not is_prime(100)\n'''\n\n\ndef main():\n if not os.environ.get(\"DASHSCOPE_API_KEY\"):\n print(\"⚠️ DASHSCOPE_API_KEY not set — cannot run the live Qwen demo.\")\n print(\" Get a key from Qwen Cloud / Alibaba Cloud Model Studio, then:\")\n print(\" export DASHSCOPE_API_KEY=sk-... && python3 demo/qwen_live_demo.py\")\n return 1\n\n print(\"=\" * 80)\n print(\"🦅 CLAWVERIFY LIVE DEMO: Qwen Worker vs Adversarial Auditor\")\n print(\"=\" * 80)\n print()\n\n with tempfile.TemporaryDirectory() as tmpdir:\n source_dir = Path(tmpdir) / \"project\"\n source_dir.mkdir()\n (source_dir / \"test_prime_utils.py\").write_text(TEST_FILE)\n (source_dir / \"pytest.ini\").write_text(\"[pytest]\\npython_files = test_*.py\\n\")\n\n print(f\"📁 Project created at {source_dir} (tests pre-written, implementation missing)\")\n print()\n print(\"🤖 SCENE 1: qwen-max worker implements the task...\")\n worker = QwenWorkerAgent(emitter=ReceiptEmitter(receipts_dir=\"/tmp/clawverify-live-receipts\"))\n receipt = worker.complete_task(TASK, \"prime_utils.py\", str(source_dir))\n\n tests = receipt.metadata[\"tests\"]\n print(f\" Model: {receipt.metadata['model_name']}, tokens: {receipt.metadata['tokens_used']}\")\n print(f\" Claim: {tests['passed']} passed, {tests['failed']} failed (exit {receipt.metadata['exit_code']})\")\n print(f\" Receipt: {receipt.hash()[:16]}... (signed)\")\n print()\n\n print(\"🔍 SCENE 2: Hallucination Auditor independently re-runs the tests...\")\n auditor = HallucinationAuditor()\n audit_result = auditor.audit(receipt, {\"source_dir\": str(source_dir)})\n for finding in audit_result[\"findings\"]:\n print(f\" • {finding}\")\n print(f\" Verdict: {'✅ VERIFIED' if audit_result['verified'] else '❌ CONTRADICTION'}\")\n print()\n\n if audit_result[\"contradiction\"]:\n ledger = LieLedger(ledger_dir=\"/tmp/clawverify-live-ledger\")\n root = ledger.append(audit_result[\"contradiction\"])\n print(f\"📖 Contradiction recorded in Lie Ledger (root {root[:16]}...)\")\n print()\n\n print(\"💰 SCENE 3: Revenue Gate decides...\")\n gate = RevenueGate(mode=\"mock\", payment_log_path=\"/tmp/clawverify-live-payments.jsonl\")\n payment = gate.attempt_payment(\n agent_id=worker.agent_id,\n receipt=receipt,\n audit_result=audit_result,\n amount_cents=50000,\n description=\"Prime utils implementation\",\n )\n if payment[\"paid\"]:\n print(f\" ✅ PAID ${payment['amount_cents']/100:.2f} — work was real and verified\")\n else:\n print(f\" ❌ BLOCKED — {payment['reason']}\")\n print()\n print(json.dumps({\"verified\": audit_result[\"verified\"], \"paid\": payment[\"paid\"]}, indent=2))\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())\n"}}}}