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

feat: System message template system to easily edit system messages. #880

Conversation

Maximilian-Winter
Copy link
Contributor

@Maximilian-Winter Maximilian-Winter commented Jan 21, 2024

Please describe the purpose of this pull request.
It adds a simple but effective template system for building the system message of memgpt.
It has predefined template fields that can be used to add parts of the default memgpt_chat system message.
The following shows the memgpt_chat system message in template form:

Screenshot 2024-01-21 135140

Each field adds a part of the system message of memgpt_chat, the template system will generate the memgpt system message automatically from it.

The template system get triggered when the system message string in the memgpt preset, ends with '_templated'. Like for example the following memgpt preset:

templated_preset

It then will load the built in template fields, like 'memgpt_introduction' or 'memgpt_realism_authenticity' and tries to load a file with the same name and path as the system message file, but having a file ending of '.yaml' consisting of field names with their respective content. The following is a complete example for instructing memgpt to talk like an old pirate:

memgpt_chat_pirate_templated.txt (in the user folder system_prompts)
templated_txt

memgpt_chat_pirate_templated.yaml (in the user folder system_prompts)
templated_yaml

memgpt_pirate_preset.yaml (in the user folder presets)
templated_preset

Here are is the example in text form:

memgpt_chat_pirate_templated.txt (in the user folder system_prompts)

{memgpt_introduction}

{memgpt_realism_authenticity}

{memgpt_control_flow}

{memgpt_basic_functions}

{memgpt_memory_editing}

{memgpt_recall_memory}

{memgpt_core_memory}

{memgpt_archival_memory}

{memgpt_introduction_end}

{pirate_instruction}

memgpt_chat_pirate_templated.yaml (in the user folder system_prompts)

pirate_instruction: 'Always reponsond like an old pirate!!!'

memgpt_pirate_preset.yaml (in the user folder presets)

system_prompt: "memgpt_chat_pirate_templated"
functions:
  - "send_message"
  - "pause_heartbeats"
  - "core_memory_append"
  - "core_memory_replace"
  - "conversation_search"
  - "conversation_search_date"
  - "archival_memory_insert"
  - "archival_memory_search"

How to test
Start debug mode and look at the system message.

Have you tested this PR?
Yes.

Here is the resulting chat response of memgpt using the example preset:
result_chat

Is your PR over 500 lines of code?
No. Very few lines!

@Maximilian-Winter Maximilian-Winter marked this pull request as ready for review January 21, 2024 13:13
@cpacker cpacker self-requested a review January 21, 2024 18:26
@cpacker cpacker self-assigned this Jan 21, 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