File size: 8,198 Bytes
51457b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8412998
 
 
 
 
51457b7
 
 
 
 
 
 
 
 
 
 
8412998
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51457b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class SeedSpec:
    seed_id: str
    entrypoint: str
    prompt: str
    canonical_solution: str
    test: str

    @property
    def original_code(self) -> str:
        return f"{self.prompt}\n{self.canonical_solution}"


SEED_BANK = (
    SeedSpec(
        seed_id="HumanEval/0",
        entrypoint="has_close_elements",
        prompt="def has_close_elements(numbers: list[float], threshold: float) -> bool:",
        canonical_solution=(
            "    for idx, elem in enumerate(numbers):\n"
            "        for idx2, elem2 in enumerate(numbers):\n"
            "            if idx != idx2:\n"
            "                distance = abs(elem - elem2)\n"
            "                if distance < threshold:\n"
            "                    return True\n"
            "    return False\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([1.0, 2.0, 3.0], 0.5) is False\n"
            "    assert candidate([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) is True\n\n"
            "check(has_close_elements)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/1",
        entrypoint="sum_to_n",
        prompt="def sum_to_n(n: int) -> int:",
        canonical_solution=(
            "    total = 0\n"
            "    for value in range(n + 1):\n"
            "        total += value\n"
            "    return total\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate(0) == 0\n"
            "    assert candidate(1) == 1\n"
            "    assert candidate(5) == 15\n"
            "    assert candidate(10) == 55\n\n"
            "check(sum_to_n)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/2",
        entrypoint="middle_slice",
        prompt="def middle_slice(values: list[int]) -> list[int]:",
        canonical_solution=(
            "    if len(values) <= 2:\n"
            "        return []\n"
            "    return values[1:-1]\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([1]) == []\n"
            "    assert candidate([1, 2]) == []\n"
            "    assert candidate([1, 2, 3]) == [2]\n"
            "    assert candidate([1, 2, 3, 4, 5]) == [2, 3, 4]\n\n"
            "check(middle_slice)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/3",
        entrypoint="is_non_decreasing",
        prompt="def is_non_decreasing(values: list[int]) -> bool:",
        canonical_solution=(
            "    return all(values[idx] <= values[idx + 1] for idx in range(len(values) - 1))\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([]) is True\n"
            "    assert candidate([5]) is True\n"
            "    assert candidate([1, 2, 2, 3]) is True\n"
            "    assert candidate([3, 2]) is False\n"
            "    assert candidate([1, 3, 2, 4]) is False\n\n"
            "check(is_non_decreasing)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/4",
        entrypoint="count_nonempty",
        prompt="def count_nonempty(strings: list[str]) -> int:",
        canonical_solution=(
            "    total = 0\n"
            "    for text in strings:\n"
            "        if len(text) > 0:\n"
            "            total += 1\n"
            "    return total\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([]) == 0\n"
            "    assert candidate(['', '']) == 0\n"
            "    assert candidate(['a', '', 'bc', '']) == 2\n"
            "    assert candidate(['hi', 'there']) == 2\n\n"
            "check(count_nonempty)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/5",
        entrypoint="running_max",
        prompt="def running_max(values: list[int]) -> int:",
        canonical_solution=(
            "    best = values[0]\n"
            "    for idx in range(1, len(values)):\n"
            "        if values[idx] > best:\n"
            "            best = values[idx]\n"
            "    return best\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([3]) == 3\n"
            "    assert candidate([3, 1, 5, 2]) == 5\n"
            "    assert candidate([-1, -4, -2]) == -1\n"
            "    assert candidate([0, 0, 0]) == 0\n\n"
            "check(running_max)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/6",
        entrypoint="first_index_of",
        prompt="def first_index_of(values: list[int], target: int) -> int:",
        canonical_solution=(
            "    for idx, value in enumerate(values):\n"
            "        if value == target:\n"
            "            return idx\n"
            "    return -1\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([], 3) == -1\n"
            "    assert candidate([1, 2, 3], 1) == 0\n"
            "    assert candidate([1, 2, 3], 3) == 2\n"
            "    assert candidate([5, 7, 5, 7], 7) == 1\n"
            "    assert candidate([9, 8], 4) == -1\n\n"
            "check(first_index_of)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/7",
        entrypoint="drop_last",
        prompt="def drop_last(values: list[int]) -> list[int]:",
        canonical_solution=(
            "    if not values:\n"
            "        return []\n"
            "    return values[:-1]\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([]) == []\n"
            "    assert candidate([1]) == []\n"
            "    assert candidate([1, 2]) == [1]\n"
            "    assert candidate([1, 2, 3, 4]) == [1, 2, 3]\n"
            "    assert candidate([7, 7, 7]) == [7, 7]\n\n"
            "check(drop_last)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/8",
        entrypoint="count_greater_than",
        prompt="def count_greater_than(values: list[int], threshold: int) -> int:",
        canonical_solution=(
            "    total = 0\n"
            "    for value in values:\n"
            "        if value > threshold:\n"
            "            total += 1\n"
            "    return total\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([], 1) == 0\n"
            "    assert candidate([1, 2, 3], 2) == 1\n"
            "    assert candidate([4, 5, 6], 3) == 3\n"
            "    assert candidate([0, -1, 2, 2], 1) == 2\n"
            "    assert candidate([5, 5, 5], 5) == 0\n\n"
            "check(count_greater_than)\n"
        ),
    ),
    SeedSpec(
        seed_id="DebugZero/9",
        entrypoint="prefix_sums",
        prompt="def prefix_sums(values: list[int]) -> list[int]:",
        canonical_solution=(
            "    total = 0\n"
            "    result = []\n"
            "    for value in values:\n"
            "        total += value\n"
            "        result.append(total)\n"
            "    return result\n"
        ),
        test=(
            "def check(candidate):\n"
            "    assert candidate([]) == []\n"
            "    assert candidate([3]) == [3]\n"
            "    assert candidate([1, 2, 3]) == [1, 3, 6]\n"
            "    assert candidate([2, -1, 4]) == [2, 1, 5]\n"
            "    assert candidate([0, 0, 0]) == [0, 0, 0]\n\n"
            "check(prefix_sums)\n"
        ),
    ),
)

SEED_BY_ID = {seed.seed_id: seed for seed in SEED_BANK}


def get_seed_by_id(seed_id: str) -> SeedSpec:
    return SEED_BY_ID[seed_id]


def legacy_seed_dict(seed: SeedSpec) -> dict[str, str]:
    return {
        "seed_id": seed.seed_id,
        "entrypoint": seed.entrypoint,
        "prompt": seed.prompt,
        "canonical_solution": seed.canonical_solution,
        "test": seed.test,
    }


HUMANEVAL_SEED = legacy_seed_dict(SEED_BANK[0])