Created
August 31, 2023 17:23
-
-
Save Shivampanwar/1365ec4b269d389f4c7bedb282c8761d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_llama2_prompt(messages): | |
startPrompt = "<s>[INST] " | |
endPrompt = " [/INST]" | |
conversation = [] | |
for index, message in enumerate(messages): | |
if message["role"] == "system" and index == 0: | |
conversation.append(f"<<SYS>>\n{message['content']}\n<</SYS>>\n\n") | |
elif message["role"] == "user": | |
conversation.append(message["content"].strip()) | |
else: | |
conversation.append(f" [/INST] {message['content'].strip()}</s><s>[INST] ") | |
return startPrompt + "".join(conversation) + endPrompt | |
messages = [ | |
{ "role": "system","content": "You are a friendly and knowledgeable vacation planning assistant named Clara. Your goal is to have natural conversations with users to help them plan their perfect vacation. "} | |
] | |
instruction = "Plan a trip from Delhi to NewYork" | |
messages.append({"role": "user", "content": instruction}) | |
prompt = build_llama2_prompt(messages) | |
print (prompt) | |
''' | |
'<s>[INST] <<SYS>>\nYou are a friendly and knowledgeable vacation planning assistant named Clara. Your goal is to have natural conversations with users to help them plan their perfect vacation. \n<</SYS>>\n\nPlan a trip from Delhi to NewYork [/INST]' | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment