[ChatStream] meta-llama/Meta-Llama-3-8B-Instruct 用の ChatPromptクラス

[ChatStream] meta-llama/Meta-Llama-3-8B-Instruct 用の ChatPromptクラス

昨日(2024/4/19) に発表になった Llama3 用の ChatPrompt クラス※をご紹介します。

from chatstream import AbstractChatPrompt

SYSTEM_PROMPT = """\
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
"""


class ChatPromptMetaLlamaLlama3Instruct(AbstractChatPrompt):
    """
    meta-llama/Meta-Llama-3-8B-Instruct

    Prompt Guide from
    https://huggingface.co/blog/llama3
    """

    def __init__(self):
        super().__init__()
        self.set_requester("user")
        self.set_responder("assistant")

    def is_skip_special_token(self):
        return False

    def get_stop_strs(self):
        if not self.chat_mode:
            return None
        return ['<|eot_id|>']

    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={}):
        if self.chat_mode == False:
            return self.get_requester_last_msg()

        # Chat Mode == True の場合のプロンプトを構築する
        ret = f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{self.system}<|eot_id|>"

        merged_message = ""
        for chat_content in self.get_contents(opts):

            chat_content_role = chat_content.get_role()
            chat_content_message = chat_content.get_message()

            if chat_content_role:

                if chat_content_message:
                    merged_message = f"<|start_header_id|>{chat_content_role}<|end_header_id|>\n\n{chat_content_message}<|eot_id|>"
                else:
                    merged_message = f"<|start_header_id|>{chat_content_role}<|end_header_id|>\n\n"

                ret += merged_message
        return ret

※ChatStream ご利用のお客様は、最新の ChatStream にも取り込まれておりますが、手動で対応したい場合は上のクラスをご利用ください


Read more

CEATEC 2026に出展します!AIアバター動画生成「MotionVox®」の最新版を実体験いただけます

CEATEC 2026に出展します!AIアバター動画生成「MotionVox®」の最新版を実体験いただけます

株式会社Qualitegは、2026年10月13日(火)~16日(金)に幕張メッセで開催される「CEATEC 2026」に出展いたします。今回の出展では、当社が開発したAIアバター動画生成サービス「MotionVox®」の最新版を中心に、動画生成の実演と作例をご紹介いたします。 昨年の CEATEC 2025 に続き、2年連続の出展となります。昨年の会場の様子は 出展レポート にまとめております。 出展概要 * 会期 2026年10月13日(火)~10月16日(金)10:00~17:00 * 会場 幕張メッセ(千葉県千葉市美浜区中瀬2-1) * 出展エリア ネクストジェネレーションパーク * ブース番号 ホール4 4H339 * 入場 無料(来場事前登録制) * CEATEC内特設サイト https://www.ceatec.com/nj/exhibitor_

By Qualiteg プロダクト開発部
ゼロから作るコーディングエージェント【第3回】「止まらなかった」は「進んだ」ではない。空転を数え、思考は切らずに上限だけ置く

ゼロから作るコーディングエージェント【第3回】「止まらなかった」は「進んだ」ではない。空転を数え、思考は切らずに上限だけ置く

300ターン走ってAPIが0本。「モデルの限界」と結論を書いた翌日、記録を読み直すと234ターンがツールを1度も呼んでいませんでした。空転率という指標、1つ塞ぐと次の形に移る空転、思考をオフにすると95点が71点に落ちて時間も縮まなかった話、出力枠を広げたら反対側を数える話を書きます。

By Qualiteg プロダクト開発部
Ubuntuの自動更新でカーネルだけ上がり、再起動したらGPUが消えた。NVIDIAモジュールが置き去りになる原因と3つの対策

Ubuntuの自動更新でカーネルだけ上がり、再起動したらGPUが消えた。NVIDIAモジュールが置き去りになる原因と3つの対策

Ubuntu 24.04のGPUサーバーを再起動したらnvidia-smiが動かない。原因はunattended-upgradesがカーネルだけを更新し、NVIDIAモジュールが依存関係の都合で見送られていたこと。ログで原因を突き止め、1コマンドで復旧し、apt-mark holdを含む3つの再発防止策を比べて採用した記録。

By Qualiteg プロダクト開発部
ゼロから作るコーディングエージェント【第2回】完了は「作った」ではなく「動いた」で決める。完了の門と、押し戻しに書くこと

ゼロから作るコーディングエージェント【第2回】完了は「作った」ではなく「動いた」で決める。完了の門と、押し戻しに書くこと

モデルの「完了しました」は5つの形ですり抜けました。構文検査だけ、テストは通るが動かない、待ち受けは立つが最初の要求で落ちる、起動するが仕様のAPIが無い、assertの無いテスト。完了の門を3段で閉じる設計と、押し戻しに「落ちた行と調べ方」を書いて「答え」を書かない理由を、数字つきで書きます。

By Qualiteg プロダクト開発部