From fcc040c9130e780463f20b4202ac1058bfc2e8e7 Mon Sep 17 00:00:00 2001 From: cpacker Date: Sat, 27 Jul 2024 21:00:17 -0700 Subject: [PATCH] moved variable hardcoded key out into constants.py --- memgpt/agent.py | 5 +++-- memgpt/constants.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/memgpt/agent.py b/memgpt/agent.py index a5d5d53f3d..9d60a91ade 100644 --- a/memgpt/agent.py +++ b/memgpt/agent.py @@ -11,6 +11,7 @@ from memgpt.constants import ( CLI_WARNING_PREFIX, FIRST_MESSAGE_ATTEMPTS, + IN_CONTEXT_MEMORY_KEYWORD, JSON_ENSURE_ASCII, JSON_LOADS_STRICT, LLM_MAX_TOKENS, @@ -86,7 +87,6 @@ def compile_system_message( The following are reserved variables: - CORE_MEMORY: the in-context memory of the LLM """ - IN_CONTEXT_MEMORY_KEYWORD = "CORE_MEMORY" if user_defined_variables is not None: # TODO eventually support the user defining their own variables to inject @@ -113,10 +113,10 @@ def compile_system_message( # Catch the special case where the system prompt is unformatted if append_icm_if_missing: - # TODO support for mustache and jinja2 memory_variable_string = "{" + IN_CONTEXT_MEMORY_KEYWORD + "}" if memory_variable_string not in system_prompt: # In this case, append it to the end to make sure memory is still injected + # warnings.warn(f"{IN_CONTEXT_MEMORY_KEYWORD} variable was missing from system prompt, appending instead") system_prompt += "\n" + memory_variable_string # render the variables using the built-in templater @@ -126,6 +126,7 @@ def compile_system_message( raise ValueError(f"Failed to format system prompt - {str(e)}. System prompt value:\n{system_prompt}") else: + # TODO support for mustache and jinja2 raise NotImplementedError(template_format) return formatted_prompt diff --git a/memgpt/constants.py b/memgpt/constants.py index 254dd2d889..e7b8ceaf3e 100644 --- a/memgpt/constants.py +++ b/memgpt/constants.py @@ -3,6 +3,9 @@ MEMGPT_DIR = os.path.join(os.path.expanduser("~"), ".memgpt") +# System prompt templating +IN_CONTEXT_MEMORY_KEYWORD = "CORE_MEMORY" + # OpenAI error message: Invalid 'messages[1].tool_calls[0].id': string too long. Expected a string with maximum length 29, but got a string with length 36 instead. TOOL_CALL_ID_MAX_LEN = 29