Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use jinja2 templates for Memory.compile instead of writing Python code #1687

Merged
merged 15 commits into from
Sep 3, 2024

Conversation

cpacker
Copy link
Collaborator

@cpacker cpacker commented Aug 27, 2024

Additions

  1. Apply PR refactor: move prompt string generation in Memory to a non-overloaded function #1683 to RecallMemory and ArchivalMemory (previous PR only did CoreMemory)
  2. Modify the compile code in CoreMemory to use jinja2 instead of having a Python loop

Re: (2) - this should make it much more straight forward to allow changing the way the 'prompt formatting' of the memory object when creating custom memory blocks on the dev portal, since the back-and-forth between the frontend and backend will be a jinja2 template string, instead of Python code that needs to be interpreted.

TODO

  • Serialize / persist the template string (so that it can be retrieved / modified with API calls)

Testing

Added test to double-check that the new jinja2 template is equivalent to the old Python __repr__ code:

pytest tests/test_memory.py::test_memory_jinja2_template

Added test for a Memory.set_template function that validates if the template string is valid or not (is it good jinja2 + does it compile?)

pytest tests/test_memory.py::test_memory_jinja2_set_template

memgpt/memory.py Outdated Show resolved Hide resolved
memgpt/memory.py Outdated Show resolved Hide resolved
memgpt/memory.py Outdated Show resolved Hide resolved
@cpacker cpacker changed the title refactor: use jinja2 templates for Memory.compile instead of writing Python code refactor: use jinja2 templates for Memory.compile instead of writing Python code Aug 27, 2024
@sarahwooders
Copy link
Collaborator

Maybe rename template to prompt_template?

memgpt/agent.py Show resolved Hide resolved
@cpacker cpacker requested a review from sarahwooders September 3, 2024 21:52
@cpacker cpacker requested a review from sarahwooders September 3, 2024 22:04
Copy link
Collaborator

@sarahwooders sarahwooders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@cpacker cpacker merged commit f10e201 into main Sep 3, 2024
12 checks passed
@cpacker cpacker deleted the refactor-memory-compile-jinja2 branch September 3, 2024 22:44
mattzh72 pushed a commit that referenced this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants