チャットのロールを設定する

Llama 3 を使いこなす

Imtihan Ahmed

Machine Learning Engineer

ロールを定義する

  • モデルの口調を整える
  • 例: カスタマーサポートのチャットボット

チャットボットとの会話 - 1

Llama 3 を使いこなす

ロールを定義する

  • モデルの口調を整える
  • 例: カスタマーサポートのチャットボット

チャットボットとの会話 - 2

Llama 3 を使いこなす

ロールを定義する

  • モデルの口調を整える
  • 例: カスタマーサポートのチャットボット

チャットボットとの会話 - 3

Llama 3 を使いこなす

チャット補完でロールを使う

  • ロールで Llama の返答を誘導

Screenshot 2025-02-26 at 15.32.28.png

  • 人柄と文体を設定

 

Screenshot 2025-02-26 at 15.31.50.png

  • 質問者を表す
Llama 3 を使いこなす

チャット補完でロールを使う

  • 構造化した会話を送信する

  • create_chat_completion() 関数

from llama_cpp import Llama

llm = Llama(model_path="path/to/model.gguf")

message_list = [...] # This list includes roles
response = llm.create_chat_completion(
messages = message_list
)
Llama 3 を使いこなす

system ロール

  • system メッセージ: モデルの振る舞いを指示
system_message = "You are a business consultant who gives data-driven answers."

message_list = [{
"role": "system",
"content": system_message
}]
Llama 3 を使いこなす

user ロール

  • user メッセージ: モデルへの質問文
system_message = "You are a business consultant who gives data-driven answers."

user_message = "What are the key factors in a successful marketing strategy?"
message_list = [{"role": "system", "content": system_message},
{ "role": "user", "content": user_message }
]
Llama 3 を使いこなす

応答を生成する

from llama_cpp import Llama
llm = Llama(model_path="path/to/model.gguf")

system_message = "You are a business consultant who gives data-driven answers."
user_message = "What are the key factors in a successful marketing strategy?"

message_list = [{"role": "system", "content": system_message},
               {"role": "user", "content": user_message}]

response = llm.create_chat_completion(messages = message_list) print(response)
{'id': ..., 'object': ..., 'created': ..., 'model': ..., 'choices': [...], ...}
Llama 3 を使いこなす

assistant ロール

response["choices"][0]

応答の出力

Llama 3 を使いこなす

assistant ロール

response["choices"][0]

メッセージを強調した応答出力

Llama 3 を使いこなす

assistant ロール

response["choices"][0]

role を強調した応答出力

Llama 3 を使いこなす

assistant ロール

response["choices"][0]

content を強調した応答出力

result['choices'][0]['message']['content']
'A successful marketing strategy relies on clear objectives, established 
through specific, measurable goals. Understanding the target audience ...'
Llama 3 を使いこなす

Passons à la pratique !

Llama 3 を使いこなす

Preparing Video For Download...