Skip to content

Commit

Permalink
Update chat prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
abetlen committed Apr 15, 2023
1 parent 02f9fb8 commit 6208751
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,12 @@ def create_chat_completion(
Generated chat completion or a stream of chat completion chunks.
"""
stop = stop if stop is not None else []
chat_history = "".join(
f'### {"Human" if message["role"] == "user" else "Assistant"}:{message["content"]}'
for message in messages
)
PROMPT = f" \n\n### Instructions:{instructions}\n\n### Inputs:{chat_history}\n\n### Response:\nassistant: "
PROMPT_STOP = ["###", "\nuser: ", "\nassistant: ", "\nsystem: "]
PROMPT = chat_history + "### Assistant:"
PROMPT_STOP = ["### Assistant:", "### Human:", "\n"]
completion_or_chunks = self(
prompt=PROMPT,
stop=PROMPT_STOP + stop,
Expand Down

2 comments on commit 6208751

@v2rockets
Copy link

@v2rockets v2rockets commented on 6208751 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I know the meaning of this change?
Right now I'm working with Alpaca models and it seems that "### Instruction:" and "### Response:" are the correct prompt words. I don't know if Assistant and Human would work as the same.

@abetlen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@v2rockets this update just ensured that the prompt for the chat model would be "cacheable", currently the model only supports continuing from the end of the last context window, which meant the alpaca instruction syntax would cause a cache miss every time with the old prompt. This syntax follows the Vicuna model prompts which I would recommend at the moment for testing out chat mode as they are trained for this rather than one-off instruction responses.

However, this is a temporary change and once #17 is complete you'll be able to set a custom prompts on a per model basis.

Please sign in to comment.