async def chat(request_data: TextData, current_user: User = Depends(auth.get_current_user)): """ Fetches a bot response for a given text/query. It is basically used to test the chat functionality of the agent """ model = AgentProcessor.get_agent(current_user.get_bot()) response = await model.handle_text(request_data.data, sender_id=current_user.get_user()) return {"data": {"response": response}}
async def predict_intent(request_data: TextData, current_user: User = Depends(auth.get_current_user)): """ Fetches the predicted intent of the entered text form the loaded agent """ model = AgentProcessor.get_agent(current_user.get_bot()) response = await model.parse_message_using_nlu_interpreter( request_data.data) intent = response.get("intent").get("name") if response else None confidence = response.get("intent").get("confidence") if response else None return {"data": {"intent": intent, "confidence": confidence}}
async def chat( request_data: TextData, current_user: User = Depends(auth.get_current_user) ): """ Fetches a bot response for a given text/query. It is basically used to test the chat functionality of the agent """ if Utility.environment.get('model') and Utility.environment['model']['train'].get('agent_url'): agent_url = Utility.environment['model']['train'].get('agent_url') token = auth.create_access_token(data={"sub": current_user.email}) response = Utility.http_request('post', urljoin(agent_url, "/api/bot/chat"), token.decode('utf8'), current_user.get_user(), json={'data': request_data.data}) else: model = AgentProcessor.get_agent(current_user.get_bot()) response = await model.handle_text( request_data.data, sender_id=current_user.get_user() ) response = {"data": {"response": response}} return response