forked from AntonOsika/gpt-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate into steps and wrap filesystem access
- Loading branch information
1 parent
026ac20
commit 15b353d
Showing
13 changed files
with
183 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
input | ||
memory | ||
TODO.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
import openai | ||
|
||
|
||
class AI: | ||
def __init__(self, **kwargs): | ||
self.kwargs = kwargs | ||
|
||
def start(self, system, user): | ||
messages = [ | ||
{"role": "system", "content": system}, | ||
{"role": "user", "content": user}, | ||
] | ||
|
||
return self.next(messages) | ||
|
||
def fsystem(self, msg): | ||
return {"role": "system", "content": msg} | ||
|
||
def fuser(self, msg): | ||
return {"role": "user", "content": msg} | ||
|
||
def next(self, messages, prompt=None): | ||
if prompt: | ||
messages = messages + [{"role": "user", "content": prompt}] | ||
|
||
response = openai.ChatCompletion.create( | ||
messages=messages, | ||
**self.kwargs | ||
) | ||
|
||
chat = [] | ||
for chunk in response: | ||
delta = chunk['choices'][0]['delta'] | ||
msg = delta.get('content', '') | ||
print(msg, end="") | ||
chat.append(msg) | ||
return messages + [{"role": "assistant", "content": "".join(chat)}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
from dataclasses import dataclass | ||
import os | ||
from pathlib import Path | ||
|
||
|
||
class DB: | ||
def __init__(self, path): | ||
self.path = Path(path).absolute() | ||
os.makedirs(self.path, exist_ok=True) | ||
|
||
def __getitem__(self, key): | ||
with open(self.path / key) as f: | ||
return f.read() | ||
|
||
def __setitem__(self, key, val): | ||
with open(self.path / key, 'w') as f: | ||
f.write(val) | ||
|
||
|
||
# dataclass for all dbs: | ||
@dataclass | ||
class DBs: | ||
memory: DB | ||
logs: DB | ||
identity: DB | ||
input: DB | ||
workspace: DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
You will improve instructions by reading: | ||
1. ORIGINAL INSTRUCTIONS | ||
2. CLARIFYING QUESTIONS AND ANSWERS | ||
|
||
As output you will give a new version of the original instruction but where the answers to the clarifying questions have been incorporated to make it completely clear. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
You almost always put different classes in different files | ||
|
||
Python toolbelt preferences: | ||
- pytest | ||
- dataclasses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
You will read instructions and NOT carry them out, only seek to CLARIFY them. | ||
You will carry out the steps: | ||
1. Write a list of super short bullets of areas that are unclear | ||
2. Ask for only one clarifying questions and wait for a reply |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from ast import List | ||
from dataclasses import dataclass | ||
from typing import Callable | ||
from ai import AI | ||
from chat_to_files import to_files | ||
|
||
from db import DBs | ||
from db import DB | ||
|
||
def setup_sys_prompt(dbs): | ||
return dbs.identity['setup'] + '\nUseful to know:\n' + dbs.identity['philosophy'] | ||
|
||
def setup(ai: AI, dbs: DBs): | ||
messages = ai.start(setup_sys_prompt(dbs), dbs.input['main_prompt']) | ||
to_files(messages[-1]['content'], dbs.workspace) | ||
return messages | ||
|
||
def run_clarified(ai: AI, dbs: DBs): | ||
messages = ai.start(setup_sys_prompt(dbs), dbs.input['main_prompt']) | ||
to_files(messages[-1]['content'], DB(str(dbs.workspace.path)+'_clarified')) | ||
return messages | ||
|
||
def clarify(ai: AI, dbs: DBs): | ||
messages = [ai.fsystem(dbs.identity['qa'])] | ||
user = dbs.input['main_prompt'] | ||
while True: | ||
messages = ai.next(messages, user) | ||
print() | ||
user = input('Answer: ') | ||
if not user or user == 'q': | ||
break | ||
|
||
user += '\nIs anything else unclear? Please ask more questions until instructions are sufficient to write the code.' | ||
|
||
# TOOD: Stop using clarify prompt. Just append questions and answers to the main prompt. | ||
prompt = dbs.identity['clarify'] | ||
messages = ai.next([ai.fsystem(prompt)] + messages[1:], prompt) | ||
dbs.memory['clarified_prompt'] = messages[-1]['content'] | ||
return messages | ||
|
||
|
||
# STEPS: List[Callable[[AI, DBs], List]] = [ | ||
STEPS=[ | ||
setup, | ||
# clarify, | ||
# run_clarified | ||
# to_files, | ||
# improve_files, | ||
# run_tests, | ||
# ImproveBasedOnHumanComments | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from ..db import DB | ||
|
||
|
||
def test_db(): | ||
# use /tmp for testing | ||
db = DB('/tmp/test_db') | ||
db['test'] = 'test' | ||
assert db['test'] == 'test' | ||
db['test'] = 'test2' | ||
assert db['test'] == 'test2' | ||
db['test2'] = 'test2' | ||
assert db['test2'] == 'test2' | ||
assert db['test'] == 'test2' | ||
print('test_db passed') |