Files
gpt-engineer/db.py
Patilla Code 68e4a58975 Merge pull request #23 from JackLeeHal/main
add multi-language support for file read
2023-06-15 21:09:21 +02:00

29 lines
573 B
Python

import os
from dataclasses import dataclass
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, 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)
# dataclass for all dbs:
@dataclass
class DBs:
memory: DB
logs: DB
identity: DB
input: DB
workspace: DB