I've been making an open-sourced system for Roblox developers to use. The system is supposed to generate code, but seems like I always get the error in the title for no reason. I don't have a paid account.
Here is the module script where I handle almost everything (For whoever understands):
local HttpService = game:GetService("HttpService")
local OpenAI = {}
OpenAI.__index = OpenAI
local API_KEY = "API-KEY (Not giving it lol)"
local BASE_URL = "https://api.openai.com/v1"
function OpenAI.new()
local self = setmetatable({}, OpenAI)
return self
end
function OpenAI:Request(method, path, data)
local url = BASE_URL .. path
local headers = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. API_KEY
}
local options = {
Url = url,
Method = method,
Headers = headers,
}
if data then
options.Body = HttpService:JSONEncode(data)
end
local response = HttpService:RequestAsync(options)
if response.Success then
return HttpService:JSONDecode(response.Body)
else
error(response.StatusCode .. ": " .. response.StatusMessage)
end
end
function OpenAI:Complete(prompt)
local data = {
prompt = prompt,
max_tokens = 150,
n = 1,
stop = "\n"
}
local response = self:Request("POST", "/engines/davinci/completions", data)
return response.choices[1].text
end
return OpenAI
Here is the Server Script that I'm using to accomplish a request:
local openai = require(game.ServerScriptService.OpenAI)
local prompt = "Write a Lua script that prints 'Hello, World!'"
local code = openai:Complete(prompt)
print(code)
ServerScriptService.OpenAI:35: 429: Too Many Requests - Server - OpenAI:35
Line 429: lua error(response.StatusCode .. ": " .. response.StatusMessage)