Files
langchain4j-demo/local-tool-calling/scripts/summarize.py
T
asmhatreandClaude Sonnet 5.5 f4f90b3b30 Add local-tool-calling module: six small Ollama models scored on one MCP-served tool suite
Four tools served over MCP, twelve prompts, LangChain4j 1.24.0 OllamaChatModel, a scorer that validates each call against the tool's own JSON schema, and scripts to run and summarise the benchmark.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b3obqqePfZ9m2Jk5Ub
2026-11-26 19:05:53 +05:30

33 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
"""ENVEL = the subset of SCHEMA where the real arguments arrive wrapped in an envelope, under a "parameters" or "arguments" key.
Reads results/*.jsonl (written by Benchmark) and prints one summary table. Pure counting, no model involved."""
import glob, json, collections, sys
ORDER = ["VALID", "HALLUCINATED_TOOL", "SCHEMA_INVALID", "WRONG_TOOL", "WRONG_VALUE", "PARTIAL", "NO_CALL", "SPURIOUS_CALL"]
HEAD = ["VALID", "HALLU", "SCHEMA", "WTOOL", "WVAL", "PART", "NOCALL", "SPUR"]
args = [x for x in sys.argv[1:] if not x.startswith("--")]
files = sorted(glob.glob((args[0] if args else "results") + "/*.jsonl"))
print(f"{'model':<14} {'n':>3} " + " ".join(f"{h:>6}" for h in HEAD) + f" {'ENVEL':>6} {'JSONtx':>6} {'s/call':>7}")
for f in files:
rows = [json.loads(l) for l in open(f)]
c = collections.Counter(r["outcome"] for r in rows)
env = sum(1 for r in rows if r["outcome"] == "SCHEMA_INVALID" and any("unknown argument 'parameters'" in n or "unknown argument 'arguments'" in n for n in r["notes"]))
jt = sum(1 for r in rows if r["jsonInText"])
sec = sum(r["ms"] for r in rows) / len(rows) / 1000
print(f"{rows[0]['model']:<14} {len(rows):>3} " + " ".join(f"{c.get(o, 0):>6}" for o in ORDER) + f" {env:>6} {jt:>6} {sec:>7.1f}")
# Per-case view: how many of the runs were VALID for each prompt.
if "--cases" in sys.argv:
by = collections.defaultdict(collections.Counter)
models = []
for f in files:
rows = [json.loads(l) for l in open(f)]
models.append(rows[0]["model"])
for r in rows:
by[r["case"]][(r["model"], "n")] += 1
by[r["case"]][(r["model"], "ok")] += r["outcome"] == "VALID"
print()
print(f"{'case':<24} " + " ".join(f"{m:>13}" for m in models))
for case in sorted(by):
print(f"{case:<24} " + " ".join(f"{str(by[case][(m, 'ok')]) + '/' + str(by[case][(m, 'n')]):>13}" for m in models))