Merge branch 'master' of http://192.168.5.5:10010/r/rag-gateway
| | |
| | | return ResponseList(code=200, msg="Unsupported agent type") |
| | | |
| | | |
| | | @router.get("/{conversation_id}/session_log") |
| | | async def session_log(conversation_id: str, db: Session = Depends(get_db), current_user: UserModel = Depends(get_current_user)): |
| | | 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}) |
| | | @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) |
| | |
| | | ] |
| | | return result |
| | | |
| | | async def get_session_log(self, token: str, agent_id: str, conversation_id: str): |
| | | url = ( |
| | | f"{self.base_url}/api/v1/chat/history?" |
| | | f"flow_id={agent_id}&" |
| | | f"chat_id={conversation_id}&page_size=30&id=" |
| | | ) |
| | | headers = {'cookie': f"access_token_cookie={token};"} |
| | | async with httpx.AsyncClient() as client: |
| | | response = await client.get(url, headers=headers) |
| | | response.raise_for_status() |
| | | data = self._check_response(response) |
| | | session_log = { |
| | | "session_log": [ |
| | | { |
| | | "message": message.get("intermediate_steps"), |
| | | "role": message.get("category"), |
| | | } |
| | | for message in data |
| | | ], |
| | | } |
| | | return session_log |
| | | |
| | | async def variable_list(self, token: str, agent_id: str) -> list: |
| | | url = f"{self.base_url}/api/v1/variable/list?flow_id={agent_id}" |
| | | headers = {'cookie': f"access_token_cookie={token};"} |
| | |
| | | response = await client.get(url, headers=headers) |
| | | data = self._handle_response(response) |
| | | session_log = { |
| | | "dialog_id": data.get("dialog_id"), |
| | | "id": data.get("id"), |
| | | "message": [ |
| | | "session_log": [ |
| | | { |
| | | "content": message.get("content"), |
| | | "message": message.get("content"), |
| | | "role": message.get("role"), |
| | | } |
| | | for message in data.get("message", []) |
| | | ], |
| | | "name": data.get("name"), |
| | | "reference": data.get("reference"), |
| | | } |
| | | return session_log |