Пример #1
0
    def test_create_authentication_token_with_expire_time(self, monkeypatch):
        start_date = datetime.datetime.now()
        token = Authentication.create_access_token(data={"sub": "test"},
                                                   token_expire=180)
        payload = jwt.decode(token,
                             Authentication.SECRET_KEY,
                             algorithms=[Authentication.ALGORITHM])
        assert round((datetime.datetime.fromtimestamp(payload.get('exp')) -
                      start_date).total_seconds() / 60) == 180
        assert payload.get('sub') == 'test'

        start_date = datetime.datetime.now()
        token = Authentication.create_access_token(data={"sub": "test"})
        payload = jwt.decode(token,
                             Authentication.SECRET_KEY,
                             algorithms=[Authentication.ALGORITHM])
        assert round((datetime.datetime.fromtimestamp(payload.get('exp')) -
                      start_date).total_seconds() / 60) == 10080

        monkeypatch.setattr(Authentication, 'ACCESS_TOKEN_EXPIRE_MINUTES',
                            None)
        start_date = datetime.datetime.now()
        token = Authentication.create_access_token(data={"sub": "test"})
        payload = jwt.decode(token,
                             Authentication.SECRET_KEY,
                             algorithms=[Authentication.ALGORITHM])
        assert round((datetime.datetime.fromtimestamp(payload.get('exp')) -
                      start_date).total_seconds() / 60) == 15
Пример #2
0
                               AddStoryRequest, SimpleStoryRequest)
from kairon.data_processor.constant import MODEL_TRAINING_STATUS, TRAINING_DATA_GENERATOR_STATUS
from kairon.data_processor.data_objects import TrainingExamples
from kairon.data_processor.processor import (
    MongoProcessor,
    AgentProcessor,
    ModelProcessor,
    TrainingDataGenerationProcessor,
)
from kairon.exceptions import AppException
from kairon.train import start_training
from kairon.utils import Utility
from urllib.parse import urljoin

router = APIRouter()
auth = Authentication()
mongo_processor = MongoProcessor()


@router.get("/intents", response_model=Response)
async def get_intents(current_user: User = Depends(auth.get_current_user)):
    """
    Fetches list of existing intents for particular bot
    """
    return Response(
        data=mongo_processor.get_intents(current_user.get_bot())).dict()


@router.get("/intents/all", response_model=Response)
async def get_intents_with_training_examples(current_user: User = Depends(
    auth.get_current_user)):