-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrun_dfs.py
53 lines (44 loc) · 1.35 KB
/
run_dfs.py
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
import llm
from lang import score_func, can_be_solution, verifier_feedback
from prompts import prompt, expansion_count, min_lines, check_func, check_cheat_func
from common import limit_depth, max_completion_depth
import random
solution = None
def generate_complete(text):
text = llm.generate(text, 1)[0]
score = score_func(text)
if score is not None:
if score < 0:
return (text, score)
else:
if can_be_solution(text, min_lines, check_func):
global solution
solution = text
return (text, score)
else:
return (text, 0.3)
def random_index(n):
cs = []
for i in range(0, n):
for j in range(0, (n-i)**2):
cs.append(i)
return random.choice(cs)
def main():
queue = [prompt]
while solution is None and queue != []:
text = queue[0]
(text, score) = generate_complete(text)
not_cheat = not check_cheat_func(text)
if score > 0 and not_cheat:
queue = [text] + queue
else:
i = random_index(len(queue))
queue = queue[i:]
if not_cheat and i==0:
hint = verifier_feedback(queue[0], text)
if hint:
queue = [hint] + queue
print('CHOSEN SOLUTION')
print(solution)
if __name__ == "__main__":
main()