mirror of
https://github.com/langgenius/dify.git
synced 2026-01-19 11:45:05 +08:00
31 lines
999 B
Python
31 lines
999 B
Python
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from core.variables.variables import Variable
|
|
from extensions.ext_database import db
|
|
from models import ConversationVariable
|
|
|
|
|
|
class ConversationVariableNotFoundError(Exception):
|
|
pass
|
|
|
|
|
|
class ConversationVariableUpdaterImpl:
|
|
def update(self, conversation_id: str, variable: Variable) -> None:
|
|
stmt = select(ConversationVariable).where(
|
|
ConversationVariable.id == variable.id, ConversationVariable.conversation_id == conversation_id
|
|
)
|
|
with Session(db.engine) as session:
|
|
row = session.scalar(stmt)
|
|
if not row:
|
|
raise ConversationVariableNotFoundError("conversation variable not found in the database")
|
|
row.data = variable.model_dump_json()
|
|
session.commit()
|
|
|
|
def flush(self) -> None:
|
|
pass
|
|
|
|
|
|
def conversation_variable_updater_factory() -> ConversationVariableUpdaterImpl:
|
|
return ConversationVariableUpdaterImpl()
|