Here’s a tutorial on using AI to turn your chats British. Learn how to integrate AI models into your game, and other projects! This tutorial uses Groq, a fast and free AI platform, similar to OpenAI.
Note: You should have a little scripting knowledge - this tutorial won’t deep dive into the scripts.
Getting your API key
Follow these steps to generate your Groq API key:
-
Register on GroqCloud
-
Go to the API Key section, and click “Create API key.”
-
Name the key whatever you want, then submit.
-
Copy the API key. Treat the API key like a password - keep it safe!
Example of a request
Here’s an example request structure we’ll be using in Roblox Studio.
local data = {
messages = {
{role = "system", content = "placeholder system message"},
{role="system", content="placeholder user message"},
},
max_tokens = 512,
model="llama3-8b-8192"
}
Key components:
-
Messages: Define the conversation structure. “System” messages set rules for the AI to follow, while “User” messages are the prompts the AI responds to.
-
Tokens: Control the request and response length. Each character is usually one token. Pricing usually depends on the token usage. Even though (at the time of writing) Groq is completely free, it’s still good practice to optimise. 512 max tokens is a good balance for most small projects.
-
Model: Choose the AI model. Unlike OpenAI which develops its own ChatGPT models, Groq uses open source AI models, mostly made by Google and Meta. My personal favorite is the “llama3-8b-8192” model - it’s quick and smart enough. You can explore other models available on Groq here.
Sending a request
The fun happens here! Here’s the code to turn any given message into overly formal British English:
local repStorage = game:GetService("ReplicatedStorage")
local httpService = game:GetService("HttpService")
local groqUrl = "https://api.groq.com/openai/v1/chat/completions"
local groqApiKey = "API_KEY"
local headers = {
["Authorization"] = "Bearer " .. groqApiKey
}
local givenMessage = "hello world"
local data = {
messages = {
{role = "system", content = "SUBSTITUTE WORDS ONLY. DO NOT ADD ADDITIONAL WORDS OR PHRASES. AVOID SWEARS. MAX 45 CHARACTERS"},
{role="system", content="Examples: hello -> greetings how are you -> how do you do what's up -> what ho. Use words like greetings, ahoy, good sir/madam, confound it, and dash it all."},
{role = "user", content = "Convert the given message into a dramatic, overly formal, old-fashioned absurdly Victorian British English: "..givenMessage}
},
max_tokens = 512,
model="llama3-8b-8192"
}
local jsonData = httpService:JSONEncode(data)
local data = httpService:PostAsync(groqUrl,jsonData,Enum.HttpContentType.ApplicationJson,false,headers)
local jsonDecoded = httpService:JSONDecode(data)
local msg = jsonDecoded.choices[1].message.content
How it works:
- The system messages shape the AI’s behaviour (e.g. defining the request, avoiding swears, etc.)
- The user message provides the input to be transformed.
- The result in this code will return the English British version of the “givenMessage” variable. If used for an actual chat, you’d parse the original chat message there instead.
You can easily switch to OpenAI’s API with minimal changes, as Groq follows the same request structure.
Try it:
The game below still uses Roblox’s Legacy Chat system - I’ve been unable to find a way to make it work with the new system. After April 30th, 2025, it will no longer work. Enjoy it while it lasts.
Example game (with my API key removed):
becomeBritishSimulatorNoApiKey.rbxl (268.2 KB)
I hope someone finds this useful!