forked from gpt-engineer-org/gpt-engineer
-
Notifications
You must be signed in to change notification settings - Fork 8
/
steps.py
68 lines (54 loc) · 1.77 KB
/
steps.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from ai import AI
from chat_to_files import to_files
from db import DBs
import json
def setup_sys_prompt(dbs):
return dbs.identity['setup'] + '\nUseful to know:\n' + dbs.identity['philosophy']
def run(ai: AI, dbs: DBs):
'''Run the AI on the main prompt and save the results'''
messages = ai.start(setup_sys_prompt(dbs), dbs.input['main_prompt'])
to_files(messages[-1]['content'], dbs.workspace)
return messages
def clarify(ai: AI, dbs: DBs):
'''Ask the user if they want to clarify anything and save the results to the workspace'''
messages = [ai.fsystem(dbs.identity['qa'])]
user = dbs.input['main_prompt']
while True:
messages = ai.next(messages, user)
if messages[-1]['content'].strip().lower() == 'no':
break
print()
user = input('(answer in text, or "q" to move on)\n')
print()
if not user or user == 'q':
break
user += (
'\n\n'
'Is anything else unclear? If yes, only answer in the form:\n'
'{remaining unclear areas} remaining questions.\n'
'{Next question}\n'
'If everything is sufficiently clear, only answer "no".'
)
print()
return messages
def run_clarified(ai: AI, dbs: DBs):
# get the messages from previous step
messages = json.loads(dbs.logs[clarify.__name__])
messages = (
[
ai.fsystem(setup_sys_prompt(dbs)),
] +
messages[1:]
)
messages = ai.next(messages, dbs.identity['use_qa'])
to_files(messages[-1]['content'], dbs.workspace)
return messages
STEPS=[
clarify,
run_clarified
]
# Future steps that can be added:
# improve_files,
# add_tests
# run_tests_and_fix_files,
# improve_based_on_in_file_feedback_comments