Skip to content

Commit 6efc45f

Browse files
committed
format code
1 parent e6c90ed commit 6efc45f

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

evaluation/scripts/personamem/pm_search.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@ def main(frame, version, top_k=20, num_workers=2):
315315

316316
with open(f"results/pm/{frame}-{version}/{frame}_pm_search_results.json", "w") as f:
317317
json.dump(dict(all_search_results), f, indent=4)
318-
print(
319-
f"📁 Results saved to: mresults/pm/{frame}-{version}/{frame}_pm_search_results.json"
320-
)
318+
print(f"📁 Results saved to: mresults/pm/{frame}-{version}/{frame}_pm_search_results.json")
321319
print("=" * 80 + "\n")
322320

323321

evaluation/scripts/utils/client.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, enable_graph=False):
5454
def add(self, messages, user_id, timestamp, batch_size=2):
5555
max_retries = 5
5656
for i in range(0, len(messages), batch_size):
57-
batch_messages = messages[i: i + batch_size]
57+
batch_messages = messages[i : i + batch_size]
5858
for attempt in range(max_retries):
5959
try:
6060
if self.enable_graph:
@@ -67,12 +67,15 @@ def add(self, messages, user_id, timestamp, batch_size=2):
6767
)
6868
else:
6969
self.client.add(
70-
messages=batch_messages, timestamp=timestamp, user_id=user_id, async_mode=False
70+
messages=batch_messages,
71+
timestamp=timestamp,
72+
user_id=user_id,
73+
async_mode=False,
7174
)
7275
break
7376
except Exception as e:
7477
if attempt < max_retries - 1:
75-
time.sleep(2 ** attempt)
78+
time.sleep(2**attempt)
7679
else:
7780
raise e
7881

@@ -108,17 +111,18 @@ def add(self, messages, user_id, batch_size=2):
108111
messages = [{"role": "assistant", "content": data, "created_at": iso_date}]
109112
"""
110113
from memobase import ChatBlob
114+
111115
real_uid = self.string_to_uuid(user_id)
112116
user = self.client.get_or_create_user(real_uid)
113117
for i in range(0, len(messages), batch_size):
114-
batch_messages = messages[i: i + batch_size]
118+
batch_messages = messages[i : i + batch_size]
115119
max_retries = 5
116120
for attempt in range(max_retries):
117121
try:
118122
_ = user.insert(ChatBlob(messages=batch_messages), sync=True)
119123
except Exception as e:
120124
if attempt < max_retries - 1:
121-
time.sleep(2 ** attempt)
125+
time.sleep(2**attempt)
122126
else:
123127
raise e
124128

@@ -135,6 +139,7 @@ def search(self, query, user_id, top_k):
135139

136140
def delete_user(self, user_id):
137141
from memobase.error import ServerError
142+
138143
real_uid = self.string_to_uuid(user_id)
139144
with suppress(ServerError):
140145
self.client.delete_user(real_uid)
@@ -211,7 +216,7 @@ def add(self, messages, user_id, conv_id=None):
211216
return response.text
212217
except Exception as e:
213218
if attempt < max_retries - 1:
214-
time.sleep(2 ** attempt)
219+
time.sleep(2**attempt)
215220
else:
216221
raise e
217222

@@ -238,7 +243,7 @@ def search(self, query, user_id, top_k):
238243
return {"text_mem": [{"memories": res}]}
239244
except Exception as e:
240245
if attempt < max_retries - 1:
241-
time.sleep(2 ** attempt)
246+
time.sleep(2**attempt)
242247
else:
243248
raise e
244249

@@ -260,7 +265,7 @@ def add(self, messages, user_id):
260265
break
261266
except Exception as e:
262267
if attempt < max_retries - 1:
263-
time.sleep(2 ** attempt)
268+
time.sleep(2**attempt)
264269
else:
265270
raise e
266271

@@ -280,7 +285,7 @@ def search(self, query, user_id, top_k):
280285
return context
281286
except Exception as e:
282287
if attempt < max_retries - 1:
283-
time.sleep(2 ** attempt)
288+
time.sleep(2**attempt)
284289
else:
285290
raise e
286291

@@ -340,5 +345,3 @@ def wait_for_completion(self, task_id):
340345
m["created_at"] = iso_date
341346
client.add(messages, user_id)
342347
memories = client.search(query, user_id, top_k)
343-
344-

0 commit comments

Comments
 (0)