huoyan-enterprise/backend/models/knowledge_base.py

75 lines
2.4 KiB
Python
Raw Permalink 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 datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class KnowledgeBase(BaseModel):
"""知识库模型"""
id: Optional[int] = None
user_id: int
enterprise_id: Optional[int] = None
department_id: Optional[int] = None
creator_id: Optional[int] = None
visibility: str = Field("private", description="private | department | enterprise")
name: str = Field(..., max_length=255)
description: Optional[str] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
is_deleted: bool = False
deleted_at: Optional[datetime] = None
class Config:
from_attributes = True
class KnowledgeBaseCreate(BaseModel):
"""创建知识库请求模型"""
name: str = Field(..., max_length=255, description="知识库名称")
description: Optional[str] = Field(None, description="知识库描述(可选)")
visibility: str = Field(
"private",
description="可见性private 仅创建者与部门领导department 本部门enterprise 全企业",
)
class KnowledgeBaseUpdate(BaseModel):
"""更新知识库请求模型"""
name: Optional[str] = Field(None, max_length=255, description="知识库名称")
description: Optional[str] = Field(None, description="知识库描述")
visibility: Optional[str] = Field(None, description="private | department | enterprise")
class KnowledgeBaseResponse(BaseModel):
"""知识库响应模型"""
id: int
user_id: int
enterprise_id: Optional[int] = None
department_id: Optional[int] = None
creator_id: Optional[int] = None
visibility: str = "private"
name: str
description: Optional[str] = None
created_at: datetime
updated_at: datetime
# 列表/详情展示创建者与部门JOIN 得到)
creator_username: Optional[str] = None
creator_display_name: Optional[str] = None
department_name: Optional[str] = None
is_mine: bool = Field(False, description="当前登录用户是否为创建者")
class Config:
from_attributes = True
class KnowledgeBaseListResponse(BaseModel):
"""知识库列表响应模型"""
total: int = Field(..., description="总数量")
items: list[KnowledgeBaseResponse] = Field(..., description="知识库列表")
class Config:
from_attributes = True