ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s

This commit is contained in:
2026-08-20 13:12:50 +00:00
commit b119135836
10275 changed files with 3284984 additions and 0 deletions
@@ -0,0 +1,76 @@
import pytest
pytest.importorskip("pandas")
"""
Test suite for compute_mle_elo calibration model and calibration rating handling.
"""
import sys
from pathlib import Path
import pandas as pd
HERE = Path(__file__).resolve().parent.parent
ELO_DIR = HERE / "chapter7" / "elo-leaderboard"
if str(ELO_DIR) not in sys.path:
sys.path.insert(0, str(ELO_DIR))
from bradley_terry import compute_mle_elo # noqa: E402
def test_compute_mle_elo_calibration_model_default_none_rating():
df = pd.DataFrame(
[
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_a"},
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_b"},
]
)
res = compute_mle_elo(df, calibration_model="gpt-4")
assert "gpt-4" in res.index
assert res["gpt-4"] == 1000.0
def test_compute_mle_elo_explicit_calibration_rating():
df = pd.DataFrame(
[
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_a"},
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_b"},
]
)
res = compute_mle_elo(df, calibration_model="gpt-4", calibration_rating=1200.0)
assert "gpt-4" in res.index
assert abs(res["gpt-4"] - 1200.0) < 1e-6
def test_compute_mle_elo_custom_init_rating_and_calibration():
df = pd.DataFrame(
[
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_a"},
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_b"},
]
)
res = compute_mle_elo(df, INIT_RATING=1500, calibration_model="gpt-4")
assert "gpt-4" in res.index
assert res["gpt-4"] == 1500.0
def test_compute_mle_elo_calibration_model_not_in_df():
df = pd.DataFrame(
[
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_a"},
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_b"},
]
)
res = compute_mle_elo(df, calibration_model="non_existent_model")
assert "gpt-4" in res.index
assert "claude-3" in res.index
def test_compute_mle_elo_no_calibration():
df = pd.DataFrame(
[
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_a"},
{"model_a": "gpt-4", "model_b": "claude-3", "winner": "model_b"},
]
)
res = compute_mle_elo(df, calibration_model=None)
assert "gpt-4" in res.index
assert "claude-3" in res.index