Files
aiagent/backend/app/models/model_config.py
2026-01-19 00:09:36 +08:00

30 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
模型配置模型
"""
from sqlalchemy import Column, String, DateTime, ForeignKey, func
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.orm import relationship
from app.core.database import Base
import uuid
class ModelConfig(Base):
"""模型配置表"""
__tablename__ = "model_configs"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="配置ID")
name = Column(String(100), nullable=False, comment="配置名称")
provider = Column(String(50), nullable=False, comment="提供商: openai/claude/local")
model_name = Column(String(100), nullable=False, comment="模型名称")
api_key = Column(String(500), nullable=False, comment="API密钥加密存储")
base_url = Column(String(255), comment="API地址")
user_id = Column(CHAR(36), ForeignKey("users.id"), comment="所属用户ID")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
# 关系
user = relationship("User", backref="model_configs")
def __repr__(self):
return f"<ModelConfig(id={self.id}, name={self.name}, provider={self.provider})>"