Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My AI chatbot script linked to GPT-2 API isnt working. Any help?

Asked by 1 year ago
local HttpService = game:GetService("HttpService")
local API_KEY = "blanked out for privacy"
local API_URL = "https://api.openai.com/v1/engines/davinci/completions"

function generateText(prompt, length)
    local requestBody = HttpService:JSONEncode({
        prompt = prompt,
        length = length,
        temperature = 0.7,
    })

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

    local response = HttpService:PostAsync(API_URL, requestBody, headers)
    local responseData = HttpService:JSONDecode(response)

    return responseData.choices[1].text
end

local generatedText = generateText("Once upon a time,", 50)
print(generatedText)
0
any error messages? s_21 74 — 1y
0
Yes. I got "unable to cast dictionary to token" Fallden4 0 — 1y
0
At what line? blowup999 659 — 1y
0
nvm, it's because PostAsync is given the wrong data - You need to do HttpService:PostAsync(API_URL, requestBody, Enum.HttpContentType.ApplicationJson, false, headers) blowup999 659 — 1y
0
I got this error: Header "Content-Type" is not allowed! - Server - Script:17 Fallden4 0 — 1y

Answer this question