コード例 #1
0
async def fallback_trend(month: int = Query(default=6, ge=1, le=6),
                         current_user: User = Security(
                             Authentication.get_current_user_and_bot,
                             scopes=TESTER_ACCESS)):
    """
    Fetches the fallback count of the bot for previous months
    """
    fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(
        current_user.get_bot())
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/trends/fallback', {
            'month': month,
            'action_fallback': fallback_action,
            'nlu_fallback': nlu_fallback_action
        })
コード例 #2
0
async def get_integrations(current_user: User = Security(
    Authentication.get_current_user_and_bot, scopes=TESTER_ACCESS), ):
    """
    List available integrations.
    """
    return Response(data=list(
        IntegrationProcessor.get_integrations(current_user.get_bot())))
コード例 #3
0
async def get_delete_history_logs(current_user: User = Security(
    Authentication.get_current_user_and_bot, scopes=ADMIN_ACCESS)):
    """
    Get history deletion event logs.
    """
    logs = list(HistoryDeletionLogProcessor.get_logs(current_user.get_bot()))
    return Response(data=logs)
コード例 #4
0
async def fallback_dropoff(month: int = Query(default=1, ge=1, le=6),
                           current_user: User = Security(
                               Authentication.get_current_user_and_bot,
                               scopes=TESTER_ACCESS)):
    """
    Fetches the list of users that dropped off after encountering fallback
    """
    fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(
        current_user.get_bot())
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/fallback/dropoff', {
            'month': month,
            'action_fallback': fallback_action,
            'nlu_fallback': nlu_fallback_action
        })
コード例 #5
0
async def visitor_hit_fallback(month: int = Query(default=1, ge=1, le=6),
                               current_user: User = Security(
                                   Authentication.get_current_user_and_bot,
                                   scopes=TESTER_ACCESS)):
    """
    Fetches the number of times the agent hit a fallback (ie. not able to answer) to user queries
    """
    fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(
        current_user.get_bot())
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/fallback', {
            'month': month,
            'action_fallback': fallback_action,
            'nlu_fallback': nlu_fallback_action
        })
コード例 #6
0
async def unsuccessful_session_count(
        month: int = Query(default=1, ge=1, le=6),
        current_user: User = Security(Authentication.get_current_user_and_bot,
                                      scopes=TESTER_ACCESS)):
    """
    Fetches the count of sessions that encountered a fallback for a particular user.
    """
    fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(
        current_user.get_bot())
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/sessions/unsuccessful',
        {
            'month': month,
            'action_fallback': fallback_action,
            'nlu_fallback': nlu_fallback_action
        })
コード例 #7
0
async def complete_conversations(month: int = Query(default=1, ge=1, le=6),
                                 current_user: User = Security(
                                     Authentication.get_current_user_and_bot,
                                     scopes=TESTER_ACCESS)):
    """
    Fetches the number of successful conversations of the bot, which had no fallback
    """
    fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(
        current_user.get_bot())
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/conversation/success',
        {
            'month': month,
            'action_fallback': fallback_action,
            'nlu_fallback': nlu_fallback_action
        })
コード例 #8
0
async def get_users_details(current_user: User = Depends(
    Authentication.get_current_user)):
    """
    returns the details of the current logged-in user
    """
    user_details = AccountProcessor.get_user_details_and_filter_bot_info_for_integration_user(
        current_user.email, current_user.is_integration_user,
        current_user.get_bot())
    return {"data": {"user": user_details}}
コード例 #9
0
 def wrapped(current_user: User, **kwargs):
     today = datetime.today()
     today_start = today.replace(hour=0, minute=0, second=0)
     account = Account.objects().get(id=current_user.account)
     limit = account.license['training'] if "training" in account.license else Utility.environment['model']['train'][
         "limit_per_day"]
     count = ModelTraining.objects(bot=current_user.get_bot(), start_timestamp__gte=today_start).count()
     if count >= limit:
         raise AppException("Training limit exhausted!")
コード例 #10
0
async def conversation_time(month: int = Query(default=1, ge=1, le=6),
                            current_user: User = Security(
                                Authentication.get_current_user_and_bot,
                                scopes=TESTER_ACCESS)):
    """
    Fetches the duration of the chat that took place between the users and the agent"""
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/conversation/time',
        {'month': month})
