[ChatStream] lightblue/karasu-7B-chat-plus 用 ChatPrompt
![[ChatStream] lightblue/karasu-7B-chat-plus 用 ChatPrompt](/content/images/size/w1200/2024/04/prompt_new.webp) 
    こんにちは! (株)Qualiteg プロダクト開発部 です!
本稿では lightblue/karasu-7B-chat-plus 用の ChatPrompt をご紹介します。
旧バージョンの ChatStream をご利用のお客様は本ChatPromptをインポートすることで利用可能となります。(最新の配信バージョンではバンドルされております)
from chatstream import AbstractChatPrompt
from chatstream.chat_prompt.role_type import RoleType
SYSTEM_PROMPT = """\
あなたはAIアシスタントです。\
"""
class ChatPromptLightblueKarasuChatPlus(AbstractChatPrompt):
    def __init__(self):
        super().__init__()  # Call the initialization of the base class
        self.set_system(f"<s>[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\n")
        self.set_requester("")
        self.set_responder("")
    def get_stop_strs(self):
        if not self.chat_mode:
            return None
        return []
    def get_custom_skip_echo_len(self, skip_echo_len):
        num_turn = self.get_turn()
        if num_turn >= 2:
            modified_skip_echo_len = skip_echo_len + 1 * self.get_turn() - 1  
            return modified_skip_echo_len
        return skip_echo_len
    def get_replacement_when_input(self):
        return None
    def get_replacement_when_output(self):  # replace when response_text gotten
        return None
    def create_prompt(self, opts={}):
        ret = self.system
        for chat_content in self.get_contents(opts):
            chat_content_role_type = chat_content.get_role_type()
            chat_content_message = chat_content.get_message()
            if chat_content_message:
                merged_message = ""
                if chat_content_role_type == RoleType.REQUESTER:
                    merged_message = f"{chat_content_message} [/INST] "
                elif chat_content_role_type == RoleType.RESPONDER:
                    merged_message = f"{chat_content_message} </s><s>[INST] "
                ret += merged_message
            else:
                pass
        return ret
    async def build_initial_prompt(self, chat_prompt):
        # 初期プロンプトは実装しない
        pass
勘の良い方はお気づきかもしれませんが本モデルは Llama2 をベースモデルとしているため、 Llama2 対応として以下処理パートが特徴的となっております。
    def get_custom_skip_echo_len(self, skip_echo_len):
        num_turn = self.get_turn()
        if num_turn >= 2:
            modified_skip_echo_len = skip_echo_len + 1 * self.get_turn() - 1  
            return modified_skip_echo_len
        return skip_echo_len
ご参考
https://blog.qualiteg.com/llama2-dui-ying-no-chatpromptshi-zhuang/
 
             
                             
             
             
            