|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import json |
| 3 | +import urllib.request |
| 4 | + |
| 5 | + |
| 6 | +def req(method, url, data=None): |
| 7 | + b = json.dumps(data).encode() if data else None |
| 8 | + r = urllib.request.Request( |
| 9 | + url, data=b, headers={"Content-Type": "application/json"}, method=method |
| 10 | + ) |
| 11 | + return json.loads(urllib.request.urlopen(r, timeout=90).read().decode()) |
| 12 | + |
| 13 | + |
| 14 | +q = "What did ministers say about water management recently?" |
| 15 | +for port, name in [(8013, "green"), (8003, "blue")]: |
| 16 | + try: |
| 17 | + t = req("POST", f"http://127.0.0.1:{port}/chat/threads") |
| 18 | + res = req( |
| 19 | + "POST", |
| 20 | + f"http://127.0.0.1:{port}/chat/threads/{t['thread_id']}/messages", |
| 21 | + {"content": q}, |
| 22 | + ) |
| 23 | + dbg = (res.get("debug") or {}).get("retrieval") or {} |
| 24 | + print(f"[{name}]") |
| 25 | + print(f" edge_count={dbg.get('edge_count')}") |
| 26 | + print(f" node_count={dbg.get('node_count')}") |
| 27 | + print(f" seed_count={dbg.get('seed_count')}") |
| 28 | + print(f" threshold={dbg.get('edge_rank_threshold')}") |
| 29 | + print(f" filtered={dbg.get('edges_filtered_by_threshold')}") |
| 30 | + print(f" skipped={dbg.get('edge_rank_filter_skipped_no_scores')}") |
| 31 | + print(f" sources={len(res.get('sources') or [])}") |
| 32 | + print( |
| 33 | + f" snippet={(res.get('assistant_message', {}).get('content', '')[:150]).replace(chr(10), ' ')}" |
| 34 | + ) |
| 35 | + except Exception as e: |
| 36 | + print(f"[{name}] ERROR: {e}") |
| 37 | + print() |
0 commit comments