gpt_engineer.core.default.disk_memory.DiskMemory

class gpt_engineer.core.default.disk_memory.DiskMemory(path: str | Path)[source]

Bases: MutableMapping[str | Path, str]

A file-based key-value store where keys correspond to filenames and values to file contents.

This class provides an interface to a file-based database, leveraging file operations to facilitate CRUD-like interactions. It allows for quick checks on the existence of keys, retrieval of values based on keys, and setting new key-value pairs.

path

The directory path where the database files are stored.

Type:

Path

Initialize the DiskMemory class with a specified path.

Parameters:

path (str or Path) – The path to the directory where the database files will be stored.

archive_logs()[source]

Moves all logs to archive directory based on current timestamp

clear() None.  Remove all items from D.
get(key: str, default: Any | None = None) Any[source]

Retrieve the content of a file in the database, or return a default value if not found.

Parameters:
  • key (str) – The key (filename) whose content is to be retrieved.

  • default (Any, optional) – The default value to return if the file does not exist. Default is None.

Returns:

The content of the file if it exists, a new DiskMemory instance if the key corresponds to a directory.

Return type:

Any

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
log(key: str | Path, val: str) None[source]

Append to a file or create and write to it if it doesn’t exist.

Parameters:
  • key (str or Path) – The key (filename) where the content is to be appended.

  • val (str) – The content to be appended to the file.

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
to_dict() Dict[str | Path, str][source]

Convert the database contents to a dictionary.

Returns:

A dictionary with keys as filenames and values as file contents.

Return type:

Dict[Union[str, Path], str]

to_json() str[source]

Serialize the database contents to a JSON string.

Returns:

A JSON string representation of the database contents.

Return type:

str

to_path_list_string(supported_code_files_only: bool = False) str[source]

Generate a string representation of the file paths in the database.

Parameters:

supported_code_files_only (bool, optional) – If True, filter the list to include only supported code file extensions. Default is False.

Returns:

A newline-separated string of file paths.

Return type:

str

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values