Exemplo n.º 1
0
async def upload_Files(
        background_tasks: BackgroundTasks,
        nlu: UploadFile = File(...),
        domain: UploadFile = File(...),
        stories: UploadFile = File(...),
        config: UploadFile = File(...),
        overwrite: bool = True,
        current_user: User = Depends(auth.get_current_user),
):
    """
    Uploads training data nlu.md, domain.yml, stories.md and config.yml files
    """
    await mongo_processor.upload_and_save(
        await nlu.read(),
        await domain.read(),
        await stories.read(),
        await config.read(),
        current_user.get_bot(),
        current_user.get_user(),
        overwrite,
    )
    background_tasks.add_task(
        start_training, current_user.get_bot(), current_user.get_user()
    )
    return {"message": "Data uploaded successfully!"}
Exemplo n.º 2
0
async def train(
        background_tasks: BackgroundTasks,
        current_user: User = Depends(auth.get_current_user),
):
    """
    Trains the chatbot
    """
    ModelProcessor.is_training_inprogress(current_user.get_bot())
    ModelProcessor.is_daily_training_limit_exceeded(current_user.get_bot())
    background_tasks.add_task(start_training, current_user.get_bot(),
                              current_user.get_user())
    return {"message": "Model training started."}
Exemplo n.º 3
0
Arquivo: bot.py Projeto: Anitej/kairon
async def get_action_server_logs(start_idx: int = 0,
                                 page_size: int = 10,
                                 current_user: User = Depends(
                                     auth.get_current_user)):
    """
    Retrieves action server logs for the bot.
    """
    logs = list(
        mongo_processor.get_action_server_logs(current_user.get_bot(),
                                               start_idx, page_size))
    row_cnt = mongo_processor.get_row_count(HttpActionLog,
                                            current_user.get_bot())
    data = {"logs": logs, "total": row_cnt}
    return Response(data=data)
Exemplo n.º 4
0
async def set_endpoint(
        background_tasks: BackgroundTasks,
        endpoint: Endpoint,
        current_user: User = Depends(auth.get_current_user),
):
    """
    Saves or Updates the bot endpoint configuration
    """
    mongo_processor.add_endpoints(endpoint.dict(), current_user.get_bot(),
                                  current_user.get_user())

    if endpoint.action_endpoint:
        background_tasks.add_task(AgentProcessor.reload,
                                  current_user.get_bot())
    return {"message": "Endpoint saved successfully!"}
Exemplo n.º 5
0
async def get_all_synonyms(
        current_user: User = Depends(auth.get_current_user_and_bot), ):
    """
    Fetches the stored synonyms of the bot
    """
    synonyms = list(mongo_processor.fetch_synonyms(current_user.get_bot()))
    return {"data": synonyms}
Exemplo n.º 6
0
async def get_data_importer_logs(current_user: User = Depends(
    auth.get_current_user_and_bot)):
    """
    Get data importer event logs.
    """
    logs = list(DataImporterLogProcessor.get_logs(current_user.get_bot()))
    return Response(data=logs)
Exemplo n.º 7
0
async def get_config(
        current_user: User = Depends(auth.get_current_user_and_bot), ):
    """
    Fetches bot pipeline and polcies configurations
    """
    config = mongo_processor.load_config(current_user.get_bot())
    return {"data": {"config": config}}
Exemplo n.º 8
0
async def get_intents(current_user: User = Depends(
    auth.get_current_user_and_bot)):
    """
    Fetches list of existing intents for particular bot
    """
    return Response(
        data=mongo_processor.get_intents(current_user.get_bot())).dict()
Exemplo n.º 9
0
Arquivo: bot.py Projeto: Anitej/kairon
async def get_latest_data_generation_status(
        current_user: User = Depends(auth.get_current_user), ):
    """
    Fetches status for latest data generation request
    """
    slots = list(mongo_processor.get_existing_slots(current_user.get_bot()))
    return {"data": slots}
