From f6b2863303625ef7ef3809c4e08edbd2e0b4530b Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 25 二月 2025 11:19:57 +0800 Subject: [PATCH] 鉴权 --- app/models/session_model.py | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/models/session_model.py b/app/models/session_model.py index 6aed237..5765a44 100644 --- a/app/models/session_model.py +++ b/app/models/session_model.py @@ -1,11 +1,17 @@ import json from datetime import datetime from enum import IntEnum -from sqlalchemy import Column, String, Enum as SQLAlchemyEnum, Integer, DateTime, JSON -from app.models import AgentType, current_time +import pytz +from sqlalchemy import Column, String, Enum as SQLAlchemyEnum, Integer, DateTime, JSON, TEXT + +from app.models.agent_model import AgentType +# from app.models import current_time from app.models.base_model import Base +def current_time(): + tz = pytz.timezone('Asia/Shanghai') + return datetime.now(tz) class SessionModel(Base): __tablename__ = "sessions" @@ -14,9 +20,11 @@ agent_id = Column(String(255)) agent_type = Column(SQLAlchemyEnum(AgentType), nullable=False) # 鐩墠鍙瓨basic鐨勶紝ragflow鍜宐isheng鐨勮皟鎺ュ彛鑾峰彇 create_date = Column(DateTime, default=current_time) # 鍒涘缓鏃堕棿锛岄粯璁ゅ�间负褰撳墠鏃跺尯鏃堕棿 - update_date = Column(DateTime, default=current_time, onupdate=current_time) # 鏇存柊鏃堕棿锛岄粯璁ゅ�间负褰撳墠鏃跺尯鏃堕棿锛屾洿鏂版椂鑷姩鏇存柊 + update_date = Column(DateTime, default=current_time, onupdate=current_time, index=True) # 鏇存柊鏃堕棿锛岄粯璁ゅ�间负褰撳墠鏃跺尯鏃堕棿锛屾洿鏂版椂鑷姩鏇存柊 tenant_id = Column(Integer) # 鍒涘缓浜� - message = Column(JSON) # 璇存槑 + message = Column(TEXT) # 璇存槑 + conversation_id = Column(String(64)) + workflow = Column(Integer, default=0) # to_dict 鏂规硶 def to_dict(self): @@ -25,6 +33,7 @@ 'name': self.name, 'agent_type': self.agent_type, 'agent_id': self.agent_id, + 'workflow': self.workflow if self.workflow else 0, 'create_date': self.create_date.strftime("%Y-%m-%d %H:%M:%S"), 'update_date': self.update_date.strftime("%Y-%m-%d %H:%M:%S"), } @@ -37,5 +46,15 @@ 'agent_id': self.agent_id, 'create_date': self.create_date.strftime("%Y-%m-%d %H:%M:%S"), 'update_date': self.update_date.strftime("%Y-%m-%d %H:%M:%S"), - 'message': self.message + 'message': json.loads(self.message) } + + def add_message(self, message: dict): + if self.message is None: + self.message = '[]' + try: + msg = json.loads(self.message) + msg.append(message) + except Exception as e: + return + self.message = json.dumps(msg) -- Gitblit v1.8.0