コード例 #11
0
async def delete_bot_conversations_history(
    background_tasks: BackgroundTasks,
    month: int = Query(default=3, ge=1, le=6),
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS)):
    """
    Deletes bot chat history for all users up to certain months  min 1 month max 6 months
    """
    HistoryDeletionLogProcessor.is_event_in_progress(
        bot=current_user.get_bot())
    ChatHistoryUtils.validate_history_endpoint(bot=current_user.get_bot())
    background_tasks.add_task(EventsTrigger.trigger_history_deletion,
                              bot=current_user.get_bot(),
                              user=current_user.get_user(),
                              month=month)
    return {
        "message":
        "Delete chat history initiated. It may take a while. Check logs!"
    }
コード例 #12
0
async def calculate_retention(month: int = Query(default=1, ge=1, le=6),
                              current_user: User = Security(
                                  Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS)):
    """
    Fetches the user retention percentage of the bot
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/users/retention',
        {'month': month})
コード例 #13
0
async def total_sessions(month: int = Query(default=1, ge=1, le=6),
                         current_user: User = Security(
                             Authentication.get_current_user_and_bot,
                             scopes=TESTER_ACCESS)):
    """
    Fetches the total session count for users for the past months.
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/sessions/total',
        {'month': month})
コード例 #14
0
async def flat_conversations(month: int = Query(default=1, ge=1, le=6),
                             current_user: User = Security(
                                 Authentication.get_current_user_and_bot,
                                 scopes=TESTER_ACCESS)):
    """
    Fetches the flattened conversation data of the bot for previous months
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/conversations/',
        {'month': month})
コード例 #15
0
async def user_with_metrics(month: int = Query(default=1, ge=1, le=6),
                            current_user: User = Security(
                                Authentication.get_current_user_and_bot,
                                scopes=TESTER_ACCESS)):
    """
    Fetches the list of user who has conversation with the agent with steps anf time
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/users',
        {'month': month})
コード例 #16
0
async def user_intent_dropoff(month: int = Query(default=1, ge=1, le=6),
                              current_user: User = Security(
                                  Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS)):
    """
    Fetches the identified intents and their counts for users before dropping off from the conversations.
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/intents/dropoff',
        {'month': month})
コード例 #17
0
async def user_input_unique(
    month: int = Query(default=1, ge=1, le=6),
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS),
):
    """
    Returns the list of user inputs that are not included as part of training examples
    """
    queries_not_present = ChatHistoryUtils.unique_user_input(
        month, current_user.get_bot())
    return Response(data=queries_not_present)
コード例 #18
0
async def conversation_time_trend(month: int = Query(default=6, ge=1, le=6),
                                  current_user: User = Security(
                                      Authentication.get_current_user_and_bot,
                                      scopes=TESTER_ACCESS)):
    """
    Fetches the average conversation time of the bot for previous months
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/trends/conversations/time',
        {'month': month})
コード例 #19
0
async def count_new_users(month: int = Query(default=1, ge=1, le=6),
                          current_user: User = Security(
                              Authentication.get_current_user_and_bot,
                              scopes=TESTER_ACCESS)):
    """
    Fetches the number of new users of the bot
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/users/new',
        {'month': month})
コード例 #20
0
async def list_bots(current_user: User = Depends(
    Authentication.get_current_user)):
    """
    List bots for account.
    """
    bots = AccountProcessor.get_accessible_bot_details(current_user.account,
                                                       current_user.email)
    if current_user.is_integration_user:
        bots = Utility.filter_bot_details_for_integration_user(
            current_user.get_bot(), bots)
    return Response(data=bots)
コード例 #21
0
async def chat_history(sender: Text,
                       month: int = Query(default=1, ge=1, le=6),
                       current_user: User = Security(
                           Authentication.get_current_user_and_bot,
                           scopes=TESTER_ACCESS)):
    """
    Fetches the list of conversation with the agent by particular user
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/conversations/users/{sender}',
        {'month': month})
