Skip to content
Merged
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SeparatorStyle(IntEnum):
PHOENIX = auto()
ROBIN = auto()
FALCON_CHAT = auto()
CHATGLM3 = auto()


@dataclasses.dataclass
Expand Down Expand Up @@ -163,6 +164,14 @@ def get_prompt(self) -> str:
else:
ret += role + "\n"
return ret
elif self.sep_style == SeparatorStyle.CHATGLM3:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

ret = "" if system_prompt == "" else system_prompt
Copy link
Contributor

@Jeffwan Jeffwan Nov 5, 2023

Choose a reason for hiding this comment

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

need \n or not?

Copy link

Choose a reason for hiding this comment

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

It doesn't need

for role, message in self.messages:
if message:
ret += role + "\n" + message
Copy link
Contributor

@Jeffwan Jeffwan Nov 5, 2023

Choose a reason for hiding this comment

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

same here. need \n ending or not?

Copy link

Choose a reason for hiding this comment

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

Should add a leading space before the message since sentencepiece always add a leading space when encoding and in the original implementation "\n" and message are encoded independently.

Line 171 should be

ret += role + "\n" + " " + message

else:
ret += role
return ret
elif self.sep_style == SeparatorStyle.CHATINTERN:
# source: https://huggingface.co/internlm/internlm-chat-7b-8k/blob/bd546fa984b4b0b86958f56bf37f94aa75ab8831/modeling_internlm.py#L771
seps = [self.sep, self.sep2]
Expand Down Expand Up @@ -448,6 +457,23 @@ def get_conv_template(name: str) -> Conversation:
)
)

# ChatGLM3 default template
register_conv_template(
Conversation(
name="chatglm3",
system_template="<|system|>\n{system_message}",
system_message="You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.",
roles=("<|user|>", "<|assistant|>"),
sep_style=SeparatorStyle.CHATGLM3,
sep="",
stop_token_ids=[
64795,
64797,
2,
], # "<|user|>", "<|observation|>", "</s>"
)
)

# Dolly V2 default template
register_conv_template(
Conversation(
Expand Down