From cbb634f9c133c726a00faf8199ba8954e18d4b05 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 15 十月 2024 14:33:45 +0800
Subject: [PATCH] 智能体列表增加排序和类型字段
---
app/models/agent_model.py | 22 +++++++++++++++++-----
app/api/agent.py | 12 ++----------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/app/api/agent.py b/app/api/agent.py
index cded0f8..416db71 100644
--- a/app/api/agent.py
+++ b/app/api/agent.py
@@ -26,15 +26,8 @@
@router.get("/list", response_model=ResponseList)
async def agent_list(db: Session = Depends(get_db)):
- agents = db.query(AgentModel).all()
- result = [
- {
- "id": item.id,
- "name": item.name,
- "agent_type": item.agent_type
- }
- for item in agents
- ]
+ agents = db.query(AgentModel).order_by(AgentModel.sort.asc()).all()
+ result = [item.to_dict() for item in agents]
return ResponseList(code=200, msg="", data=result)
@@ -64,4 +57,3 @@
else:
return ResponseList(code=200, msg="Unsupported agent type")
-
diff --git a/app/models/agent_model.py b/app/models/agent_model.py
index 1b2bdb2..f8fc5ff 100644
--- a/app/models/agent_model.py
+++ b/app/models/agent_model.py
@@ -1,15 +1,27 @@
-from enum import IntEnum
-from sqlalchemy import Column, String, Enum as SQLAlchemyEnum
+from enum import IntEnum, StrEnum
+from sqlalchemy import Column, String, Enum as SQLAlchemyEnum, Integer
from app.models.base_model import Base
class AgentType(IntEnum):
RAGFLOW = 1
BISHENG = 2
+ BASIC = 3
class AgentModel(Base):
__tablename__ = "agent"
- id = Column(String(255), primary_key=True, index=True)
- name = Column(String(255), index=True)
- agent_type = Column(SQLAlchemyEnum(AgentType), nullable=False) # 1 ragflow 2 bisheng
+ id = Column(String(255), primary_key=True)
+ name = Column(String(255))
+ sort = Column(Integer, default=0, nullable=False)
+ agent_type = Column(SQLAlchemyEnum(AgentType), nullable=False)
+ type = Column(String(255), nullable=False)
+
+ # to_dict 鏂规硶
+ def to_dict(self):
+ return {
+ 'id': self.id,
+ 'name': self.name,
+ 'agent_type': self.agent_type,
+ 'type': self.type
+ }
--
Gitblit v1.8.0