Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Conversation:
sep_style: SeparatorStyle = SeparatorStyle.ADD_COLON_SINGLE
sep: str = "\n"
sep2: str = None
prefix_token = ""
# Stop criteria (the default one is EOS token)
stop_str: Union[str, List[str]] = None
# Stops generation if meeting any token in this list
Expand All @@ -62,6 +63,7 @@ def get_prompt(self) -> str:
"""Get the prompt for generation."""
system_prompt = self.system_template.format(system_message=self.system_message)
if self.sep_style == SeparatorStyle.ADD_COLON_SINGLE:
self.prefix_token = self.roles[1] + ": "
ret = system_prompt + self.sep
for role, message in self.messages:
if message:
Expand All @@ -70,6 +72,7 @@ def get_prompt(self) -> str:
ret += role + ":"
return ret
elif self.sep_style == SeparatorStyle.ADD_COLON_TWO:
self.prefix_token = self.roles[1] + ": "
seps = [self.sep, self.sep2]
ret = system_prompt + seps[0]
for i, (role, message) in enumerate(self.messages):
Expand All @@ -79,6 +82,9 @@ def get_prompt(self) -> str:
ret += role + ":"
return ret
elif self.sep_style == SeparatorStyle.ADD_COLON_SPACE_SINGLE:
self.prefix_token = self.roles[1] + ": "
if self.sep2 is None:
self.sep2 = self.roles[0] + ": "
ret = system_prompt + self.sep
for role, message in self.messages:
if message:
Expand Down Expand Up @@ -125,6 +131,7 @@ def get_prompt(self) -> str:
ret += role + ":"
return ret
elif self.sep_style == SeparatorStyle.LLAMA2:
self.prefix_token = self.roles[1] + " "
seps = [self.sep, self.sep2]
if self.system_message:
ret = system_prompt
Expand Down Expand Up @@ -159,6 +166,9 @@ def get_prompt(self) -> str:
ret += f"{role}:"
return ret
elif self.sep_style == SeparatorStyle.CHATML:
self.prefix_token = self.roles[1] + "\n"
if self.sep2 is None:
self.sep2 = self.sep
ret = "" if system_prompt == "" else system_prompt + self.sep + "\n"
for role, message in self.messages:
if message:
Expand Down Expand Up @@ -300,6 +310,7 @@ def copy(self):
sep_style=self.sep_style,
sep=self.sep,
sep2=self.sep2,
prefix_token=self.prefix_token,
stop_str=self.stop_str,
stop_token_ids=self.stop_token_ids,
)
Expand Down
Loading