trust-game-llama-2-7b-chat / system_prompt_config.py
botsi's picture
Upload 14 files
6890fdc verified
raw
history blame
5.01 kB
# From Llama2 Local code
from data_fetcher import json_result
'''
# These variables represent the beginning-of-sequence (BOS) and end-of-sequence (EOS) tokens.
BOS, EOS = "<s>", "</s>"
# These variables represent the beginning and end markers for an instruction.
BINST, EINST = "[INST]", "[/INST]"
# These variables define markers to denote the beginning and end of a system message.
# In the context of a chatbot, a system message is information or instructions provided by the system rather than the user.
# The markers here use <<SYS>> to indicate the start and <</SYS>> to indicate the end, with newline characters \n for formatting.
BSYS, ESYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
# This line initializes a multiline string (""") for the default system prompt.
# It's the set of instructions for the chatbot to follow during a conversation in the trust game scenario that will be contained in the system message.
DEFAULT_SYSTEM_PROMPT = """\ Your task is to answer in a consistent style. You answer per question is maximum 2 sentences long.
You are an intelligent and fair game guide in a 2-player trust game.
Your role is to assist players in making decisions during the game.
The game consists of 3 rounds, and each player starts with an initial asset of 10€.
In each round, both players can trust each other with an amount between 0€ and 10€.
The trusted amounts are added, multiplied by 3, divided by 2, and then evenly distributed among the participants.
This sum, along with what's left of their initial assets, becomes their new asset for the next round.
For example, if player A trusts player B with 5€, and player B trusts player A with 3€, the combined trust is (5 + 3) = 8€.
After the multiplier and division, both players receive (8 * 3 / 2) = 12€.
Adding this to what's left from their initial 10€ forms their asset for the next round.
After 3 rounds, the final earnings are calculated using the same process.
You will receive a JSON with information on who trusted whom with how much money after each round as context.
Your goal is to guide players through the game, providing clear instructions and explanations.
If any question or action seems unclear, explain it rather than providing inaccurate information.
If you're unsure about an answer, it's better not to guess.
Example JSON context after a round:
{
"round": 1,
"trust_data": {
"player_A": {"trusts": "player_B", "amount": 5},
"player_B": {"trusts": "player_A", "amount": 3}
}
}
# Example JSON context after a round: {json_result}
# Few-shot training examples
{BSYS} Give an overview of the trust game. {ESYS}
{BSYS} Explain how trust amounts are calculated. {ESYS}
{BSYS} What happens if a player doesn't trust in a round? {ESYS}
"""
# Original: DEFAULT_SYSTEM_PROMPT = """\ 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 construct_input_prompt(chat_history, message) -> str:
# chat_history has the following structure:
# - dialogs
# --- instruction
# --- response (None for the most recent dialog)
input_prompt = ""
for i, dialog in enumerate(chat_history[:-1]):
instruction, response = dialog[0], dialog[1]
# prepend system instruction before first instruction
if i == 0:
instruction = f"{BSYS}{DEFAULT_SYSTEM_PROMPT}{ESYS}" + instruction
else:
# the tokenizer automatically adds a bos_token during encoding,
# for this reason the bos_token is not added for the first instruction
input_prompt += BOS
input_prompt += f"{BINST} {instruction.strip()} {EINST} {response.strip()} " + EOS
# new instruction from the user
new_instruction = chat_history[-1][0].strip()
# the tokenizer automatically adds a bos_token during encoding,
# for this reason the bos_token is not added for the first instruction
if len(chat_history) > 1:
input_prompt += BOS
else:
# prepend system instruction before first instruction
new_instruction = f"{BSYS}{DEFAULT_SYSTEM_PROMPT}{ESYS}" + new_instruction
input_prompt += f"{BINST} {new_instruction} {EINST}"
return input_prompt
'''
# From own code
def get_default_system_prompt():
return "Default System Prompt"
def construct_input_prompt(chat_history, message):
input_prompt = f"<s>[INST] <<SYS>>\n{get_default_system_prompt()}\n<</SYS>>\n\n "
for user, assistant in chat_history:
input_prompt += f"{user} [/INST] {assistant} <s>[INST] "
input_prompt += f"{message} [/INST] "
return input_prompt