39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
|
|
"""
|
|||
|
|
工具定义模型
|
|||
|
|
"""
|
|||
|
|
from sqlalchemy import Column, String, Text, JSON, DateTime, Boolean, ForeignKey, Integer, func
|
|||
|
|
from sqlalchemy.dialects.mysql import CHAR
|
|||
|
|
from sqlalchemy.orm import relationship
|
|||
|
|
from app.core.database import Base
|
|||
|
|
import uuid
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Tool(Base):
|
|||
|
|
"""工具定义表"""
|
|||
|
|
__tablename__ = "tools"
|
|||
|
|
|
|||
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="工具ID")
|
|||
|
|
name = Column(String(100), nullable=False, unique=True, comment="工具名称")
|
|||
|
|
description = Column(Text, nullable=False, comment="工具描述")
|
|||
|
|
category = Column(String(50), comment="工具分类")
|
|||
|
|
|
|||
|
|
# 工具定义(OpenAI Function格式)
|
|||
|
|
function_schema = Column(JSON, nullable=False, comment="函数定义(JSON Schema)")
|
|||
|
|
|
|||
|
|
# 工具实现类型
|
|||
|
|
implementation_type = Column(String(50), nullable=False, comment="实现类型: builtin/http/workflow/code")
|
|||
|
|
implementation_config = Column(JSON, comment="实现配置")
|
|||
|
|
|
|||
|
|
# 元数据
|
|||
|
|
is_public = Column(Boolean, default=False, comment="是否公开")
|
|||
|
|
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=True, comment="创建者ID")
|
|||
|
|
use_count = Column(Integer, default=0, comment="使用次数")
|
|||
|
|
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
|||
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
|
|||
|
|
|
|||
|
|
# 关系
|
|||
|
|
user = relationship("User", backref="tools")
|
|||
|
|
|
|||
|
|
def __repr__(self):
|
|||
|
|
return f"<Tool(id={self.id}, name={self.name})>"
|