Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/memos/mem_reader/strategy_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
CUSTOM_TAGS_INSTRUCTION_ZH,
SIMPLE_STRUCT_DOC_READER_PROMPT,
SIMPLE_STRUCT_DOC_READER_PROMPT_ZH,
SIMPLE_STRUCT_MEM_READER_EXAMPLE,
SIMPLE_STRUCT_MEM_READER_EXAMPLE_ZH,
)
from memos.templates.mem_reader_strategy_prompts import (
STRATEGY_STRUCT_MEM_READER_PROMPT,
Expand All @@ -27,8 +25,6 @@
"chat": {
"en": STRATEGY_STRUCT_MEM_READER_PROMPT,
"zh": STRATEGY_STRUCT_MEM_READER_PROMPT_ZH,
"en_example": SIMPLE_STRUCT_MEM_READER_EXAMPLE,
"zh_example": SIMPLE_STRUCT_MEM_READER_EXAMPLE_ZH,
},
"doc": {"en": SIMPLE_STRUCT_DOC_READER_PROMPT, "zh": SIMPLE_STRUCT_DOC_READER_PROMPT_ZH},
"custom_tags": {"en": CUSTOM_TAGS_INSTRUCTION, "zh": CUSTOM_TAGS_INSTRUCTION_ZH},
Expand All @@ -45,7 +41,6 @@ def __init__(self, config: StrategyStructMemReaderConfig):
def _get_llm_response(self, mem_str: str, custom_tags: list[str] | None) -> dict:
lang = detect_lang(mem_str)
template = STRATEGY_PROMPT_DICT["chat"][lang]
examples = STRATEGY_PROMPT_DICT["chat"][f"{lang}_example"]
prompt = template.replace("${conversation}", mem_str)

custom_tags_prompt = (
Expand All @@ -55,8 +50,6 @@ def _get_llm_response(self, mem_str: str, custom_tags: list[str] | None) -> dict
)
prompt = prompt.replace("${custom_tags_prompt}", custom_tags_prompt)

if self.config.remove_prompt_example: # TODO unused
prompt = prompt.replace(examples, "")
messages = [{"role": "user", "content": prompt}]
try:
response_text = self.llm.generate(messages)
Expand Down
34 changes: 34 additions & 0 deletions tests/mem_reader/test_strategy_struct_dead_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ast
from pathlib import Path


SOURCE = Path(__file__).resolve().parents[2] / "src/memos/mem_reader/strategy_struct.py"


def _get_llm_response_body():
module = ast.parse(SOURCE.read_text())
for node in module.body:
if isinstance(node, ast.ClassDef) and node.name == "StrategyStructMemReader":
for item in node.body:
if isinstance(item, ast.FunctionDef) and item.name == "_get_llm_response":
return item.body
raise AssertionError("StrategyStructMemReader._get_llm_response not found")


def test_strategy_struct_reader_does_not_keep_dead_prompt_example_branch():
body = _get_llm_response_body()
names = {
node.id
for statement in body
for node in ast.walk(statement)
if isinstance(node, ast.Name)
}
attrs = {
node.attr
for statement in body
for node in ast.walk(statement)
if isinstance(node, ast.Attribute)
}

assert "remove_prompt_example" not in attrs
assert "examples" not in names