zhangxiao
2024-10-16 30311881800e4840a13f13dd702b093543b2082e
app/api/agent.py
@@ -1,3 +1,5 @@
import uuid
from fastapi import Depends, APIRouter, Query, HTTPException
from pydantic import BaseModel
from sqlalchemy.orm import Session
@@ -26,15 +28,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)
@@ -65,3 +60,11 @@
    else:
        return ResponseList(code=200, msg="Unsupported agent type")
@router.get("/get-chat-id/{agent_id}", response_model=Response)
async def agent_list(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")
    return Response(code=200, msg="", data={"chat_id": uuid.uuid4().hex})