Commit e85f3e8a authored by 林洋洋's avatar 林洋洋

添加知识库相关类

parent 2a74dc05
This diff is collapsed.
......@@ -12,3 +12,4 @@ from .menu import VadminMenu
from .role import VadminRole
from .user import VadminUser
from .dept import VadminDept
from .knowledge import KnowledgeDept
......@@ -16,7 +16,7 @@ class VadminDept(BaseModel):
__table_args__ = ({'comment': '部门表'})
name: Mapped[str] = mapped_column(String(50), index=True, nullable=False, comment="部门名称")
dept_key: Mapped[str] = mapped_column(String(50), index=True, nullable=False, comment="部门标识")
dept_key: Mapped[str | None] = mapped_column(String(50), comment="部门标识")
disabled: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否禁用")
order: Mapped[int | None] = mapped_column(Integer, comment="显示排序")
desc: Mapped[str | None] = mapped_column(String(255), comment="描述")
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Create Time : 2023/10/23 13:41
# @File : dept.py
# @IDE : PyCharm
# @desc : 部门模型
from sqlalchemy.orm import Mapped, mapped_column
from dbgpt.app.apps.db.db_base import BaseModel
from sqlalchemy import String, Integer, ForeignKey
class KnowledgeDept(BaseModel):
__tablename__ = "knowledge_space"
__table_args__ = ({'comment': '知识库表'})
name: Mapped[str] = mapped_column(String(100), index=True, nullable=False, comment="名称")
# vector_type: Mapped[str] = mapped_column(String(50), nullable=False, comment="vector_type")
# domain_type: Mapped[str] = mapped_column(String(50), nullable=False, comment="domain_type")
# desc: Mapped[int | str] = mapped_column(String(500), nullable=False,comment="desc")
......@@ -39,3 +39,10 @@ vadmin_auth_role_depts = Table(
Column("dept_id", Integer, ForeignKey("vadmin_auth_dept.id", ondelete="CASCADE")),
)
vadmin_auth_role_knowledge = Table(
"vadmin_auth_role_knowledge",
Base.metadata,
Column("role_id", Integer, ForeignKey("vadmin_auth_role.id", ondelete="CASCADE")),
Column("knowledge_id", Integer, ForeignKey("knowledge_space.id", ondelete="CASCADE")),
)
from fastapi import Depends, Query
from dbgpt.app.apps.core.dependencies import Paging, QueryParams
class KnowledgeParams(QueryParams):
"""
列表分页
"""
def __init__(
self,
name: str | None = Query(None, title="部门名称"),
params: Paging = Depends()
):
super().__init__(params)
self.name = ("like", name)
......@@ -2,3 +2,4 @@ from .user import UserOut, UserUpdate, User, UserIn, UserSimpleOut, ResetPwd, Us
from .role import Role, RoleOut, RoleIn, RoleOptionsOut, RoleSimpleOut
from .menu import Menu, MenuSimpleOut, RouterOut, Meta, MenuTreeListOut
from .dept import Dept, DeptSimpleOut, DeptTreeListOut
from .knowledge import Knowledge, KnowledgeOut
\ No newline at end of file
......@@ -13,7 +13,7 @@ from dbgpt.app.apps.core.data_types import DatetimeStr
class Dept(BaseModel):
name: str
dept_key: str
dept_key: str | None = None
disabled: bool = False
order: int | None = None
desc: str | None = None
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Create Time : 2023/10/25 12:19
# @File : dept.py
# @IDE : PyCharm
# @desc : pydantic 模型,用于数据库序列化操作
from pydantic import BaseModel, ConfigDict
from dbgpt.app.apps.core.data_types import DatetimeStr
class Knowledge(BaseModel):
name: str
class KnowledgeOut(Knowledge):
model_config = ConfigDict(from_attributes=True)
id: int
create_datetime: DatetimeStr
......@@ -106,7 +106,6 @@ async def user_current_reset_password(data: schemas.ResetPwd, auth: Auth = Depen
@router.post("/user/current/update/password", summary="修改用户密码")
async def user_current_update_password(data: schemas.UpdatePwd, auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.UserDal(auth.db).update_password_id(data))
......@@ -327,3 +326,12 @@ async def put_dept(
auth: Auth = Depends(FullAdminAuth())
):
return SuccessResponse(await crud.DeptDal(auth.db).put_data(data_id, data))
@router.get("/knowledges", summary="获取全部知识库")
async def get_knowledges(auth: Auth = Depends(OpenAuth())):
schema = schemas.KnowledgeOut
knowledge_list = await crud.KnowledgeDal(auth.db).get_datas(v_schema=schema)
role_knowledge_list = await crud.KnowledgeDal(auth.db).get_datas(v_schema=schema)
return SuccessResponse({"role_knowledge_list": role_knowledge_list, "knowledge_list": knowledge_list})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment