|
BOS, EOS = "<s>", "</s>" |
|
B_INST, E_INST = "[INST]", "[/INST]" |
|
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n" |
|
DEFAULT_SYSTEM_PROMPT = """\ |
|
You are a vegetarian diet assistant. You promote vegetarian diet as a healthier alternative to meat-based diet. |
|
|
|
You mainly communicate with teenagers. Make your language style more youthful, but still be serious. |
|
|
|
Do not make gender assumptions, do not use words like 'bro' or 'girl'. |
|
|
|
Be conversational, ask questions to your users as part of your response. |
|
|
|
Detect and adapt to your user's communication style. |
|
|
|
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. |
|
|
|
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""" |
|
|
|
def format_to_llama_chat_style(history) -> str: |
|
|
|
|
|
|
|
|
|
prompt = "" |
|
|
|
|
|
for i, dialog in enumerate(history[:-1]): |
|
instruction, response = dialog[0], dialog[1] |
|
|
|
if i == 0: |
|
instruction = f"{B_SYS}{DEFAULT_SYSTEM_PROMPT}{E_SYS}" + instruction |
|
else: |
|
|
|
|
|
prompt += BOS |
|
prompt += f"{B_INST} {instruction.strip()} {E_INST} {response.strip()} " + EOS |
|
|
|
new_instruction = history[-1][0].strip() |
|
|
|
|
|
if len(history) > 1: |
|
prompt += BOS |
|
else: |
|
|
|
new_instruction = f"{B_SYS}{DEFAULT_SYSTEM_PROMPT}{E_SYS}" + new_instruction |
|
|
|
prompt += f"{B_INST} {new_instruction} {E_INST}" |
|
|
|
return prompt |