Exemplo n.º 10
0
async def count_new_users(month: HistoryMonth = 1,
                          current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of new users of the bot
    """
    user_count, message = ChatHistory.new_users(current_user.get_bot(), month)
    return {"data": user_count, "message": message}
Exemplo n.º 11
0
async def deploy(current_user: User = Depends(auth.get_current_user)):
    """
    Deploys the latest bot model to the particular http endpoint
    """
    response = mongo_processor.deploy_model(bot=current_user.get_bot(),
                                            user=current_user.get_user())
    return {"message": response}
Exemplo n.º 12
0
async def get_intents_with_training_examples(current_user: User = Depends(
    auth.get_current_user)):
    """
    Fetches list of existing intents and associated training examples for particular bot
    """
    return Response(data=mongo_processor.get_intents_and_training_examples(
        current_user.get_bot())).dict()
Exemplo n.º 13
0
async def chat_history_users(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):

    """
    Fetches the list of user who has conversation with the agent
    """
    users, message = ChatHistory.fetch_chat_users(current_user.get_bot(), month)
    return {"data": {"users": users}, "message": message}
Exemplo n.º 14
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!")
Exemplo n.º 15
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!")
Exemplo n.º 16
0
 def wrapped(current_user: User, **kwargs):
     account = Account.objects().get(id=current_user.account)
     limit = account.license[
         'examples'] if "examples" in account.license else 50
     count = TrainingExamples.objects(bot=current_user.get_bot()).count()
     if count >= limit:
         raise AppException("Training example limit exhausted!")
Exemplo n.º 17
0
async def get_endpoint(current_user: User = Depends(auth.get_current_user), ):
    """
    Fetches the http and mongo endpoint for the bot
    """
    endpoint = mongo_processor.get_endpoints(current_user.get_bot(),
                                             raise_exception=False)
    return {"data": {"endpoint": endpoint}}
Exemplo n.º 18
0
async def get_model_training_history(
        current_user: User = Depends(auth.get_current_user), ):
    """
    Fetches model training history, when and who trained the bot
    """
    training_history = list(
        ModelProcessor.get_training_history(current_user.get_bot()))
    return {"data": {"training_history": training_history}}
Exemplo n.º 19
0
async def complete_conversations(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of successful conversations of the bot, which had no fallback
    """
    conversation_count, message = ChatHistory.successful_conversations(
        current_user.get_bot(), month
    )
    return {"data": conversation_count, "message": message}
Exemplo n.º 20
0
async def visitor_hit_fallback(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of times the agent hit a fallback (ie. not able to answer) to user queries
    """
    visitor_hit_fallback, message = ChatHistory.visitor_hit_fallback(
        current_user.get_bot(), month
    )
    return {"data": visitor_hit_fallback, "message": message}
Exemplo n.º 21
0
async def conversation_time(month: HistoryMonth = 1,
                            current_user: User = Depends(
                                auth.get_current_user)):
    """
    Fetches the duration of the chat that took place between the users and the agent"""
    conversation_time, message = ChatHistory.conversation_time(
        current_user.get_bot(), month)
    return {"data": conversation_time, "message": message}
Exemplo n.º 22
0
async def get_trainData_history(
        current_user: User = Depends(auth.get_current_user), ):
    """
    Fetches File Data Generation history, when and who initiated the process
    """
    file_history = TrainingDataGenerationProcessor.get_training_data_generator_history(
        current_user.get_bot())
    return {"data": {"training_history": file_history}}
Exemplo n.º 23
0
async def complete_conversation_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the counts of successful conversations of the bot for previous months
    """
    range_value, message = ChatHistory.successful_conversation_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Exemplo n.º 24
0
async def calculate_retention(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the user retention percentage of the bot
    """
    retention_count, message = ChatHistory.user_retention(
        current_user.get_bot(), month
    )
    return {"data": retention_count, "message": message}
Exemplo n.º 25
0
async def add_utterance(request: TextData,
                        current_user: User = Depends(
                            auth.get_current_user_and_bot)):
    mongo_processor.add_utterance_name(request.data,
                                       current_user.get_bot(),
                                       current_user.get_user(),
                                       raise_error_if_exists=True)
    return {'message': 'Utterance added'}
Exemplo n.º 26
0
async def retention_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the counts of user retention percentages of the bot for previous months
    """
    range_value, message = ChatHistory.user_retention_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Exemplo n.º 27
0
async def get_all_responses(current_user: User = Depends(
    auth.get_current_user_and_bot)):
    """
    Fetches list of all utterances added.
    """
    return {
        "data": list(mongo_processor.get_all_responses(current_user.get_bot()))
    }
Exemplo n.º 28
0
async def chat_history(
    sender: Text, month: HistoryMonth = 1,current_user: User = Depends(auth.get_current_user)
):
    """
    Fetches the list of conversation with the agent by particular user
    """
    history, message = ChatHistory.fetch_chat_history(current_user.get_bot(), sender, month)
    return {"data": {"history": list(history)}, "message": message}
Exemplo n.º 29
0
async def get_latest_data_generation_status(
        current_user: User = Depends(auth.get_current_user), ):
    """
    Fetches status for latest data generation request
    """
    latest_data_generation_status = TrainingDataGenerationProcessor.fetch_latest_workload(
        current_user.get_bot(), current_user.get_user())
    return {"data": latest_data_generation_status}
Exemplo n.º 30
0
async def list_epoch_and_fallback_properties(current_user: User = Depends(
    auth.get_current_user_and_bot)):
    """
    List properties (epoch and fallback) in the bot pipeline and policies configurations
    """
    config = mongo_processor.list_epoch_and_fallback_config(
        current_user.get_bot())
    return {"data": config}