OpenAI.luau
GitHub • Roblox Marketplace • Wally¹ • Documentation
One day I wanted to use an external AI model for my project, but I wanted to use an API wrapper for it. Since I couldn’t find one like what I wanted, I decided to make one, and after I made it, I thought other people might find it useful, so I’m releasing it!
Example Code
local OpenAI = require("./path/to/openai")
-- Creating the OpenAI client
local openai = OpenAI.new({
apiKey = "your-api-key",
baseURL = "https://api.openai.com/v1",
endpoints = {
chatCompletion = "/chat/completions",
listModels = "/models",
moderation = "/moderations"
}
})
-- Generating a chat completion
local response = openai:CreateChatCompletion({
model = "gpt-4o-mini",
messages = {
{
role = "user",
content = "Hello, how are you?"
}
},
temperature = 1,
max_completion_tokens = 4096
})
print(response)
-- Moderation
local moderationResult = openai:CreateModeration({
"I hope you die", "I love you so much!"
})
print(moderationResult.results[1].flagged) -- True
print(moderationResult.results[2].flagged) -- False
-- Grabbing models
local models = openai:GetAvailableModels()
print(models)
Todo:
Moderation API supportGetting available models- OpenAI assistant support
Please share any issues on the GitHub Issues page, or fork it to fix issues yourself!
¹ The Wally repo is sort of experimental as I’ve never used it before, so let me know how it goes.
Released under the MIT license because I love open source.