def create(name: str, age: int, weight: float, human: bool, hat_id: int = None) -> dict: """ Create character """ result: dict = {} try: # if hat_id is not None, check if exists, throw exception instead if hat_id is not None: hat = HatModel.query.get(hat_id) if hat is None: raise ResourceDoesNotExist( "Hat {} does not exist".format(hat_id)) character = CharacterModel(name=name, age=age, weight=weight, human=human, hat_id=hat_id) character.save() result = { 'id': character.id, 'name': character.name, 'age': character.age, 'weight': character.weight, 'human': character.human, 'hat_id': character.hat_id, } except IntegrityError: CharacterModel.rollback() # raise ResourceExists('Character already exists') return result
def create(event, context): logger.debug(f'Event received: {json.dumps(event)}') data = json.loads(event.get('body')) character = CharacterModel(id=str(uuid4()), name=data.get('name'), account=data.get('account', 'None'), player_class=int(data.get('player_class')), created_at=datetime.utcnow()) character.save() response = { 'statusCode': 200, 'body': json.dumps(character, cls=ModelEncoder), 'headers': { 'Access-Control-Allow-Origin': '*' } } logger.debug(f'Response: {json.dumps(response)}') return response
char_train_dataset = CharacterDataset(train_texts, train_selected_texts, train_offsets, train_start_logits_list, train_end_logits_list) char_val_dataset = CharacterDataset(val_texts, val_selected_texts, val_offsets_list, val_start_logits_list, val_end_logits_list) char_train_loader = torch.utils.data.DataLoader( dataset=char_train_dataset, batch_size=config.batch_size, shuffle=False) char_val_loader = torch.utils.data.DataLoader( dataset=char_val_dataset, batch_size=config.batch_size, shuffle=False) dataloaders_dict = {'train': char_train_loader, 'val': char_val_loader} char_model = CharacterModel() char_model.to(device) optimizer = optim.AdamW(char_model.parameters(), lr=config.character_lr, betas=(0.9, 0.999)) print('Training Character Model for fold ' + str(fold)) train_character_model(char_model, device, dataloaders_dict, criterion, optimizer, fold)
# } # character = get(request, None) # print() # print() # print(character['body']) # print() # print('All characters') # response = list(None, None) # print(response) character_1 = CharacterModel(name='Angst') character_1.save() print(character_1) character_1.add_item( InventoryItemMap(id=str(uuid4()), slot=1, slot_name='Head', damage=21, crit_chance=.025)) character_1.save() print() print(character_1)