mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
Make gpt-engineer pip installable/runnable (#60)
This commit is contained in:
33
gpt_engineer/db.py
Normal file
33
gpt_engineer/db.py
Normal 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
|
||||
Reference in New Issue
Block a user