import random
from locust import HttpUser, task, between
class Llama3ChatUser(HttpUser):
wait_time = between(1, 5)
QUESTIONS = [
"What is the capital of France?",
"Translate 'Hello, how are you?' into Spanish.",
"Who wrote 'Pride and Prejudice'?",
"What's 13 multiplied by 17?",
"Name three benefits of a vegan diet.",
"Give me a quick summary of the plot of '1984'.",
"Explain the concept of machine learning in simple terms.",
"What are the main differences between Python and JavaScript?",
"How does photosynthesis work?",
"What are some tips for effective time management?"
]
@task
def chat_completion(self):
question = random.choice(self.QUESTIONS)
# Used to show a preview of the question in LF
preview = (question[:20] + "...") if len(question) > 20 else question
payload = {
"model": "llama3.3-70b-instruct",
"messages": [{"role": "user", "content": question}],
"stream": False,
"include_functions_info": False,
"include_retrieval_info": False,
"include_guardrails_info": False
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.api_token}"
}
with self.client.post(
"/api/v1/chat/completions",
json=payload,
headers=headers,
name=f"chat: {preview}",
catch_response=True
) as response:
if response.status_code == 200:
response.success()
else:
response.failure(f"Status {response.status_code}")
def on_start(self):
# Set your DigitalOcean AI API token here
self.api_token = "your-digitalocean-ai-token"