コード例 #22
0
async def delete_user_chat_history(background_tasks: BackgroundTasks,
                                   sender: Text,
                                   month: int = Query(default=3, ge=1, le=6),
                                   current_user: User = Security(
                                       Authentication.get_current_user_and_bot,
                                       scopes=ADMIN_ACCESS)):
    """
    Deletes user chat history up to certain months  min 3 month max 6 months
    """
    HistoryDeletionLogProcessor.is_event_in_progress(
        bot=current_user.get_bot())
    ChatHistoryUtils.validate_history_endpoint(bot=current_user.get_bot())
    background_tasks.add_task(EventsTrigger.trigger_history_deletion,
                              bot=current_user.get_bot(),
                              user=current_user.get_user(),
                              month=month,
                              sender_id=sender)
    return {
        "message":
        "Delete user history initiated. It may take a while. Check logs!"
    }
コード例 #23
0
async def download_conversations(
    month: int = Query(default=1, ge=1, le=6),
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS),
):
    """
    Downloads conversation history of the bot, for the specified months
    """
    response = Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/conversations/download',
        {'month': month},
        return_json=False)

    bot_name = [
        bot['name'] for bot in AccountProcessor.list_bots(current_user.account)
        if bot['_id'] == current_user.get_bot()
    ][0]
    response.headers[
        "Content-Disposition"] = f"attachment; filename=conversation_history_{bot_name}{datetime.date.today().strftime('_%d_%m_%y.csv')}"
    return StreamingResponse(BytesIO(response.content),
                             headers=response.headers)
コード例 #24
0
async def update_integration_token(
    request: IntegrationRequest,
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=ADMIN_ACCESS),
):
    """
    Enable/disable/delete an integration.
    """
    Authentication.update_integration_token(request.name,
                                            current_user.get_bot(),
                                            current_user.get_user(),
                                            int_status=request.status)
    return {"message": "Integration status updated!"}
コード例 #25
0
async def engaged_users_trend(month: int = Query(default=6, ge=1, le=6),
                              conversation_step_threshold: int = 10,
                              current_user: User = Security(
                                  Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS)):
    """
    Fetches the counts of engaged users of the bot for previous months
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/trends/users/engaged', {
            'month': month,
            'conversation_step_threshold': conversation_step_threshold
        })
コード例 #26
0
async def top_n_actions(month: int = Query(default=1, ge=1, le=6),
                        top_n: int = Query(default=10, ge=1),
                        current_user: User = Security(
                            Authentication.get_current_user_and_bot,
                            scopes=TESTER_ACCESS)):
    """
    Fetches the top n identified actions of the bot
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/metrics/actions/topmost', {
            'month': month,
            'top_n': top_n
        })
コード例 #27
0
async def word_cloud(
    month: int = Query(default=1, ge=1, le=6),
    l_bound: float = Query(default=0, ge=0, lt=1),
    u_bound: float = Query(default=1, gt=0, le=1),
    stopword_list: list = Query(default=None),
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=TESTER_ACCESS),
):
    """
    Returns the conversation string that is required for word cloud formation
    """
    return Utility.trigger_history_server_request(
        current_user.get_bot(),
        f'/api/history/{current_user.get_bot()}/conversations/wordcloud', {
            'u_bound': u_bound,
            'l_bound': l_bound,
            'stopword_list': stopword_list,
            'month': month
        })
コード例 #28
0
async def generate_integration_token(
    request: IntegrationRequest,
    current_user: User = Security(Authentication.get_current_user_and_bot,
                                  scopes=ADMIN_ACCESS),
):
    """
    Generates an access token for api integration.
    """
    access_token = Authentication.generate_integration_token(
        current_user.get_bot(),
        current_user.get_user(),
        expiry=request.expiry_minutes,
        name=request.name,
        access_limit=request.access_list,
        role=request.role)
    return {
        "data": {
            "access_token": access_token,
            "token_type": "bearer"
        },
        "message":
        """This token will be shown only once. Please copy this somewhere safe. 
            It is your responsibility to keep the token secret. If leaked, others may have access to your system."""
    }
コード例 #29
0
 def wrapped(current_user: User, **kwargs):
     account = Account.objects().get(id=current_user.account)
     count = Intents.objects(bot=current_user.get_bot()).count()
     limit = account.license['intents'] if "intents" in account.license else 10
     if count >= limit:
         raise AppException("Intent limit exhausted!")
コード例 #30
0
 def wrapped(current_user: User, **kwargs):
     account = Account.objects().get(id=current_user.account)
     limit = account.license['augmentation'] if "augmentation" in account.license else 5
     count = ModelTraining.objects(bot=current_user.get_bot()).count()
     if count >= limit:
         raise AppException("Daily augmentation limit exhausted!")