[ChatStream] ChatPrompt for matsuo-lab/weblab-10b-instruction-sft
We have released a ChatPrompt class for matsuo-lab/weblab-10b-instruction-sft.
It is included in the latest version of ChatStream, but you can also use the code below.
from chatstream import AbstractChatPrompt
from chatstream.chat_prompt.prompt_ttl import PromptTTL
class ChatPromptMatsuoLabJpGptNeoxInstSft(AbstractChatPrompt):
def __init__(self):
super().__init__() # Call the initialization of the base class
# The system prompt and role names below are the model's own Japanese prompt format and must be kept as is.
# System prompt: "The following is a combination of an instruction describing a task and contextual input. Write a response that appropriately satisfies the request."
self.set_system("以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。")
self.set_requester("指示") # "Instruction"
self.set_responder("応答") # "Response"
self.set_prefix_as_stop_str_enabled(True) # enable requester's prompt suffix as stop str
self.set_prompt_ttl(PromptTTL.SINGLE_TURN)
def get_stop_strs(self):
if not self.chat_mode:
return None
return ["Q:"]
def get_replacement_when_input(self):
return None
def get_replacement_when_output(self):
return None
def create_prompt(self, opts={}):
if self.chat_mode == False:
return self.get_requester_last_msg()
# Build the prompt for the case Chat Mode == True
ret = self.system + "\n\n";
for chat_content in self.get_contents(opts):
chat_content_role = chat_content.get_role()
chat_content_message = chat_content.get_message()
chat_content_child_messages = chat_content.get_child_messages()
has_child_messages = chat_content.has_child_messages()
if chat_content_role:
if chat_content_message:
merged_message = f"### {chat_content_role}: \n" + chat_content_message + "\n\n"
if has_child_messages:
merged_message += f"### 入力: \n" # "### Input:" (model-specific header, kept in Japanese)
chat_content_child_messages = chat_content.get_child_messages()
for message in chat_content_child_messages:
merged_message += message + "\n\n"
else:
merged_message = f"### {chat_content_role}: "
ret += merged_message
return ret
def build_initial_prompt(self, chat_prompt):
# No initial prompt is implemented
pass