Fixed api issues, missing deps and got first endpoint to work

This commit is contained in:
Vasilije 2023-11-17 21:04:53 +01:00
parent f3a5ee929e
commit ef7d1b3bc7
3 changed files with 16 additions and 13 deletions

View file

@ -10,7 +10,7 @@ class MemoryModel(Base):
id = Column(String, primary_key=True) id = Column(String, primary_key=True)
user_id = Column(String, ForeignKey('users.id'), index=True) user_id = Column(String, ForeignKey('users.id'), index=True)
operation_id = Column(String, ForeignKey('operations.id'), index=True) operation_id = Column(String, nullable=True)
memory_name = Column(String, nullable=True) memory_name = Column(String, nullable=True)
created_at = Column(DateTime, default=datetime.utcnow) created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, onupdate=datetime.utcnow) updated_at = Column(DateTime, onupdate=datetime.utcnow)

View file

@ -146,6 +146,7 @@ class Memory:
namespace: str = None, namespace: str = None,
memory_id: str = None, memory_id: str = None,
memory_class = None, memory_class = None,
job_id:str = None
) -> None: ) -> None:
self.load_environment_variables() self.load_environment_variables()
self.memory_id = memory_id self.memory_id = memory_id
@ -156,6 +157,7 @@ class Memory:
self.namespace = namespace self.namespace = namespace
self.memory_instances = [] self.memory_instances = []
self.memory_class = memory_class self.memory_class = memory_class
self.job_id=job_id
# self.memory_class = DynamicBaseMemory( # self.memory_class = DynamicBaseMemory(
# "Memory", user_id, str(self.memory_id), index_name, db_type, namespace # "Memory", user_id, str(self.memory_id), index_name, db_type, namespace
# ) # )
@ -194,10 +196,10 @@ class Memory:
) )
memory_class = DynamicBaseMemory( memory_class = DynamicBaseMemory(
memory_label, user_id, str(memory_id), index_name=memory_label, db_type='weaviate', **kwargs memory_label, user_id, str(memory_id), index_name=memory_label , db_type='weaviate', **kwargs
) )
return cls(user_id=user_id, session=session, memory_id=memory_id, memory_class=memory_class, **kwargs) return cls(user_id=user_id, session=session, memory_id=memory_id, job_id =job_id, memory_class=memory_class, **kwargs)
async def list_memory_classes(self): async def list_memory_classes(self):
""" """
@ -267,6 +269,7 @@ class Memory:
""" """
try: try:
memory_id = str(uuid.uuid4()) memory_id = str(uuid.uuid4())
logging.info("Job id %s", job_id)
memory = MemoryModel( memory = MemoryModel(
id=memory_id, id=memory_id,
user_id=user_id, user_id=user_id,
@ -458,15 +461,15 @@ async def main():
await memory.add_dynamic_memory_class("semanticmemory", "SEMANTICMEMORY") await memory.add_dynamic_memory_class("semanticmemory", "SEMANTICMEMORY")
await memory.add_method_to_class(memory.semanticmemory_class, "add_memories") await memory.add_method_to_class(memory.semanticmemory_class, "add_memories")
await memory.add_method_to_class(memory.semanticmemory_class, "fetch_memories") await memory.add_method_to_class(memory.semanticmemory_class, "fetch_memories")
# sss = await memory.dynamic_method_call(memory.semanticmemory_class, 'add_memories', sss = await memory.dynamic_method_call(memory.semanticmemory_class, 'add_memories',
# observation='some_observation', params=params, loader_settings=loader_settings) observation='some_observation', params=params, loader_settings=loader_settings)
susu = await memory.dynamic_method_call( # susu = await memory.dynamic_method_call(
memory.semanticmemory_class, # memory.semanticmemory_class,
"fetch_memories", # "fetch_memories",
observation="document summary", # observation="document summary",
) # )
print(susu) # print(susu)
# Adding a dynamic memory class # Adding a dynamic memory class
# dynamic_memory = memory.add_dynamic_memory_class("DynamicMemory", "ExampleNamespace") # dynamic_memory = memory.add_dynamic_memory_class("DynamicMemory", "ExampleNamespace")

View file

@ -504,8 +504,8 @@ async def main():
"source": "URL", "source": "URL",
"path": ["https://www.ibiblio.org/ebooks/London/Call%20of%20Wild.pdf"], "path": ["https://www.ibiblio.org/ebooks/London/Call%20of%20Wild.pdf"],
} }
# await load_documents_to_vectorstore(session, user_id, loader_settings=loader_settings) await load_documents_to_vectorstore(session, user_id, loader_settings=loader_settings)
await user_query_to_graph_db(session, user_id, "I walked in the forest yesterday and added to my list I need to buy some milk in the store") # await user_query_to_graph_db(session, user_id, "I walked in the forest yesterday and added to my list I need to buy some milk in the store")
# await add_documents_to_graph_db(session, user_id) # await add_documents_to_graph_db(session, user_id)
# memory_instance = Memory(namespace='SEMANTICMEMORY') # memory_instance = Memory(namespace='SEMANTICMEMORY')
# sss = await memory_instance.dynamic_method_call(memory_instance.semantic_memory_class, 'fetch_memories', observation='some_observation') # sss = await memory_instance.dynamic_method_call(memory_instance.semantic_memory_class, 'fetch_memories', observation='some_observation')