Working with Llama 3
Imtihan Ahmed
Machine Learning Engineer
Sending a structured conversation
create_chat_completion()
function
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
)
system_message = "You are a business consultant who gives data-driven answers."
message_list = [{
"role": "system",
"content": system_message
}]
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 }
]
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': [...], ...}
response["choices"][0]
response["choices"][0]
response["choices"][0]
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 ...'
Working with Llama 3