Merge branch 'develop' of github.com:SuanmoSuanyangTechnology/MemoryBear into develop
This commit is contained in:
@@ -6,6 +6,7 @@ from .document_model import Document
|
||||
from .file_model import File
|
||||
from .generic_file_model import GenericFile
|
||||
from .models_model import ModelConfig, ModelProvider, ModelType, ModelApiKey
|
||||
from .memory_short_model import ShortTermMemory, LongTermMemory
|
||||
from .knowledgeshare_model import KnowledgeShare
|
||||
from .app_model import App
|
||||
from .agent_app_config_model import AgentConfig
|
||||
@@ -67,6 +68,8 @@ __all__ = [
|
||||
"BuiltinToolConfig",
|
||||
"CustomToolConfig",
|
||||
"MCPToolConfig",
|
||||
"ShortTermMemory",
|
||||
"LongTermMemory",
|
||||
"ToolExecution",
|
||||
"ToolType",
|
||||
"ToolStatus",
|
||||
|
||||
40
api/app/models/memory_perceptual_model.py
Normal file
40
api/app/models/memory_perceptual_model.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import datetime
|
||||
import uuid
|
||||
from enum import IntEnum
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, DateTime, String
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.db import Base
|
||||
|
||||
|
||||
class PerceptualType(IntEnum):
|
||||
VISION = 1
|
||||
AUDIO = 2
|
||||
TEXT = 3
|
||||
CONVERSATION = 4
|
||||
|
||||
|
||||
class FileStorageType(IntEnum):
|
||||
LOCAL = 1
|
||||
REMOTE = 2
|
||||
|
||||
|
||||
class MemoryPerceptualModel(Base):
|
||||
__tablename__ = "memory_perceptual"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
end_user_id = Column(UUID(as_uuid=True), ForeignKey("end_users.id"), index=True)
|
||||
|
||||
perceptual_type = Column(Integer, index=True, nullable=False, comment="感知类型")
|
||||
|
||||
storage_service = Column(Integer, default=0, comment="存储服务类型")
|
||||
file_path = Column(String, nullable=False, comment="文件路径")
|
||||
file_name = Column(String, nullable=False, comment="文件名称")
|
||||
file_ext = Column(String, nullable=False, comment="文件后缀名")
|
||||
|
||||
summary = Column(String, comment="摘要")
|
||||
meta_data = Column(JSONB, comment="元信息")
|
||||
|
||||
created_time = Column(DateTime, default=datetime.datetime.now, comment="创建时间")
|
||||
60
api/app/models/memory_short_model.py
Normal file
60
api/app/models/memory_short_model.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
记忆模型 - 短期记忆和长期记忆表
|
||||
"""
|
||||
import uuid
|
||||
import datetime
|
||||
from sqlalchemy import Column, String, DateTime, Text, JSON
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from app.db import Base
|
||||
|
||||
|
||||
class ShortTermMemory(Base):
|
||||
"""短期记忆表
|
||||
|
||||
用于存储临时的对话记忆,通常保存较短时间
|
||||
"""
|
||||
__tablename__ = "memory_short_term"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True, comment="记忆ID")
|
||||
|
||||
# 用户信息
|
||||
end_user_id = Column(String(255), nullable=False, index=True, comment="终端用户ID")
|
||||
|
||||
# 对话内容
|
||||
messages = Column(Text, nullable=False, comment="用户消息内容")
|
||||
aimessages = Column(Text, nullable=True, comment="AI回复消息内容")
|
||||
|
||||
# 搜索开关
|
||||
search_switch = Column(String(50), nullable=True, comment="搜索开关状态")
|
||||
|
||||
# 检索内容 - 存储为JSON格式的列表,包含字典 [{}, {}]
|
||||
retrieved_content = Column(JSON, nullable=True, default=list, comment="检索到的相关内容,格式为[{}, {}]")
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=datetime.datetime.now, nullable=False, index=True, comment="创建时间")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ShortTermMemory(id={self.id}, end_user_id={self.end_user_id}, created_at={self.created_at})>"
|
||||
|
||||
|
||||
class LongTermMemory(Base):
|
||||
"""长期记忆表
|
||||
|
||||
用于存储重要的对话记忆,长期保存
|
||||
"""
|
||||
__tablename__ = "memory_long_term"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True, comment="记忆ID")
|
||||
|
||||
# 用户信息
|
||||
end_user_id = Column(String(255), nullable=False, index=True, comment="终端用户ID")
|
||||
|
||||
# 检索内容 - 存储为JSON格式的列表,包含字典 [{}, {}]
|
||||
retrieved_content = Column(JSON, nullable=True, default=list, comment="检索到的相关内容,格式为[{}, {}]")
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=datetime.datetime.now, nullable=False, index=True, comment="创建时间")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<LongTermMemory(id={self.id}, end_user_id={self.end_user_id}, created_at={self.created_at})>"
|
||||
Reference in New Issue
Block a user