mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-14 13:40:54 +00:00
feat: (0.6)New UI (#1855)
Co-authored-by: 夏姜 <wenfengjiang.jwf@digital-engine.com> Co-authored-by: aries_ckt <916701291@qq.com> Co-authored-by: wb-lh513319 <wb-lh513319@alibaba-inc.com> Co-authored-by: csunny <cfqsunny@163.com>
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
from .gpts_conversations_db import GptsConversationsDao, GptsConversationsEntity
|
||||
from .gpts_manage_db import GptsInstanceDao, GptsInstanceEntity
|
||||
from .gpts_messages_db import GptsMessagesDao, GptsMessagesEntity
|
||||
from .gpts_plans_db import GptsPlansDao, GptsPlansEntity
|
||||
from .my_plugin_db import MyPluginDao, MyPluginEntity
|
||||
from .plugin_hub_db import PluginHubDao, PluginHubEntity
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ from sqlalchemy import (
|
||||
desc,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Query
|
||||
|
||||
from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
@@ -70,6 +71,18 @@ class GptsConversationsDao(BaseDao):
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def get_like_conv_id_asc(self, conv_id: str):
|
||||
session = self.get_raw_session()
|
||||
try:
|
||||
gpts_conv_qry: Query = session.query(GptsConversationsEntity)
|
||||
gpts_conv_qry: Query = gpts_conv_qry.filter(
|
||||
GptsConversationsEntity.conv_id.like(f"{conv_id}%")
|
||||
).order_by(GptsConversationsEntity.id.asc())
|
||||
result = gpts_conv_qry.all()
|
||||
finally:
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def get_convs(self, user_code: str = None, system_app: str = None):
|
||||
session = self.get_raw_session()
|
||||
gpts_conversations = session.query(GptsConversationsEntity)
|
||||
|
@@ -1,104 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
|
||||
from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
|
||||
class GptsInstanceEntity(Model):
|
||||
__tablename__ = "gpts_instance"
|
||||
id = Column(Integer, primary_key=True, comment="autoincrement id")
|
||||
|
||||
gpts_name = Column(String(255), nullable=False, comment="Current AI assistant name")
|
||||
gpts_describe = Column(
|
||||
String(2255), nullable=False, comment="Current AI assistant describe"
|
||||
)
|
||||
team_mode = Column(String(255), nullable=False, comment="Team work mode")
|
||||
is_sustainable = Column(
|
||||
Boolean,
|
||||
nullable=False,
|
||||
default=False,
|
||||
comment="Applications for sustainable dialogue",
|
||||
)
|
||||
|
||||
resource_db = Column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="List of structured database names contained in the current gpts",
|
||||
)
|
||||
resource_internet = Column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="Is it possible to retrieve information from the internet",
|
||||
)
|
||||
resource_knowledge = Column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="List of unstructured database names contained in the current gpts",
|
||||
)
|
||||
gpts_agents = Column(
|
||||
String(1000),
|
||||
nullable=True,
|
||||
comment="List of agents names contained in the current gpts",
|
||||
)
|
||||
gpts_models = Column(
|
||||
String(1000),
|
||||
nullable=True,
|
||||
comment="List of llm model names contained in the current gpts",
|
||||
)
|
||||
language = Column(String(100), nullable=True, comment="gpts language")
|
||||
|
||||
user_code = Column(String(255), nullable=False, comment="user code")
|
||||
sys_code = Column(String(255), nullable=True, comment="system app code")
|
||||
|
||||
created_at = Column(DateTime, default=datetime.utcnow, comment="create time")
|
||||
updated_at = Column(
|
||||
DateTime,
|
||||
default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow,
|
||||
comment="last update time",
|
||||
)
|
||||
|
||||
__table_args__ = (UniqueConstraint("gpts_name", name="uk_gpts"),)
|
||||
|
||||
|
||||
class GptsInstanceDao(BaseDao):
|
||||
def add(self, engity: GptsInstanceEntity):
|
||||
session = self.get_raw_session()
|
||||
session.add(engity)
|
||||
session.commit()
|
||||
id = engity.id
|
||||
session.close()
|
||||
return id
|
||||
|
||||
def get_by_name(self, name: str) -> GptsInstanceEntity:
|
||||
session = self.get_raw_session()
|
||||
gpts_instance = session.query(GptsInstanceEntity)
|
||||
if name:
|
||||
gpts_instance = gpts_instance.filter(GptsInstanceEntity.gpts_name == name)
|
||||
result = gpts_instance.first()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def get_by_user(self, user_code: str = None, sys_code: str = None):
|
||||
session = self.get_raw_session()
|
||||
gpts_instance = session.query(GptsInstanceEntity)
|
||||
if user_code:
|
||||
gpts_instance = gpts_instance.filter(
|
||||
GptsInstanceEntity.user_code == user_code
|
||||
)
|
||||
if sys_code:
|
||||
gpts_instance = gpts_instance.filter(
|
||||
GptsInstanceEntity.sys_code == sys_code
|
||||
)
|
||||
result = gpts_instance.all()
|
||||
session.close()
|
||||
return result
|
@@ -1,7 +1,19 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Column, DateTime, Index, Integer, String, Text, and_, desc, or_
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
Index,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
and_,
|
||||
desc,
|
||||
func,
|
||||
or_,
|
||||
)
|
||||
|
||||
from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
@@ -25,6 +37,17 @@ class GptsMessagesEntity(Model):
|
||||
)
|
||||
model_name = Column(String(255), nullable=True, comment="message generate model")
|
||||
rounds = Column(Integer, nullable=False, comment="dialogue turns")
|
||||
is_success = Column(Boolean, default=True, nullable=True, comment="is success")
|
||||
app_code = Column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
comment="The message in which app",
|
||||
)
|
||||
app_name = Column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
comment="The message in which app name",
|
||||
)
|
||||
content = Column(
|
||||
Text(length=2**31 - 1), nullable=True, comment="Content of the speech"
|
||||
)
|
||||
@@ -40,7 +63,11 @@ class GptsMessagesEntity(Model):
|
||||
nullable=True,
|
||||
comment="Current conversation action report",
|
||||
)
|
||||
|
||||
resource_info = Column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="Current conversation resource info",
|
||||
)
|
||||
role = Column(
|
||||
String(255), nullable=True, comment="The role of the current message content"
|
||||
)
|
||||
@@ -63,13 +90,17 @@ class GptsMessagesDao(BaseDao):
|
||||
sender=entity.get("sender"),
|
||||
receiver=entity.get("receiver"),
|
||||
content=entity.get("content"),
|
||||
is_success=entity.get("is_success", True),
|
||||
role=entity.get("role", None),
|
||||
model_name=entity.get("model_name", None),
|
||||
context=entity.get("context", None),
|
||||
rounds=entity.get("rounds", None),
|
||||
app_code=entity.get("app_code", None),
|
||||
app_name=entity.get("app_name", None),
|
||||
current_goal=entity.get("current_goal", None),
|
||||
review_info=entity.get("review_info", None),
|
||||
action_report=entity.get("action_report", None),
|
||||
resource_info=entity.get("resource_info", None),
|
||||
)
|
||||
session.add(message)
|
||||
session.commit()
|
||||
|
@@ -1,162 +0,0 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, DateTime, Integer, String, UniqueConstraint, func
|
||||
|
||||
from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
from ..model import MyPluginVO
|
||||
|
||||
|
||||
class MyPluginEntity(Model):
|
||||
__tablename__ = "my_plugin"
|
||||
id = Column(Integer, primary_key=True, comment="autoincrement id")
|
||||
tenant = Column(String(255), nullable=True, comment="user's tenant")
|
||||
user_code = Column(String(255), nullable=False, comment="user code")
|
||||
user_name = Column(String(255), nullable=True, comment="user name")
|
||||
name = Column(String(255), unique=True, nullable=False, comment="plugin name")
|
||||
file_name = Column(String(255), nullable=False, comment="plugin package file name")
|
||||
type = Column(String(255), comment="plugin type")
|
||||
version = Column(String(255), comment="plugin version")
|
||||
use_count = Column(
|
||||
Integer, nullable=True, default=0, comment="plugin total use count"
|
||||
)
|
||||
succ_count = Column(
|
||||
Integer, nullable=True, default=0, comment="plugin total success count"
|
||||
)
|
||||
sys_code = Column(String(128), index=True, nullable=True, comment="System code")
|
||||
gmt_created = Column(
|
||||
DateTime, default=datetime.utcnow, comment="plugin install time"
|
||||
)
|
||||
UniqueConstraint("user_code", "name", name="uk_name")
|
||||
|
||||
@classmethod
|
||||
def to_vo(cls, entities: List["MyPluginEntity"]) -> List[MyPluginVO]:
|
||||
results = []
|
||||
for entity in entities:
|
||||
results.append(
|
||||
MyPluginVO(
|
||||
id=entity.id,
|
||||
tenant=entity.tenant,
|
||||
user_code=entity.user_code,
|
||||
user_name=entity.user_name,
|
||||
sys_code=entity.sys_code,
|
||||
name=entity.name,
|
||||
file_name=entity.file_name,
|
||||
type=entity.type,
|
||||
version=entity.version,
|
||||
use_count=entity.use_count,
|
||||
succ_count=entity.succ_count,
|
||||
gmt_created=entity.gmt_created.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
)
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
class MyPluginDao(BaseDao):
|
||||
def add(self, engity: MyPluginEntity):
|
||||
session = self.get_raw_session()
|
||||
my_plugin = MyPluginEntity(
|
||||
tenant=engity.tenant,
|
||||
user_code=engity.user_code,
|
||||
user_name=engity.user_name,
|
||||
name=engity.name,
|
||||
type=engity.type,
|
||||
version=engity.version,
|
||||
use_count=engity.use_count or 0,
|
||||
succ_count=engity.succ_count or 0,
|
||||
sys_code=engity.sys_code,
|
||||
gmt_created=datetime.now(),
|
||||
)
|
||||
session.add(my_plugin)
|
||||
session.commit()
|
||||
id = my_plugin.id
|
||||
session.close()
|
||||
return id
|
||||
|
||||
def raw_update(self, entity: MyPluginEntity):
|
||||
session = self.get_raw_session()
|
||||
updated = session.merge(entity)
|
||||
session.commit()
|
||||
return updated.id
|
||||
|
||||
def get_by_user(self, user: str) -> list[MyPluginEntity]:
|
||||
session = self.get_raw_session()
|
||||
my_plugins = session.query(MyPluginEntity)
|
||||
if user:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_code == user)
|
||||
result = my_plugins.all()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def get_by_user_and_plugin(self, user: str, plugin: str) -> MyPluginEntity:
|
||||
session = self.get_raw_session()
|
||||
my_plugins = session.query(MyPluginEntity)
|
||||
if user:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_code == user)
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.name == plugin)
|
||||
result = my_plugins.first()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def list(self, query: MyPluginEntity, page=1, page_size=20) -> list[MyPluginEntity]:
|
||||
session = self.get_raw_session()
|
||||
my_plugins = session.query(MyPluginEntity)
|
||||
all_count = my_plugins.count()
|
||||
if query.id is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.id == query.id)
|
||||
if query.name is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.name == query.name)
|
||||
if query.tenant is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.tenant == query.tenant)
|
||||
if query.type is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.type == query.type)
|
||||
if query.user_code is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_code == query.user_code)
|
||||
if query.user_name is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_name == query.user_name)
|
||||
if query.sys_code is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.sys_code == query.sys_code)
|
||||
|
||||
my_plugins = my_plugins.order_by(MyPluginEntity.id.desc())
|
||||
my_plugins = my_plugins.offset((page - 1) * page_size).limit(page_size)
|
||||
result = my_plugins.all()
|
||||
session.close()
|
||||
total_pages = all_count // page_size
|
||||
if all_count % page_size != 0:
|
||||
total_pages += 1
|
||||
|
||||
return result, total_pages, all_count
|
||||
|
||||
def count(self, query: MyPluginEntity):
|
||||
session = self.get_raw_session()
|
||||
my_plugins = session.query(func.count(MyPluginEntity.id))
|
||||
if query.id is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.id == query.id)
|
||||
if query.name is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.name == query.name)
|
||||
if query.type is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.type == query.type)
|
||||
if query.tenant is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.tenant == query.tenant)
|
||||
if query.user_code is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_code == query.user_code)
|
||||
if query.user_name is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.user_name == query.user_name)
|
||||
if query.sys_code is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.sys_code == query.sys_code)
|
||||
count = my_plugins.scalar()
|
||||
session.close()
|
||||
return count
|
||||
|
||||
def raw_delete(self, plugin_id: int):
|
||||
session = self.get_raw_session()
|
||||
if plugin_id is None:
|
||||
raise Exception("plugin_id is None")
|
||||
query = MyPluginEntity(id=plugin_id)
|
||||
my_plugins = session.query(MyPluginEntity)
|
||||
if query.id is not None:
|
||||
my_plugins = my_plugins.filter(MyPluginEntity.id == query.id)
|
||||
my_plugins.delete()
|
||||
session.commit()
|
||||
session.close()
|
@@ -1,172 +0,0 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
import pytz
|
||||
from sqlalchemy import (
|
||||
DDL,
|
||||
Column,
|
||||
DateTime,
|
||||
Index,
|
||||
Integer,
|
||||
String,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
|
||||
from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
from ..model import PluginHubVO
|
||||
|
||||
# TODO We should consider that the production environment does not have permission to execute the DDL
|
||||
char_set_sql = DDL("ALTER TABLE plugin_hub CONVERT TO CHARACTER SET utf8mb4")
|
||||
|
||||
|
||||
class PluginHubEntity(Model):
|
||||
__tablename__ = "plugin_hub"
|
||||
id = Column(
|
||||
Integer, primary_key=True, autoincrement=True, comment="autoincrement id"
|
||||
)
|
||||
name = Column(String(255), unique=True, nullable=False, comment="plugin name")
|
||||
description = Column(String(255), nullable=False, comment="plugin description")
|
||||
author = Column(String(255), nullable=True, comment="plugin author")
|
||||
email = Column(String(255), nullable=True, comment="plugin author email")
|
||||
type = Column(String(255), comment="plugin type")
|
||||
version = Column(String(255), comment="plugin version")
|
||||
storage_channel = Column(String(255), comment="plugin storage channel")
|
||||
storage_url = Column(String(255), comment="plugin download url")
|
||||
download_param = Column(String(255), comment="plugin download param")
|
||||
gmt_created = Column(
|
||||
DateTime, default=datetime.utcnow, comment="plugin upload time"
|
||||
)
|
||||
installed = Column(Integer, default=False, comment="plugin already installed count")
|
||||
|
||||
UniqueConstraint("name", name="uk_name")
|
||||
Index("idx_q_type", "type")
|
||||
|
||||
@classmethod
|
||||
def to_vo(cls, entities: List["PluginHubEntity"]) -> List[PluginHubVO]:
|
||||
results = []
|
||||
for entity in entities:
|
||||
vo = PluginHubVO(
|
||||
id=entity.id,
|
||||
name=entity.name,
|
||||
description=entity.description,
|
||||
author=entity.author,
|
||||
email=entity.email,
|
||||
type=entity.type,
|
||||
version=entity.version,
|
||||
storage_channel=entity.storage_channel,
|
||||
storage_url=entity.storage_url,
|
||||
download_param=entity.download_param,
|
||||
installed=entity.installed,
|
||||
gmt_created=entity.gmt_created.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
)
|
||||
results.append(vo)
|
||||
return results
|
||||
|
||||
|
||||
class PluginHubDao(BaseDao):
|
||||
def add(self, engity: PluginHubEntity):
|
||||
session = self.get_raw_session()
|
||||
timezone = pytz.timezone("Asia/Shanghai")
|
||||
plugin_hub = PluginHubEntity(
|
||||
name=engity.name,
|
||||
author=engity.author,
|
||||
email=engity.email,
|
||||
type=engity.type,
|
||||
version=engity.version,
|
||||
storage_channel=engity.storage_channel,
|
||||
storage_url=engity.storage_url,
|
||||
gmt_created=timezone.localize(datetime.now()),
|
||||
)
|
||||
session.add(plugin_hub)
|
||||
session.commit()
|
||||
id = plugin_hub.id
|
||||
session.close()
|
||||
return id
|
||||
|
||||
def raw_update(self, entity: PluginHubEntity):
|
||||
session = self.get_raw_session()
|
||||
try:
|
||||
updated = session.merge(entity)
|
||||
session.commit()
|
||||
return updated.id
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
def list(
|
||||
self, query: PluginHubEntity, page=1, page_size=20
|
||||
) -> list[PluginHubEntity]:
|
||||
session = self.get_raw_session()
|
||||
plugin_hubs = session.query(PluginHubEntity)
|
||||
all_count = plugin_hubs.count()
|
||||
|
||||
if query.id is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.id == query.id)
|
||||
if query.name is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.name == query.name)
|
||||
if query.type is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.type == query.type)
|
||||
if query.author is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.author == query.author)
|
||||
if query.storage_channel is not None:
|
||||
plugin_hubs = plugin_hubs.filter(
|
||||
PluginHubEntity.storage_channel == query.storage_channel
|
||||
)
|
||||
|
||||
plugin_hubs = plugin_hubs.order_by(PluginHubEntity.id.desc())
|
||||
plugin_hubs = plugin_hubs.offset((page - 1) * page_size).limit(page_size)
|
||||
result = plugin_hubs.all()
|
||||
session.close()
|
||||
|
||||
total_pages = all_count // page_size
|
||||
if all_count % page_size != 0:
|
||||
total_pages += 1
|
||||
|
||||
return result, total_pages, all_count
|
||||
|
||||
def get_by_storage_url(self, storage_url):
|
||||
session = self.get_raw_session()
|
||||
plugin_hubs = session.query(PluginHubEntity)
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.storage_url == storage_url)
|
||||
result = plugin_hubs.all()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def get_by_name(self, name: str) -> PluginHubEntity:
|
||||
session = self.get_raw_session()
|
||||
plugin_hubs = session.query(PluginHubEntity)
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.name == name)
|
||||
result = plugin_hubs.first()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def count(self, query: PluginHubEntity):
|
||||
session = self.get_raw_session()
|
||||
plugin_hubs = session.query(func.count(PluginHubEntity.id))
|
||||
if query.id is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.id == query.id)
|
||||
if query.name is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.name == query.name)
|
||||
if query.type is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.type == query.type)
|
||||
if query.author is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.author == query.author)
|
||||
if query.storage_channel is not None:
|
||||
plugin_hubs = plugin_hubs.filter(
|
||||
PluginHubEntity.storage_channel == query.storage_channel
|
||||
)
|
||||
count = plugin_hubs.scalar()
|
||||
session.close()
|
||||
return count
|
||||
|
||||
def raw_delete(self, plugin_id: int):
|
||||
session = self.get_raw_session()
|
||||
if plugin_id is None:
|
||||
raise Exception("plugin_id is None")
|
||||
plugin_hubs = session.query(PluginHubEntity)
|
||||
if plugin_id is not None:
|
||||
plugin_hubs = plugin_hubs.filter(PluginHubEntity.id == plugin_id)
|
||||
plugin_hubs.delete()
|
||||
session.commit()
|
||||
session.close()
|
Reference in New Issue
Block a user