Skip to content

Commit

Permalink
moved variable hardcoded key out into constants.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker committed Jul 28, 2024
1 parent 5dd351b commit fcc040c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions memgpt/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions memgpt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fcc040c

Please sign in to comment.