#Too Many Requests | Roblox Luau

66 messages ยท Page 1 of 1 (latest)

low sparrow
#

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)

low sparrow
#

How so?

wanton sinew
#

local response = self:Request("POST", "/engines/davinci/completions", data)
return response.choices[1].text

low sparrow
#

First of all, I do not use ChatGPT since the responses that I get aren't good. And yes, Bing AI did it. Since I do not know how to use the API.

#

Though, I've done research and they are similar to this code.

low sparrow
low sparrow
unborn swallow
#

It look like it not code issue (it kinna suck but ok) Error 429 means that you have exceeded your free $18 in API credits. Try see https://openai.com/pricing.

low sparrow
#

I haven't even used my API.

#

I haven't even paid.

wanton sinew
wanton sinew
low sparrow
boreal kettle
unborn swallow
#

no

#

it not

#

in lua first index in array is 1

#

i mean luau but it same

boreal kettle
#

oh aight

#

guess I will never be coding in luauu

wanton sinew
low sparrow
#

so what's the problem

#

...

wanton sinew
unborn swallow
#

idk my friend also face with this problem when use davinci model

boreal kettle
#

@unborn swallow that code is outdated .

use this curl

curl https://api.openai.com/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0 }'

with this library

https://lua-curl.github.io/

I am not the lua guy

unborn swallow
#

im just gonna say that lol nvm lemme try

low sparrow
#

How would I translate it to Luau?

#

lol

unborn swallow
#

i am doing rn

#

wait

low sparrow
#

k

boreal kettle
#

roblox ๐Ÿ’€ ๐Ÿ’€

unborn swallow
#
local HttpService = game:GetService("HttpService")

local API_KEY = "API KEY HERE"
local BASE_URL = "https://api.openai.com/v1"

local OpenAI = {}

function OpenAI:Complete(Prompt)
    local Url = BASE_URL .. "/completions"

    local Headers = {
        ["Content-Type"] = "application/json",
        ["Authorization"] = "Bearer " .. API_KEY
    }

    local Body = {
        ["model"] = "text-davinci-003",
        ["prompt"] = Prompt,
        ["max_tokens"] = 150,
        ["temperature"] = 0,
        ["n"] = 1,
        ["stop"] = "\n"
    }

    local Response = HttpService:RequestAsync({
        ["Url"] = Url,
        ["Method"] = "POST",
        ["Headers"] = Headers,
        ["Body"] = HttpService:JSONEncode(Body)
    })
    -- local Response = HttpService:GetAsync(Url)

    if Response.Success then
        local Data = HttpService:JSONDecode(Response)
        return Data["choices"][1]
    end
end

return OpenAI

Idk this gonna work or not

low sparrow
#

nil - Server - Server:5

Server script:

local openai = require(game.ServerScriptService.OpenAIV2)
local prompt = "Write a Lua script that prints 'Hello, World!'"
local code = openai:Complete(prompt)

print(code)
#

seems like it worked but just returned nil

unborn swallow
#

oh

low sparrow
#

so there isn't the error of Too many requests.

unborn swallow
#

i

#

k

#

Change this local Data = HttpService:JSONDecode(Response.Body)

low sparrow
#

still nil

unborn swallow
#
if Response.Success then
        local Data = HttpService:JSONDecode(Response.Body)
        print("Worked", Data)
        return Data["choices"][1]
    else
        error(Response.StatusCode .. ": " .. Response.StatusMessage)
        return nil
    end

lemee try log it

low sparrow
#

lol

unborn swallow
#

ok now i think api issue

low sparrow
#

so uh.

#

Are there any possibilities of fixing that?

unborn swallow
#

try change model to "davinci"

low sparrow
#

like that?

unborn swallow
#

yep

low sparrow
#

guess what

unborn swallow
#

same

low sparrow
#

yep

unborn swallow
#

hate u completions

low sparrow
#

๐Ÿ’€

#

Why would an API code be so difficult ๐Ÿ’€

unborn swallow
#

code is work fine but api is ahhh

low sparrow
#

exactly

unborn swallow
#

how chat completion api is flag with beta but work fine and completions api is ...

#

๐Ÿ’€

#

so i gtg bye hope it fix soon

low sparrow
#

aka never

#

lol