Skip to content

Commit 8d909d4

Browse files
committed
refactor(client): pref mem
1 parent 067f895 commit 8d909d4

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

evaluation/scripts/utils/client.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,33 +250,23 @@ def search(self, query, user_id, top_k):
250250
preference_note = json.loads(response.text)["data"]["preference_note"]
251251
for i in text_mem_res:
252252
i.update({"memory": i.pop("memory_value")})
253+
explicit_pref_string = "Explicit Preference:"
254+
implicit_pref_string = "\n\nImplicit Preference:"
255+
explicit_idx = 0
256+
implicit_idx = 0
257+
for pref in pref_mem_res:
258+
if pref["preference_type"] == "explicit_preference":
259+
explicit_pref_string += f"\n{explicit_idx + 1}. {pref['preference']}"
260+
explicit_idx += 1
261+
if pref["preference_type"] == "explicit_preference":
262+
implicit_pref_string += f"\n{implicit_idx + 1}. {pref['preference']}"
263+
implicit_idx += 1
264+
265+
return {
266+
"text_mem": [{"memories": text_mem_res}],
267+
"pref_string": explicit_pref_string + implicit_pref_string + preference_note,
268+
}
253269

254-
explicit_prefs = [
255-
p["preference"]
256-
for p in pref_mem_res
257-
if p.get("preference_type", "") == "explicit_preference"
258-
]
259-
implicit_prefs = [
260-
p["preference"]
261-
for p in pref_mem_res
262-
if p.get("preference_type", "") == "implicit_preference"
263-
]
264-
265-
pref_parts = []
266-
if explicit_prefs:
267-
pref_parts.append(
268-
"Explicit Preference:\n"
269-
+ "\n".join(f"{i + 1}. {p}" for i, p in enumerate(explicit_prefs))
270-
)
271-
if implicit_prefs:
272-
pref_parts.append(
273-
"Implicit Preference:\n"
274-
+ "\n".join(f"{i + 1}. {p}" for i, p in enumerate(implicit_prefs))
275-
)
276-
277-
pref_string = "\n".join(pref_parts) + preference_note
278-
279-
return {"text_mem": [{"memories": text_mem_res}], "pref_string": pref_string}
280270
except Exception as e:
281271
if attempt < max_retries - 1:
282272
time.sleep(2**attempt)

0 commit comments

Comments
 (0)