docs: fix search method return value handling in integration and example docs (#3208)
This commit is contained in:
@@ -87,8 +87,8 @@ class Companion:
|
||||
|
||||
previous_memories = self.memory.search(question, user_id=user_id_to_use)
|
||||
relevant_memories_text = ""
|
||||
if previous_memories:
|
||||
relevant_memories_text = '\n'.join(mem["memory"] for mem in previous_memories)
|
||||
if previous_memories and previous_memories.get('results'):
|
||||
relevant_memories_text = '\n'.join(mem["memory"] for mem in previous_memories['results'])
|
||||
|
||||
prompt = f"User input: {question}\nPrevious {check_answer} memories: {relevant_memories_text}"
|
||||
|
||||
@@ -146,7 +146,7 @@ def print_memories(user_id, label):
|
||||
memories = ai_companion.get_memories(user_id=user_id)
|
||||
if memories:
|
||||
for m in memories:
|
||||
print(f"- {m['text']}")
|
||||
print(f"- {m['memory']}")
|
||||
else:
|
||||
print("No memories found.")
|
||||
|
||||
|
||||
@@ -213,8 +213,8 @@ class MultiAgentLearningSystem:
|
||||
query="learning machine learning"
|
||||
)
|
||||
|
||||
if memories and len(memories):
|
||||
history = "\n".join(f"- {m['memory']}" for m in memories)
|
||||
if memories and memories.get('results'):
|
||||
history = "\n".join(f"- {m['memory']}" for m in memories['results'])
|
||||
return history
|
||||
else:
|
||||
return "No learning history found yet. Let's start building your profile!"
|
||||
|
||||
@@ -86,7 +86,7 @@ def apply_writing_style(original_content):
|
||||
print("No preferences found.")
|
||||
return None
|
||||
|
||||
preferences = "\n".join(r["memory"] for r in results)
|
||||
preferences = "\n".join(r["memory"] for r in results.get('results', []))
|
||||
|
||||
system_prompt = f"""
|
||||
You are a writing assistant.
|
||||
|
||||
@@ -225,7 +225,7 @@ async function addSampleMemories() {
|
||||
|
||||
const getMemoryString = (memories) => {
|
||||
const MEMORY_STRING_PREFIX = "These are the memories I have stored. Give more weightage to the question by users and try to answer that first. You have to modify your answer based on the memories I have provided. If the memories are irrelevant you can ignore them. Also don't reply to this section of the prompt, or the memories, they are only for your reference. The MEMORIES of the USER are: \n\n";
|
||||
const memoryString = memories.map((mem) => `${mem.memory}`).join("\n") ?? "";
|
||||
const memoryString = (memories?.results || memories).map((mem) => `${mem.memory}`).join("\n") ?? "";
|
||||
return memoryString.length > 0 ? `${MEMORY_STRING_PREFIX}${memoryString}` : "";
|
||||
};
|
||||
|
||||
|
||||
@@ -155,11 +155,11 @@ class PersonalTravelAssistant:
|
||||
|
||||
def get_memories(self, user_id):
|
||||
memories = self.memory.get_all(user_id=user_id)
|
||||
return [m['memory'] for m in memories['memories']]
|
||||
return [m['memory'] for m in memories.get('results', [])]
|
||||
|
||||
def search_memories(self, query, user_id):
|
||||
memories = self.memory.search(query, user_id=user_id)
|
||||
return [m['memory'] for m in memories['memories']]
|
||||
return [m['memory'] for m in memories.get('results', [])]
|
||||
|
||||
# Usage example
|
||||
user_id = "traveler_123"
|
||||
|
||||
Reference in New Issue
Block a user