Add compare_pipelines skill script
Browse files
openclaw/skills/compare_pipelines/compare_pipelines.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
OpenClaw Skill: compare_pipelines
|
| 4 |
+
Run dual-pipeline comparison and return structured results.
|
| 5 |
+
"""
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import requests
|
| 10 |
+
|
| 11 |
+
API_BASE = os.getenv("GRAPHRAG_API_BASE", "http://localhost:3000")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def compare_pipelines(query: str, provider: str = "anthropic", model: str = None) -> dict:
|
| 15 |
+
"""Compare Baseline RAG vs GraphRAG on a query."""
|
| 16 |
+
try:
|
| 17 |
+
payload = {"query": query, "adaptiveRouting": True}
|
| 18 |
+
if provider:
|
| 19 |
+
payload["provider"] = provider
|
| 20 |
+
if model:
|
| 21 |
+
payload["model"] = model
|
| 22 |
+
|
| 23 |
+
response = requests.post(f"{API_BASE}/api/compare", json=payload, timeout=120)
|
| 24 |
+
response.raise_for_status()
|
| 25 |
+
data = response.json()
|
| 26 |
+
|
| 27 |
+
b = data.get("baseline", {})
|
| 28 |
+
g = data.get("graphrag", {})
|
| 29 |
+
|
| 30 |
+
return {
|
| 31 |
+
"query": query,
|
| 32 |
+
"baseline": {
|
| 33 |
+
"answer": b.get("answer", ""),
|
| 34 |
+
"tokens": b.get("tokens", 0),
|
| 35 |
+
"latency_ms": b.get("latencyMs", 0),
|
| 36 |
+
"cost_usd": b.get("costUsd", 0),
|
| 37 |
+
},
|
| 38 |
+
"graphrag": {
|
| 39 |
+
"answer": g.get("answer", ""),
|
| 40 |
+
"tokens": g.get("tokens", 0),
|
| 41 |
+
"latency_ms": g.get("latencyMs", 0),
|
| 42 |
+
"cost_usd": g.get("costUsd", 0),
|
| 43 |
+
"entities_found": len(g.get("entities", [])),
|
| 44 |
+
"relations_found": len(g.get("relations", [])),
|
| 45 |
+
},
|
| 46 |
+
"complexity": data.get("complexity", 0),
|
| 47 |
+
"query_type": data.get("queryType", "unknown"),
|
| 48 |
+
"recommended": data.get("recommended", "baseline"),
|
| 49 |
+
"token_ratio": g.get("tokens", 1) / max(b.get("tokens", 1), 1),
|
| 50 |
+
}
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return {"error": str(e)}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
query = sys.argv[1] if len(sys.argv) > 1 else "What is the capital of France?"
|
| 57 |
+
provider = sys.argv[2] if len(sys.argv) > 2 else "anthropic"
|
| 58 |
+
result = compare_pipelines(query, provider)
|
| 59 |
+
print(json.dumps(result, indent=2))
|