hey, i’m extremely new to HTTP stuff and i needed an AI chatbot for my game (i chose DialoGPT from Hugging Face, as it’s free to use), when i make a request it says
can someone help me fix this?
--// Hugging Face setup
local url = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-small"
local headers = {
["Authorization"] = "my-token", -- cannot share the token obviously
["Content-Type"] = "application/json"
}
--// Sequence
while true do
task.wait(3)
Sounds.Bell:Play()
task.wait(0.2)
tweenIn:Play()
task.wait(1)
local product = products[math.random(1, #products)]
local messagePicked = beginnings[math.random(1, #beginnings)]
local textAsked = string.gsub(messagePicked, "<PRODUCT>", product)
dialogueRF:InvokeClient(player, textAsked)
local pitch = player.Chatted:Wait()
-- Build prompt for DialoGPT
local prompt = "The player is trying to sell you an item called '" .. product .. "'. They say: " .. pitch .. " What is your response?"
-- Send to Hugging Face API
local body = HTTPService:JSONEncode({
inputs = prompt
})
local success, response = pcall(function()
return HTTPService:PostAsync(url, body, Enum.HttpContentType.ApplicationJson, false, headers)
end)
if success then
local result = HTTPService:JSONDecode(response)
local message = result[1] and result[1].generated_text or "Sorry, what?"
dialogueRF:InvokeClient(player, message)
else
warn("Error talking to DialoGPT:", response)
dialogueRF:InvokeClient(player, "uhh... mhgg.... let me sleep on it..")
end
end
this feature is required for my game, so i would deeply appreciate any help!