Make gpt-engineer pip installable/runnable (#60)

This commit is contained in:
Jack Eadie
2023-06-16 21:25:29 +10:00
committed by GitHub
parent 12cb93fc7a
commit 6f8e976a42
8 changed files with 59 additions and 23 deletions

33
gpt_engineer/db.py Normal file
View File

@@ -0,0 +1,33 @@
from dataclasses import dataclass
import os
from pathlib import Path
class DB:
"""A simple key-value store, where keys are filenames and values are file contents."""
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, encoding='utf-8') as f:
return f.read()
def __setitem__(self, key, val):
with open(self.path / key, 'w', encoding='utf-8') as f:
f.write(val)
def __contains__(self, key):
return (self.path / key).exists()
@dataclass
class DBs:
"""A dataclass for all dbs"""
memory: DB
logs: DB
identity: DB
input: DB
workspace: DB