Commit 4a7eb1f7 authored by 张会鑫's avatar 张会鑫

代码提交

parent fd472c01
from .dict import DictType, DictDetails, DictTypeSimpleOut, DictDetailsSimpleOut, DictTypeOptionsOut
from .settings_tab import SettingsTab, SettingsTabSimpleOut
from .settings import Settings, SettingsSimpleOut
from .task import Task, TaskSimpleOut
...@@ -35,9 +35,9 @@ async def get_dict_types(p: DictTypeParams = Depends(), auth: Auth = Depends(All ...@@ -35,9 +35,9 @@ async def get_dict_types(p: DictTypeParams = Depends(), auth: Auth = Depends(All
return SuccessResponse(datas, count=count) return SuccessResponse(datas, count=count)
@router.post("/dict/types", summary="创建字典类型") # @router.post("/dict/types", summary="创建字典类型")
async def create_dict_types(data: schemas.DictType, auth: Auth = Depends(AllUserAuth())): # async def create_dict_types(data: schemas.DictType, auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.DictTypeDal(auth.db).create_data(data=data)) # return SuccessResponse(await crud.DictTypeDal(auth.db).create_data(data=data))
@router.delete("/dict/types", summary="批量删除字典类型") @router.delete("/dict/types", summary="批量删除字典类型")
...@@ -60,23 +60,23 @@ async def get_dicts_options(auth: Auth = Depends(AllUserAuth())): ...@@ -60,23 +60,23 @@ async def get_dicts_options(auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.DictTypeDal(auth.db).get_select_datas()) return SuccessResponse(await crud.DictTypeDal(auth.db).get_select_datas())
@router.put("/dict/types/{data_id}", summary="更新字典类型") # @router.put("/dict/types/{data_id}", summary="更新字典类型")
async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depends(AllUserAuth())): # async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.DictTypeDal(auth.db).put_data(data_id, data)) # return SuccessResponse(await crud.DictTypeDal(auth.db).put_data(data_id, data))
@router.get("/dict/types/{data_id}", summary="获取字典类型详细") # @router.get("/dict/types/{data_id}", summary="获取字典类型详细")
async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())): # async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())):
schema = schemas.DictTypeSimpleOut # schema = schemas.DictTypeSimpleOut
return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, v_schema=schema)) # return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, v_schema=schema))
########################################################### ###########################################################
# 字典元素管理 # 字典元素管理
########################################################### ###########################################################
@router.post("/dict/details", summary="创建字典元素") # @router.post("/dict/details", summary="创建字典元素")
async def create_dict_details(data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())): # async def create_dict_details(data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.DictDetailsDal(auth.db).create_data(data=data)) # return SuccessResponse(await crud.DictDetailsDal(auth.db).create_data(data=data))
@router.get("/dict/details", summary="获取单个字典类型下的字典元素列表,分页") @router.get("/dict/details", summary="获取单个字典类型下的字典元素列表,分页")
...@@ -91,15 +91,15 @@ async def delete_dict_details(ids: IdList = Depends(), auth: Auth = Depends(AllU ...@@ -91,15 +91,15 @@ async def delete_dict_details(ids: IdList = Depends(), auth: Auth = Depends(AllU
return SuccessResponse("删除成功") return SuccessResponse("删除成功")
@router.put("/dict/details/{data_id}", summary="更新字典元素") # @router.put("/dict/details/{data_id}", summary="更新字典元素")
async def put_dict_details(data_id: int, data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())): # async def put_dict_details(data_id: int, data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())):
return SuccessResponse(await crud.DictDetailsDal(auth.db).put_data(data_id, data)) # return SuccessResponse(await crud.DictDetailsDal(auth.db).put_data(data_id, data))
@router.get("/dict/details/{data_id}", summary="获取字典元素详情") # @router.get("/dict/details/{data_id}", summary="获取字典元素详情")
async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())): # async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
schema = schemas.DictDetailsSimpleOut # schema = schemas.DictDetailsSimpleOut
return SuccessResponse(await crud.DictDetailsDal(auth.db).get_data(data_id, v_schema=schema)) # return SuccessResponse(await crud.DictDetailsDal(auth.db).get_data(data_id, v_schema=schema))
# ########################################################### # ###########################################################
...@@ -123,11 +123,11 @@ async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())): ...@@ -123,11 +123,11 @@ async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
# return SuccessResponse(result) # return SuccessResponse(result)
@router.post("/upload/image/to/local", summary="上传图片到本地") # @router.post("/upload/image/to/local", summary="上传图片到本地")
async def upload_image_to_local(file: UploadFile, path: str = Form(...)): # async def upload_image_to_local(file: UploadFile, path: str = Form(...)):
manage = FileManage(file, path) # manage = FileManage(file, path)
path = await manage.save_image_local() # path = await manage.save_image_local()
return SuccessResponse(path) # return SuccessResponse(path)
########################################################### ###########################################################
......
...@@ -12,4 +12,3 @@ from .menu import VadminMenu ...@@ -12,4 +12,3 @@ from .menu import VadminMenu
from .role import VadminRole from .role import VadminRole
from .user import VadminUser from .user import VadminUser
from .dept import VadminDept from .dept import VadminDept
from .knowledge import KnowledgeDept
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Create Time : 2022/2/24 10:21
# @File : crud.py
# @IDE : PyCharm
# @desc : 增删改查
from typing import Any
from sqlalchemy.orm.strategy_options import _AbstractLoad, contains_eager
from dbgpt.app.apps.core.exception import CustomException
from sqlalchemy import select, false, and_
from dbgpt.app.apps.core.crud import DalBase
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select, update
from . import models, schemas
from dbgpt.app.apps.utils import status
from .params.media_list import MediaEditParams, QuestionEditParams
class MediaDal(DalBase):
def __init__(self, db: AsyncSession):
super(MediaDal, self).__init__()
self.db = db
self.model = models.VadminMedia
self.schema = schemas.MediaOut
async def update_media_datas(self, params: MediaEditParams) -> None:
"""
编辑资源名称、分组
"""
if params.file_name is not None:
# 文件名称不为空 判定为重命名
sql = update(self.model).where(self.model.id.in_(params.ids)).values(file_name=params.file_name)
await self.db.execute(sql)
elif params.group_id is not None:
# 文件分组不为空 判定为移动分组
sql = update(self.model).where(self.model.id.in_(params.ids)).values(group_id=params.group_id)
await self.db.execute(sql)
class GroupDal(DalBase):
def __init__(self, db: AsyncSession):
super(GroupDal, self).__init__()
self.db = db
self.model = models.VadminGroup
self.schema = schemas.GroupOut
class QuestionDal(DalBase):
def __init__(self, db: AsyncSession):
super(QuestionDal, self).__init__()
self.db = db
self.model = models.VadminQuestion
self.schema = schemas.QuestionOut
async def update_question_datas(self, params: QuestionEditParams) -> None:
if params.group_id is not None:
# 文件分组不为空 判定为移动分组
sql = update(self.model).where(self.model.id.in_(params.ids)).values(group_id=params.group_id)
await self.db.execute(sql)
else:
# 否则判定为修改问答对
sql = update(self.model).where(self.model.id.in_(params.ids)).values(title=params.title,
key_word=params.key_word,
answer=params.answer)
await self.db.execute(sql)
class CorrelationDal(DalBase):
def __init__(self, db: AsyncSession):
super(CorrelationDal, self).__init__()
self.db = db
self.model = models.VadminCorrelation
self.schema = schemas.CorrelationOut
\ No newline at end of file
from .media import VadminMedia
from .media import VadminGroup
from .media import VadminQuestion
from .media import VadminCorrelation
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sqlalchemy.orm import Mapped, mapped_column
from dbgpt.app.apps.db.db_base import BaseModel
from sqlalchemy import String, ForeignKey, Integer, JSON
class VadminMedia(BaseModel):
__tablename__ = "vadmin_media"
__table_args__ = ({'comment': '资源表'})
file_name: Mapped[str] = mapped_column(String(500), index=True, nullable=False, comment="文件原名称")
type: Mapped[int] = mapped_column(Integer, nullable=False, comment="类型")
group_id: Mapped[int] = mapped_column(Integer, nullable=True, comment="关联分组id")
key_word: Mapped[str] = mapped_column(String(500), comment="关键词")
local_path: Mapped[str] = mapped_column(String(500), nullable=False, comment="绝对路径")
remote_path: Mapped[str] = mapped_column(String(500), nullable=False, comment="访问路径")
is_delete: Mapped[int] = mapped_column(Integer, comment="是否删除", default=0)
class VadminGroup(BaseModel):
__tablename__ = "vadmin_group"
__table_args__ = ({'comment': '分组表'})
name: Mapped[str] = mapped_column(String(500), index=True, nullable=False, comment="组名称")
type: Mapped[int] = mapped_column(Integer, nullable=False, comment="类型")
is_delete: Mapped[int] = mapped_column(Integer, comment="是否删除", default=0)
class VadminQuestion(BaseModel):
__tablename__ = "vadmin_question"
__table_args__ = ({'comment': '问答对表'})
title: Mapped[str] = mapped_column(String(500), index=True, nullable=False, comment="问题标题")
key_word: Mapped[str] = mapped_column(String(255), comment="关键词")
answer: Mapped[str] = mapped_column(String(2000), comment="标准答案")
group_id: Mapped[int] = mapped_column(Integer, nullable=True, comment="关联分组id")
is_delete: Mapped[int] = mapped_column(Integer, comment="是否删除", default=0)
class VadminCorrelation(BaseModel):
__tablename__ = "knowledge_space"
__table_args__ = ({'comment': '知识库表'})
name: Mapped[str] = mapped_column(String(100), comment="知识库名称")
image_group: Mapped[str] = mapped_column(JSON, nullable=True, comment="图片分组")
video_group: Mapped[str] = mapped_column(JSON, nullable=True, comment="视频分组")
question_group: Mapped[str] = mapped_column(JSON, nullable=True, comment="问答对分组")
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-
from fastapi import Depends
from dbgpt.app.apps.core.dependencies import Paging, QueryParams
class MediaListParams(QueryParams):
"""
列表分页
"""
def __init__(self, group_id: int = None, type: int = None, file_name: str = None, params: Paging = Depends()):
super().__init__(params)
self.type = type
self.group_id = group_id
self.file_name = ("like", file_name)
class GroupListParams(QueryParams):
def __init__(self, type: int = None):
super().__init__()
self.type = type
class MediaEditParams:
def __init__(self, ids: list[int] = None, file_name: str = None, group_id: int = None):
super().__init__()
self.ids = ids
self.file_name = file_name
self.group_id = group_id
class QuestionListParams(QueryParams):
def __init__(self, group_id: int = None, title: str = None, params: Paging = Depends()):
super().__init__(params)
self.group_id = group_id
self.title = ("like", title)
class QuestionEditParams:
def __init__(self, ids: list[int] = None, title: str = None, group_id: int = None, key_word: str = None, answer: str = None):
super().__init__()
self.ids = ids
self.title = title
self.key_word = key_word
self.answer = answer
self.group_id = group_id
class CorrelationListParams(QueryParams):
def __init__(self, name: str = None, params: Paging = Depends()):
super().__init__(params)
self.name = ("like", name)
\ No newline at end of file
from .media import Media
from .media import MediaOut
from .media import Group
from .media import GroupOut
from .media import Question
from .media import QuestionOut
from .media import Correlation
from .media import CorrelationOut
from .media import GroupJson
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pydantic import BaseModel, ConfigDict, Field
from dbgpt.app.apps.core.data_types import DatetimeStr
from typing import List
class Media(BaseModel):
file_name: str
type: int
group_id: int | None = 0
key_word: str | None = None
local_path: str
remote_path: str
class MediaOut(Media):
model_config = ConfigDict(from_attributes=True)
id: int
create_datetime: DatetimeStr
update_datetime: DatetimeStr
class Group(BaseModel):
name: str
type: int
class GroupOut(Group):
model_config = ConfigDict(from_attributes=True)
id: int
create_datetime: DatetimeStr
update_datetime: DatetimeStr
class Question(BaseModel):
title: str
key_word: str
answer: str
group_id: int | None = 0
class QuestionOut(Question):
model_config = ConfigDict(from_attributes=True)
id: int
create_datetime: DatetimeStr
update_datetime: DatetimeStr
class GroupJson(BaseModel):
group_id: int
group_name: str
class Correlation(BaseModel):
id: int
image_group: List[GroupJson] | None = None
video_group: List[GroupJson] | None = None
question_group: List[GroupJson] | None = None
class CorrelationOut(Correlation):
model_config = ConfigDict(from_attributes=True)
id: int
name: str
from fastapi import APIRouter, Depends, Body, UploadFile, Form, Request
from dbgpt.app.apps.utils.file.file_manage import FileManage
from dbgpt.app.apps.utils.response import SuccessResponse
from dbgpt.app.apps.vadmin.auth.utils.current import FullAdminAuth
from dbgpt.app.apps.vadmin.auth.utils.validation.auth import Auth
from . import schemas, crud
from .params.media_list import MediaListParams, GroupListParams, MediaEditParams, QuestionListParams, \
QuestionEditParams, CorrelationListParams
from ...core.dependencies import IdList
router = APIRouter()
@router.post("/upload/image", summary="上传图片到本地")
async def upload_image_to_local(file: UploadFile, path: str = Form(...)):
manage = FileManage(file, path)
path = await manage.save_image_local()
return SuccessResponse(path)
@router.post("/upload/video", summary="上传视频到本地")
async def upload_video_to_local(file: UploadFile, path: str = Form(...)):
manage = FileManage(file, path)
path = await manage.save_video_local()
return SuccessResponse(path)
@router.post("/upload/save", summary="上传提交保存")
async def upload_save(data: schemas.Media, auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.MediaDal(auth.db).create_data(data=data))
@router.post("/media/list", summary="资源列表(图片、视频)")
async def media_image_list(params: MediaListParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
datas, count = await crud.MediaDal(auth.db).get_datas(**params.dict(), v_return_count=True)
return SuccessResponse(datas, count=count)
@router.post("/media/del", summary="删除资源")
async def media_edit(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
await crud.MediaDal(auth.db).delete_datas(ids.ids, v_soft=True)
return SuccessResponse("删除成功")
@router.post("/group/add", summary="新建分组")
async def group_add(data: schemas.Group, auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.GroupDal(auth.db).create_data(data=data))
@router.get("/group/list", summary="分组列表")
async def image_list(params: GroupListParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
datas, count = await crud.GroupDal(auth.db).get_datas(**params.dict(), v_return_count=True)
return SuccessResponse(datas, count=count)
@router.post("/group/del", summary="删除分组")
async def group_del(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
await crud.GroupDal(auth.db).delete_datas(ids.ids, v_soft=True)
return SuccessResponse("删除成功")
@router.post("/media/edit", summary="编辑资源名称、归属分组")
async def media_edit(params: MediaEditParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.MediaDal(auth.db).update_media_datas(params))
@router.post("/question/add", summary="新建问答对")
async def question_add(data: schemas.Question, auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.QuestionDal(auth.db).create_data(data=data))
@router.post("/question/list", summary="问答对列表")
async def question_list(params: QuestionListParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
datas, count = await crud.QuestionDal(auth.db).get_datas(**params.dict(), v_return_count=True)
return SuccessResponse(datas, count=count)
@router.post("/question/del", summary="删除问答对")
async def question_add(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.QuestionDal(auth.db).delete_datas(ids.ids, v_soft=True))
@router.post("/question/edit", summary="编辑问答对")
async def question_edit(params: QuestionEditParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.QuestionDal(auth.db).update_question_datas(params))
@router.post("/correlation/edit", summary="编辑知识库关联关系")
async def correlation_add(data: schemas.Correlation, auth: Auth = Depends(FullAdminAuth())):
return SuccessResponse(await crud.CorrelationDal(auth.db).put_data(data_id=data.id, data=data))
@router.post("/correlation/list", summary="问答对列表")
async def correlation_list(params: CorrelationListParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
datas, count = await crud.CorrelationDal(auth.db).get_datas(**params.dict(), v_return_count=True)
return SuccessResponse(datas, count=count)
...@@ -27,7 +27,7 @@ from dbgpt.configs.model_config import ( ...@@ -27,7 +27,7 @@ from dbgpt.configs.model_config import (
EMBEDDING_MODEL_CONFIG, EMBEDDING_MODEL_CONFIG,
LLM_MODEL_CONFIG, LLM_MODEL_CONFIG,
LOGDIR, LOGDIR,
STATIC_MESSAGE_IMG_PATH, STATIC_MESSAGE_IMG_PATH, STATIC_RESOURCE_PATH,
) )
from dbgpt.serve.core import add_exception_handler from dbgpt.serve.core import add_exception_handler
from dbgpt.util.fastapi import create_app, replace_router from dbgpt.util.fastapi import create_app, replace_router
...@@ -97,6 +97,7 @@ def mount_routers(app: FastAPI): ...@@ -97,6 +97,7 @@ def mount_routers(app: FastAPI):
from dbgpt.app.apps.vadmin.auth.utils.login import router as login from dbgpt.app.apps.vadmin.auth.utils.login import router as login
from dbgpt.app.apps.vadmin.auth.views import router as views from dbgpt.app.apps.vadmin.auth.views import router as views
from dbgpt.app.apps.system.views import router as system_views from dbgpt.app.apps.system.views import router as system_views
from dbgpt.app.apps.vadmin.media.views import router as media_views
from dbgpt.app.apps.vadmin.word.views import router as word_views from dbgpt.app.apps.vadmin.word.views import router as word_views
app.include_router(api_v1, prefix="/api", tags=["Chat"]) app.include_router(api_v1, prefix="/api", tags=["Chat"])
...@@ -110,6 +111,7 @@ def mount_routers(app: FastAPI): ...@@ -110,6 +111,7 @@ def mount_routers(app: FastAPI):
app.include_router(login, prefix="/api/v2/auth", tags=["System"]) app.include_router(login, prefix="/api/v2/auth", tags=["System"])
app.include_router(views, prefix="/api/v2/vadmin/auth", tags=["System"]) app.include_router(views, prefix="/api/v2/vadmin/auth", tags=["System"])
app.include_router(system_views, prefix="/api/v2/vadmin/system", tags=["System"]) app.include_router(system_views, prefix="/api/v2/vadmin/system", tags=["System"])
app.include_router(media_views, prefix="/api/v2", tags=["System"])
app.include_router(word_views, prefix="/api/v2/vadmin/word", tags=["Word"]) app.include_router(word_views, prefix="/api/v2/vadmin/word", tags=["Word"])
...@@ -124,6 +126,11 @@ def mount_static_files(app: FastAPI): ...@@ -124,6 +126,11 @@ def mount_static_files(app: FastAPI):
"/_next/static", StaticFiles(directory=static_file_path + "/_next/static") "/_next/static", StaticFiles(directory=static_file_path + "/_next/static")
) )
app.mount("/", StaticFiles(directory=static_file_path, html=True), name="static") app.mount("/", StaticFiles(directory=static_file_path, html=True), name="static")
app.mount(
"/media",
StaticFiles(directory=STATIC_RESOURCE_PATH, html=True),
name="static3",
)
# add_exception_handler(app) # add_exception_handler(app)
......
...@@ -7,6 +7,7 @@ from functools import cache ...@@ -7,6 +7,7 @@ from functools import cache
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
MODEL_PATH = os.path.join(ROOT_PATH, "models") MODEL_PATH = os.path.join(ROOT_PATH, "models")
PILOT_PATH = os.path.join(ROOT_PATH, "pilot") PILOT_PATH = os.path.join(ROOT_PATH, "pilot")
STATIC_RESOURCE_PATH = os.path.join(ROOT_PATH, "dbgpt/app/apps/static")
LOGDIR = os.getenv("DBGPT_LOG_DIR", os.path.join(ROOT_PATH, "logs")) LOGDIR = os.getenv("DBGPT_LOG_DIR", os.path.join(ROOT_PATH, "logs"))
STATIC_MESSAGE_IMG_PATH = os.path.join(PILOT_PATH, "message/img") STATIC_MESSAGE_IMG_PATH = os.path.join(PILOT_PATH, "message/img")
......
...@@ -543,7 +543,7 @@ def quantization_requires(): ...@@ -543,7 +543,7 @@ def quantization_requires():
"https://jllllll.github.io/bitsandbytes-windows-webui", "https://jllllll.github.io/bitsandbytes-windows-webui",
"0.41.1", "0.41.1",
) )
whl_url = f"https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-{latest_version}-py3-none-win_amd64.whl" whl_url = f"https://gh.llkk.cc/https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl"
local_pkg_path = cache_package(whl_url, "bitsandbytes", True) local_pkg_path = cache_package(whl_url, "bitsandbytes", True)
setup_spec.extras["bitsandbytes"] = [f"bitsandbytes @ {local_pkg_path}"] setup_spec.extras["bitsandbytes"] = [f"bitsandbytes @ {local_pkg_path}"]
else: else:
......
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