mirror of
https://github.com/langgenius/dify.git
synced 2026-04-14 07:56:31 +08:00
refactor: make save_memory and get_memory_by_spec work on latest version
This commit is contained in:
parent
e3903f34e4
commit
3d761a3189
@ -71,23 +71,22 @@ class ChatflowMemoryService:
|
||||
app_id=memory.app_id,
|
||||
node_id=memory.node_id,
|
||||
conversation_id=memory.conversation_id
|
||||
).first()
|
||||
if existing:
|
||||
existing.value = memory.value
|
||||
else:
|
||||
session.add(
|
||||
ChatflowMemoryVariable(
|
||||
memory_id=memory.spec.id,
|
||||
tenant_id=memory.tenant_id,
|
||||
app_id=memory.app_id,
|
||||
node_id=memory.node_id,
|
||||
conversation_id=memory.conversation_id,
|
||||
name=memory.spec.name,
|
||||
value=memory.value,
|
||||
term=memory.spec.term,
|
||||
scope=memory.spec.scope,
|
||||
)
|
||||
).order_by(ChatflowMemoryVariable.version.desc()).first()
|
||||
new_version = 1 if not existing else existing.version + 1
|
||||
session.add(
|
||||
ChatflowMemoryVariable(
|
||||
memory_id=memory.spec.id,
|
||||
tenant_id=memory.tenant_id,
|
||||
app_id=memory.app_id,
|
||||
node_id=memory.node_id,
|
||||
conversation_id=memory.conversation_id,
|
||||
name=memory.spec.name,
|
||||
value=memory.value,
|
||||
term=memory.spec.term,
|
||||
scope=memory.spec.scope,
|
||||
version=new_version,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
if is_draft:
|
||||
@ -163,7 +162,7 @@ class ChatflowMemoryService:
|
||||
ChatflowMemoryVariable.conversation_id == \
|
||||
(conversation_id if spec.term == MemoryTerm.SESSION else None),
|
||||
)
|
||||
)
|
||||
).order_by(ChatflowMemoryVariable.version.desc()).limit(1)
|
||||
result = session.execute(stmt).scalar()
|
||||
if result:
|
||||
return MemoryBlock(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user