File size: 2,779 Bytes
3c332d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from researchbench.generation import estimate_generation_model_calls, parse_matched_score, run_generation_record, score_generation
from researchbench.clients import MockClient


def test_parse_matched_score_accepts_zero_to_five() -> None:
    assert parse_matched_score("**Matched score starts:** 4 **Matched score ends**") == 4.0
    assert parse_matched_score("Reason: ok\nMatched score: 4") == 4.0
    assert parse_matched_score("Matched score: 5.0") == 5.0
    assert parse_matched_score("Matched score: 6") is None
    assert parse_matched_score("no score") is None


def test_score_generation_normalizes_average_matched_score() -> None:
    predictions = [
        {"sample_id": "s1", "final_hypothesis": "hypothesis", "matched_score": 2},
        {"sample_id": "s2", "final_hypothesis": "hypothesis", "matched_score": 4},
    ]
    data = [
        {"sample_id": "s1", "gold_hypothesis": "gold 1"},
        {"sample_id": "s2", "gold_hypothesis": "gold 2"},
    ]
    result = score_generation(predictions, data, MockClient())

    assert result["summary"]["average_score"] == 3.0
    assert result["summary"]["accuracy"] == 0.6


def test_run_generation_accepts_legacy_ture_retrieve_key() -> None:
    record = {
        "sample_id": "s1",
        "research_question": "question",
        "background_survey": "survey",
        "ture_retrieve": [{"title": "Inspiration", "abstract": "abstract"}],
    }
    result = run_generation_record(record, MockClient(), num_mutations=1, num_itr_self_refine=1)

    assert "moosechem_trace" in result
    assert result["moosechem_trace"]["inspiration_results"][0]["inspiration_title"] == "Inspiration"
    assert result["final_hypothesis"]


def test_run_generation_defaults_to_no_background_survey_for_moosechem_reproducibility() -> None:
    record = {
        "sample_id": "s1",
        "research_question": "question",
        "background_survey": "private survey text",
        "gold_inspirations": [{"title": "Inspiration", "abstract": "abstract"}],
    }
    result = run_generation_record(record, MockClient(), num_mutations=1, num_itr_self_refine=1)
    prompt = result["moosechem_trace"]["inspiration_results"][0]["mutations"]["0"]["trace"][0]["prompt"]

    assert "Survey not provided. Please overlook the survey." in prompt
    assert "private survey text" not in prompt
    assert result["moosechem_trace"]["params"]["if_use_background_survey"] is False


def test_estimate_generation_model_calls_default_three_inspirations() -> None:
    record = {
        "sample_id": "s1",
        "gold_inspirations": [
            {"title": "A", "abstract": "a"},
            {"title": "B", "abstract": "b"},
            {"title": "C", "abstract": "c"},
        ],
    }

    assert estimate_generation_model_calls(record) == 105