cpacker / MemGPT

Create LLM agents with long-term memory and custom tools 📚🦙
https://memgpt.readme.io
Apache License 2.0
10.77k stars 1.16k forks source link

`DotDict` deprecation causing issues on load #562

Closed cpacker closed 7 months ago

cpacker commented 7 months ago

Describe the bug

On loads of old agents that used LocalLLMs, DotDict is present in the pickle file (even though we deprecated DotDict for Box):

  File "/.../lib/python3.11/site-packages/memgpt/persistence_manager.py", line 52, in load
    data = pickle.load(f)
           ^^^^^^^^^^^^^^
AttributeError: Can't get attribute 'DotDict' on <module 'memgpt.local_llm.utils' from '/.../lib/python3.11/site-packages/memgpt/local_llm/utils.py'>

Solution: add back DotDict to utils.py for backcompat.

gavsgav commented 7 months ago

For a temporary fix just add to the top of the /.../lib/python3.11/site-packages/memgpt/local_llm/utils.py

class DotDict(dict):
    """Allow dot access on properties similar to OpenAI response object"""

    def __getattr__(self, attr):
        return self.get(attr)

    def __setattr__(self, key, value):
        self[key] = value

    # following methods necessary for pickling
    def __getstate__(self):
        return vars(self)

    def __setstate__(self, state):
        vars(self).update(state)