From d1f7a4ecdb84acaf6a7d986a13a642a337dd31e5 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期四, 14 十一月 2024 18:17:25 +0800 Subject: [PATCH] 配置组权限 --- app/api/agent.py | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/api/agent.py b/app/api/agent.py index 416db71..59d1f21 100644 --- a/app/api/agent.py +++ b/app/api/agent.py @@ -1,4 +1,7 @@ +import uuid + from fastapi import Depends, APIRouter, Query, HTTPException +from fastapi.responses import JSONResponse from pydantic import BaseModel from sqlalchemy.orm import Session @@ -12,16 +15,6 @@ from app.service.token import get_ragflow_token, get_bisheng_token router = APIRouter() - - -# Pydantic 妯″瀷鐢ㄤ簬鍝嶅簲 -class AgentResponse(BaseModel): - id: str - name: str - agent_type: AgentType - - class Config: - orm_mode = True @router.get("/list", response_model=ResponseList) @@ -38,7 +31,7 @@ return ResponseList(code=404, msg="Agent not found") if agent.agent_type == AgentType.RAGFLOW: - ragflow_service = RagflowService(base_url=settings.ragflow_base_url) + ragflow_service = RagflowService(base_url=settings.fwr_base_url) try: token = get_ragflow_token(db, current_user.id) result = await ragflow_service.get_chat_sessions(token, agent_id) @@ -47,7 +40,7 @@ return ResponseList(code=200, msg="", data=result) elif agent.agent_type == AgentType.BISHENG: - bisheng_service = BishengService(base_url=settings.bisheng_base_url) + bisheng_service = BishengService(base_url=settings.sgb_base_url) try: token = get_bisheng_token(db, current_user.id) result = await bisheng_service.get_chat_sessions(token) @@ -57,3 +50,39 @@ else: return ResponseList(code=200, msg="Unsupported agent type") + + +@router.get("/{agent_id}/{conversation_id}/session_log") +async def session_log(agent_id: str, conversation_id: str, db: Session = Depends(get_db), current_user: UserModel = Depends(get_current_user)): + agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() + if not agent: + return Response(code=404, msg="Agent not found") + + if agent.agent_type == AgentType.RAGFLOW: + ragflow_service = RagflowService(base_url=settings.fwr_base_url) + try: + token = get_ragflow_token(db, current_user.id) + result = await ragflow_service.get_session_log(token, conversation_id) + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + return JSONResponse(status_code=200, content={"code": 200, "log": result}) + if agent.agent_type == AgentType.BISHENG: + bisheng_service = BishengService(base_url=settings.sgb_base_url) + try: + token = get_bisheng_token(db, current_user.id) + result = await bisheng_service.get_session_log(token, agent_id, conversation_id) + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + return JSONResponse(status_code=200, content={"code": 200, "log": result}) + + else: + return JSONResponse(status_code=200, content={"code": 200, "log": "Unsupported agent type"}) + + +@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") + + return Response(code=200, msg="", data={"chat_id": uuid.uuid4().hex}) -- Gitblit v1.8.0