From 633a8ed975625851f23398f896594581c179f612 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期一, 23 十二月 2024 09:45:50 +0800 Subject: [PATCH] mysql链接数量 --- app/api/agent.py | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/api/agent.py b/app/api/agent.py index 2bde98c..fb1ad87 100644 --- a/app/api/agent.py +++ b/app/api/agent.py @@ -9,6 +9,7 @@ from app.api import Response, get_current_user, ResponseList, process_files from app.api.user import reset_user_pwd from app.config.config import settings +from app.models import DialogModel, MenuCapacityModel from app.models.agent_model import AgentType, AgentModel from app.models.base_model import get_db from app.models.session_model import SessionModel @@ -17,6 +18,7 @@ from app.service.dialog import get_session_history from app.service.ragflow import RagflowService from app.service.service_token import get_ragflow_token, get_bisheng_token +from app.task.fetch_agent import initialize_agents router = APIRouter() @@ -35,22 +37,24 @@ limit: int = Query(1000, ge=1, le=1000), db: Session = Depends(get_db), current_user: UserModel = Depends(get_current_user)): - agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() + # agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() + agent = db.query(MenuCapacityModel).filter(MenuCapacityModel.chat_id == agent_id).first() if not agent: return ResponseList(code=404, msg="Agent not found") - - if agent.agent_type == AgentType.RAGFLOW: + agent_type = int(agent.capacity_type) + if agent_type == AgentType.RAGFLOW: ragflow_service = RagflowService(base_url=settings.fwr_base_url) try: token = await get_ragflow_token(db, current_user.id) result = await ragflow_service.get_chat_sessions(token, agent_id) if not result: - result = await get_session_history(db, current_user.id, agent_id) + result = await get_session_history(db, current_user.id, agent_id, page, limit) except Exception as e: + print(e) raise HTTPException(status_code=500, detail=str(e)) return ResponseList(code=200, msg="", data=result) - elif agent.agent_type == AgentType.BISHENG: + elif agent_type == AgentType.BISHENG: bisheng_service = BishengService(base_url=settings.sgb_base_url) try: token = await get_bisheng_token(db, current_user.id) @@ -59,13 +63,13 @@ raise HTTPException(status_code=500, detail=str(e)) return ResponseList(code=200, msg="", data=result) - elif agent.agent_type == AgentType.BASIC: + elif agent_type == AgentType.BASIC: offset = (page - 1) * limit records = db.query(SessionModel).filter(SessionModel.agent_id == agent_id, SessionModel.tenant_id==current_user.id).order_by(SessionModel.create_date.desc()).offset(offset).limit(limit).all() result = [item.to_dict() for item in records] return ResponseList(code=200, msg="", data=result) - elif agent.agent_type == AgentType.DIFY: + elif agent_type == AgentType.DIFY: offset = (page - 1) * limit records = db.query(SessionModel).filter(SessionModel.agent_id == agent_id, SessionModel.tenant_id==current_user.id).order_by(SessionModel.create_date.desc()).offset(offset).limit(limit).all() result = [item.to_dict() for item in records] @@ -250,8 +254,8 @@ @router.get("/get-chat-id/{agent_id}", response_model=Response) async def get_chat_id(agent_id: str, db: Session = Depends(get_db)): - agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() - if not agent: - return Response(code=404, msg="Agent not found") + # agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() + # if not agent: + # return Response(code=404, msg="Agent not found") return Response(code=200, msg="", data={"chat_id": uuid.uuid4().hex}) -- Gitblit v1.8.0