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)
COMMUNITY QUESTION
My AI chatbot script linked to GPT-2 API isnt working. Any help?
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
any error messages?
Yes. I got "unable to cast dictionary to token"
At what line?
nvm, it's because PostAsync is given the wrong data - You need to do HttpService:PostAsync(API_URL, requestBody, Enum.HttpContentType.ApplicationJson, false, headers)
I got this error: Header "Content-Type" is not allowed! - Server - Script:17