! pip install datasets
!pip install accelerate -U

import numpy as np
from transformers import AutoTokenizer, AutoConfig, AutoModelForPreTraining, \
                         TrainingArguments, Trainer
import torch
from torch.utils.data import Dataset

import json
with open('/content/conversations.json') as file:
    data = json.load(file)
def load_conversations_from_json(json_data):
    context = []
    response = []
    conversations = json_data['conversations']
    for conv in conversations:
        messages = conv['messages']
        for i in range(len(messages)-1):
            if messages[i]['type'] == 'customer' and messages[i+1]['type'] == 'agent':
                context.append(messages[i]['message'])
                response.append(messages[i+1]['message'])
    return context, response

SPECIAL_TOKENS  = { "bos_token": "
",
                    "eos_token": "
",
                    "unk_token": "
",
                    "pad_token": "
",
                    "sep_token": "
"}
MAXLEN = 60

class myDataset(Dataset):

  def __init__(self, data, tokenizer):

    context, response = [], []

    for k, v in data.items():
      context.append(v[0])
      response.append(v[1])

    self.tokenizer = tokenizer
    self.response  = response
    self.context      = context

  def __len__(self):
    return len(self.context)

  def __getitem__(self, i):

    input = SPECIAL_TOKENS['bos_token'] + self.context[i] + \
            SPECIAL_TOKENS['sep_token'] + \
            self.response[i] + SPECIAL_TOKENS['eos_token']

    encodings_dict = tokenizer(input,
                              truncation=True,
                              max_length=MAXLEN,
                              padding="max_length")

    input_ids = encodings_dict['input_ids']
    attention_mask = encodings_dict['attention_mask']

    return {'label': torch.tensor(input_ids),
            'input_ids': torch.tensor(input_ids),
            'attention_mask': torch.tensor(attention_mask)}

tokenizer = AutoTokenizer.from_pretrained('gpt2')

tokenizer.add_special_tokens(SPECIAL_TOKENS)

config = AutoConfig.from_pretrained('gpt2',
                                    bos_token_id=tokenizer.bos_token_id,
                                    eos_token_id=tokenizer.eos_token_id,
                                    sep_token_id=tokenizer.sep_token_id,
                                    pad_token_id=tokenizer.pad_token_id,
                                    output_hidden_states=False)

model = AutoModelForPreTraining.from_pretrained('gpt2', config=config)
model.resize_token_embeddings(len(tokenizer))
model.cuda()

context_train, response_train = load_conversations_from_json(data)
context_val, response_val = load_conversations_from_json(data)



train_data = dict()
i=0

for context, response in zip (context_train, response_train):
  train_data[i] = [context, response]
  i += 1

#********************************************
val_data = dict()
i=0

for context, response in zip (context_val, response_val):
  val_data[i] = [context, response]
  i += 1

train_dataset = myDataset(train_data, tokenizer)
val_dataset = myDataset(val_data, tokenizer)

training_args = TrainingArguments(
    output_dir="/content",
    num_train_epochs=3,
    eval_steps = 2000,
    save_steps=2000,
    warmup_steps=500,
    prediction_loss_only=True,
    learning_rate = 5e-4,
    do_eval = True,
    evaluation_strategy = 'steps'
    )

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    eval_dataset=val_dataset,
    tokenizer=tokenizer
)

trainer.train()

trainer.save_model('/content/drive/MyDrive/final model')
based on this code i want to add this knowledge based md file 
# Knowledge Base

## Chargeback

- Chargebacks beyond 90 days are not possible.
- Chargebacks above $1000 are not allowed
- Chargebacks for transactions with a valid 3D secure are not allowed