1 Answer
- Newest
- Most votes
- Most comments
0
The issue was resolved. It was due to the format of payload.
Previous payload like below is not working. payload = { "inputs": [[ {"role": "system", "content": payload_system}, {"role": "user", "content": result}, ]], "parameters": {"max_new_tokens": 512, "top_p": 0.5, "temperature": 0.5} }. Need to transform the "inputs" of payload to be like: <s>[INST] <<SYS>> {{ system_prompt }} <</SYS>>
{{ user_message }} [/INST] See details of Llama-2 format on https://huggingface.co/blog/llama2#how-to-prompt-llama-2.
The following function can help to transform "inputs" above into correct form.
def format_messages(messages: List[Dict[str, str]]) -> List[str]:
"""Format messages for Llama-2 chat models.
The model only supports 'system', 'user' and 'assistant' roles, starting with 'system', then 'user' and
alternating (u/a/u/a/u...). The last message must be from 'user'.
"""
prompt: List[str] = []
if messages[0]["role"] == "system":
content = "".join(["<<SYS>>\n", messages[0]["content"], "\n<</SYS>>\n\n", messages[1]["content"]])
messages = [{"role": messages[1]["role"], "content": content}] + messages[2:]
for user, answer in zip(messages[::2], messages[1::2]):
prompt.extend(["<s>", "[INST] ", (user["content"]).strip(), " [/INST] ", (answer["content"]).strip(), "</s>"])
prompt.extend(["<s>", "[INST] ", (messages[-1]["content"]).strip(), " [/INST] "])
return "".join(prompt)
answered a year ago
Relevant content
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago