supermemory-pipecat 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/PKG-INFO +1 -1
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/pyproject.toml +1 -1
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/src/supermemory_pipecat/__init__.py +1 -1
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/src/supermemory_pipecat/service.py +12 -7
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/src/supermemory_pipecat/utils.py +19 -2
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/tests/test_empty_profile.py +34 -1
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/.gitignore +0 -0
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/README.md +0 -0
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/src/supermemory_pipecat/exceptions.py +0 -0
- {supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: supermemory-pipecat
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Supermemory integration for Pipecat - memory-enhanced conversational AI pipelines
|
|
5
5
|
Project-URL: Homepage, https://supermemory.ai
|
|
6
6
|
Project-URL: Documentation, https://docs.supermemory.ai
|
|
@@ -21,7 +21,12 @@ from pipecat.processors.aggregators.llm_context import LLMContext
|
|
|
21
21
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
|
22
22
|
|
|
23
23
|
from .exceptions import ConfigurationError, MemoryRetrievalError, MemoryStorageError
|
|
24
|
-
from .utils import
|
|
24
|
+
from .utils import (
|
|
25
|
+
_field,
|
|
26
|
+
deduplicate_memories,
|
|
27
|
+
escape_memory_delimiters,
|
|
28
|
+
format_memories_to_text,
|
|
29
|
+
)
|
|
25
30
|
|
|
26
31
|
# Pipecat 1.0 removed the legacy message and OpenAI-specific context frames.
|
|
27
32
|
# Keep them optional so the integration supports both the declared 0.0.98
|
|
@@ -359,9 +364,11 @@ class SupermemoryPipecatService(FrameProcessor):
|
|
|
359
364
|
memories_data: Memory data from Supermemory API.
|
|
360
365
|
"""
|
|
361
366
|
profile = memories_data["profile"]
|
|
367
|
+
include_profile = self.params.mode in ("profile", "full")
|
|
368
|
+
include_search = self.params.mode in ("query", "full")
|
|
362
369
|
deduplicated = deduplicate_memories(
|
|
363
|
-
static=profile["static"],
|
|
364
|
-
dynamic=profile["dynamic"],
|
|
370
|
+
static=profile["static"] if include_profile else [],
|
|
371
|
+
dynamic=profile["dynamic"] if include_profile else [],
|
|
365
372
|
search_results=memories_data["search_results"],
|
|
366
373
|
)
|
|
367
374
|
|
|
@@ -374,9 +381,6 @@ class SupermemoryPipecatService(FrameProcessor):
|
|
|
374
381
|
if total_memories == 0:
|
|
375
382
|
return
|
|
376
383
|
|
|
377
|
-
include_profile = self.params.mode in ("profile", "full")
|
|
378
|
-
include_search = self.params.mode in ("query", "full")
|
|
379
|
-
|
|
380
384
|
memory_text = format_memories_to_text(
|
|
381
385
|
deduplicated,
|
|
382
386
|
system_prompt=self.params.system_prompt,
|
|
@@ -388,7 +392,8 @@ class SupermemoryPipecatService(FrameProcessor):
|
|
|
388
392
|
if not memory_text:
|
|
389
393
|
return
|
|
390
394
|
|
|
391
|
-
|
|
395
|
+
safe_memory_text = escape_memory_delimiters(memory_text)
|
|
396
|
+
tagged_memory = f"{MEMORY_TAG_START}\n{safe_memory_text}\n{MEMORY_TAG_END}"
|
|
392
397
|
|
|
393
398
|
inject_to_system = self.params.inject_mode == "system" or (
|
|
394
399
|
self.params.inject_mode == "auto" and self._audio_frames_detected
|
|
@@ -5,7 +5,23 @@ from datetime import datetime, timezone
|
|
|
5
5
|
from typing import Any, Dict, List, Union
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
_DYNAMIC_DATE_PREFIX = re.compile(
|
|
8
|
+
_DYNAMIC_DATE_PREFIX = re.compile(
|
|
9
|
+
r"^\s*(?:\[recent\]\s*)?(?:\[\d{4}-\d{2}-\d{2}\]\s*)?",
|
|
10
|
+
re.IGNORECASE,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
_USER_MEMORIES_TAG_PATTERN = re.compile(
|
|
14
|
+
r"<\s*/?\s*user_memories\b[^>]*>",
|
|
15
|
+
re.IGNORECASE,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def escape_memory_delimiters(text: str) -> str:
|
|
20
|
+
"""Neutralize reserved memory-wrapper tags inside formatted content."""
|
|
21
|
+
return _USER_MEMORIES_TAG_PATTERN.sub(
|
|
22
|
+
lambda match: match.group(0).replace("<", "<").replace(">", ">"),
|
|
23
|
+
text,
|
|
24
|
+
)
|
|
9
25
|
|
|
10
26
|
|
|
11
27
|
def get_last_user_message(messages: List[Dict[str, Any]]) -> str | None:
|
|
@@ -91,7 +107,8 @@ def deduplicate_memories(
|
|
|
91
107
|
def comparison_key(memory: str) -> str:
|
|
92
108
|
# Dynamic profile entries are date-labelled by the API while search
|
|
93
109
|
# results contain the same memory without that presentation prefix.
|
|
94
|
-
|
|
110
|
+
without_prefix = _DYNAMIC_DATE_PREFIX.sub("", memory.strip())
|
|
111
|
+
return " ".join(without_prefix.split()).casefold()
|
|
95
112
|
|
|
96
113
|
def unique_strings(memories: List[str]) -> List[str]:
|
|
97
114
|
out: List[str] = []
|
|
@@ -120,4 +120,37 @@ class TestSupermemoryPipecatNullProfile(unittest.IsolatedAsyncioTestCase):
|
|
|
120
120
|
"profile": {"static": [], "dynamic": []},
|
|
121
121
|
"search_results": [],
|
|
122
122
|
},
|
|
123
|
-
)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def test_query_mode_keeps_search_fact_also_present_in_profile(self) -> None:
|
|
126
|
+
fact = "User likes machine learning projects"
|
|
127
|
+
service = SupermemoryPipecatService(
|
|
128
|
+
api_key="mock_key",
|
|
129
|
+
user_id="user-123",
|
|
130
|
+
session_id="conversation-456",
|
|
131
|
+
params=SupermemoryPipecatService.InputParams(mode="query"),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
class Context:
|
|
135
|
+
def __init__(self):
|
|
136
|
+
self.messages = [{"role": "user", "content": "What do I like?"}]
|
|
137
|
+
|
|
138
|
+
def get_messages(self):
|
|
139
|
+
return self.messages
|
|
140
|
+
|
|
141
|
+
def add_message(self, message):
|
|
142
|
+
self.messages.append(message)
|
|
143
|
+
|
|
144
|
+
context = Context()
|
|
145
|
+
service._enhance_context_with_memories(
|
|
146
|
+
context,
|
|
147
|
+
"What do I like?",
|
|
148
|
+
{
|
|
149
|
+
"profile": {"static": [fact], "dynamic": []},
|
|
150
|
+
"search_results": [SimpleNamespace(memory=fact)],
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
self.assertTrue(
|
|
155
|
+
any(fact in message.get("content", "") for message in context.messages)
|
|
156
|
+
)
|
|
File without changes
|
|
File without changes
|
{supermemory_pipecat-0.1.2 → supermemory_pipecat-0.1.3}/src/supermemory_pipecat/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|