Chat-Rollen zuweisen

Arbeiten mit Llama 3

Imtihan Ahmed

Machine Learning Engineer

Rollen definieren

  • Ton des Modells verfeinern
  • Beispiel: Customer-Support-Chatbot

Unterhaltung mit einem Chatbot - 1

Arbeiten mit Llama 3

Rollen definieren

  • Ton des Modells verfeinern
  • Beispiel: Customer-Support-Chatbot

Unterhaltung mit einem Chatbot - 2

Arbeiten mit Llama 3

Rollen definieren

  • Ton des Modells verfeinern
  • Beispiel: Customer-Support-Chatbot

Unterhaltung mit einem Chatbot - 3

Arbeiten mit Llama 3

Rollen in Chat Completions nutzen

  • Chat-Rollen lenken Llamas Antworten

Screenshot 2025-02-26 at 15.32.28.png

  • Legt Persönlichkeit und Stil fest

 

Screenshot 2025-02-26 at 15.31.50.png

  • Repräsentiert die fragende Person
Arbeiten mit Llama 3

Rollen in Chat Completions nutzen

  • Eine strukturierte Unterhaltung senden

  • Funktion create_chat_completion()

from llama_cpp import Llama

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

message_list = [...] # Diese Liste enthält Rollen
response = llm.create_chat_completion(
messages = message_list
)
Arbeiten mit Llama 3

Die System-Rolle

  • System-Nachricht: Vorgaben zum Verhalten des Modells
system_message = "You are a business consultant who gives data-driven answers."

message_list = [{
"role": "system",
"content": system_message
}]
Arbeiten mit Llama 3

Die User-Rolle

  • User-Nachricht: die Frage/der Prompt an das Modell
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 }
]
Arbeiten mit Llama 3

Die Antwort generieren

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': [...], ...}
Arbeiten mit Llama 3

Die Assistant-Rolle

response["choices"][0]

Antwortausgabe

Arbeiten mit Llama 3

Die Assistant-Rolle

response["choices"][0]

Antwortausgabe mit markierter Nachricht

Arbeiten mit Llama 3

Die Assistant-Rolle

response["choices"][0]

Antwortausgabe mit markierter Rolle

Arbeiten mit Llama 3

Die Assistant-Rolle

response["choices"][0]

Antwortausgabe mit markiertem Inhalt

result['choices'][0]['message']['content']
'A successful marketing strategy relies on clear objectives, established 
through specific, measurable goals. Understanding the target audience ...'
Arbeiten mit Llama 3

Lass uns üben!

Arbeiten mit Llama 3

Preparing Video For Download...