Skip to content

Commit 0c37d98

Browse files
authored
Improve chat templates (#2539)
1 parent 125f374 commit 0c37d98

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

fastchat/conversation.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Conversation prompt templates.
33
4-
We kindly request that you import fastchat instead of copying this file if you want to use it.
5-
You can contribute back the changes you want to make.
4+
We kindly request that you import fastchat instead of copying this file if you wish to use it.
5+
If you have any changes in mind, please contribute back so the community can benefit collectively and continue to maintain these valuable templates.
66
"""
77

88
import dataclasses
@@ -1012,7 +1012,9 @@ def get_conv_template(name: str) -> Conversation:
10121012

10131013

10141014
if __name__ == "__main__":
1015-
print("Vicuna template:")
1015+
from fastchat.conversation import get_conv_template
1016+
1017+
print("-- Vicuna template --")
10161018
conv = get_conv_template("vicuna_v1.1")
10171019
conv.append_message(conv.roles[0], "Hello!")
10181020
conv.append_message(conv.roles[1], "Hi!")
@@ -1022,11 +1024,31 @@ def get_conv_template(name: str) -> Conversation:
10221024

10231025
print("\n")
10241026

1025-
print("Llama-2 template:")
1027+
print("-- Llama-2 template --")
10261028
conv = get_conv_template("llama-2")
10271029
conv.set_system_message("You are a helpful, respectful and honest assistant.")
10281030
conv.append_message(conv.roles[0], "Hello!")
10291031
conv.append_message(conv.roles[1], "Hi!")
10301032
conv.append_message(conv.roles[0], "How are you?")
10311033
conv.append_message(conv.roles[1], None)
10321034
print(conv.get_prompt())
1035+
1036+
print("\n")
1037+
1038+
print("-- ChatGPT template --")
1039+
conv = get_conv_template("chatgpt")
1040+
conv.append_message(conv.roles[0], "Hello!")
1041+
conv.append_message(conv.roles[1], "Hi!")
1042+
conv.append_message(conv.roles[0], "How are you?")
1043+
conv.append_message(conv.roles[1], None)
1044+
print(conv.to_openai_api_messages())
1045+
1046+
print("\n")
1047+
1048+
print("-- Claude template --")
1049+
conv = get_conv_template("claude")
1050+
conv.append_message(conv.roles[0], "Hello!")
1051+
conv.append_message(conv.roles[1], "Hi!")
1052+
conv.append_message(conv.roles[0], "How are you?")
1053+
conv.append_message(conv.roles[1], None)
1054+
print(conv.get_prompt())

0 commit comments

Comments
 (0)