add AttrDict

This commit is contained in:
geekan 2024-01-08 16:26:52 +08:00
parent 7ab6e43b62
commit 77938b076c
4 changed files with 32 additions and 19 deletions

View file

@ -7,7 +7,7 @@
"""
import os
from pathlib import Path
from typing import Dict, Optional
from typing import Optional
from metagpt.config2 import Config
from metagpt.const import OPTIONS
@ -17,8 +17,27 @@ from metagpt.utils.cost_manager import CostManager
from metagpt.utils.git_repository import GitRepository
class AttrDict:
def __init__(self, d=None):
if d is None:
d = {}
self.__dict__["_dict"] = d
def __getattr__(self, key):
return self._dict.get(key, None)
def __setattr__(self, key, value):
self._dict[key] = value
def __delattr__(self, key):
if key in self._dict:
del self._dict[key]
else:
raise AttributeError(f"No such attribute: {key}")
class Context:
kwargs: Dict = {}
kwargs: AttrDict = {}
config: Config = Config.default()
git_repo: Optional[GitRepository] = None
src_workspace: Optional[Path] = None