Skip to content

Commit

Permalink
fix: when to_list() on the queueinginterface buffer (eg for python cl…
Browse files Browse the repository at this point in the history
…ient), if we're going to message objects make sure to deduplicate Message objects, since one Message object may correspond to multiple MemGPTMessage objects
  • Loading branch information
cpacker committed Aug 30, 2024
1 parent 89d6c7d commit 96025e1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions memgpt/server/rest_api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ def to_list(self, style: Literal["obj", "api"] = "obj"):
break
if len(items) > 1 and items[-1] == "STOP":
items.pop()

# If the style is "obj", then we need to deduplicate any messages
# Filter down items for duplicates based on item.id
if style == "obj":
seen_ids = set()
unique_items = []
for item in reversed(items):
if item.id not in seen_ids:
seen_ids.add(item.id)
unique_items.append(item)
items = list(reversed(unique_items))

return items

def clear(self):
Expand Down

0 comments on commit 96025e1

Please sign in to comment.