Призначення ролей у чаті

Робота з 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]

Вивід відповіді з підсвіченою роллю

Робота з Llama 3

Роль assistant

response["choices"][0]

Вивід відповіді з підсвіченим вмістом

result['choices'][0]['message']['content']
'A successful marketing strategy relies on clear objectives, established 
through specific, measurable goals. Understanding the target audience ...'
Робота з Llama 3

Давайте потренуємось!

Робота з Llama 3

Preparing Video For Download...