MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / remove_code_blocks

Function remove_code_blocks

methods/mem0/memory/utils.py:34–45  ·  view source on GitHub ↗

Removes enclosing code block markers ```[language] and ``` from a given string. Remarks: - The function uses a regex pattern to match code blocks that may start with ``` followed by an optional language tag (letters or numbers) and end with ```. - If a code block is detected, it re

(content: str)

Source from the content-addressed store, hash-verified

32
33
34def remove_code_blocks(content: str) -> str:
35 """
36 Removes enclosing code block markers ```[language] and ``` from a given string.
37
38 Remarks:
39 - The function uses a regex pattern to match code blocks that may start with ``` followed by an optional language tag (letters or numbers) and end with ```.
40 - If a code block is detected, it returns only the inner content, stripping out the markers.
41 - If no code block markers are found, the original content is returned as-is.
42 """
43 pattern = r"^```[a-zA-Z0-9]*\n([\s\S]*?)\n```$"
44 match = re.match(pattern, content.strip())
45 return match.group(1).strip() if match else content.strip()
46
47
48def get_image_description(image_obj, llm, vision_details):

Callers 1

_add_to_vector_storeMethod · 0.90

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected