35 lines
828 B
Python
35 lines
828 B
Python
from ..models import Memory
|
|
|
|
|
|
class MemoryService:
|
|
@staticmethod
|
|
def create_memory(workspace_id, data):
|
|
memory = Memory(
|
|
workspace_id=workspace_id,
|
|
agent_id=data.get("agent_id"),
|
|
type=data["type"],
|
|
content=data["content"],
|
|
tags=data.get("tags"),
|
|
importance=data.get("importance", 5),
|
|
)
|
|
memory.save()
|
|
return memory
|
|
|
|
@staticmethod
|
|
def update_memory(memory, data):
|
|
if "content" in data:
|
|
memory.content = data["content"]
|
|
|
|
if "tags" in data:
|
|
memory.tags = data["tags"]
|
|
|
|
if "importance" in data:
|
|
memory.importance = data["importance"]
|
|
|
|
memory.save()
|
|
return memory
|
|
|
|
@staticmethod
|
|
def delete_memory(memory):
|
|
memory.delete()
|