Hi, I’m trying to make a chatbot, where the player sends a message in chat and the bot responds. I’m using models from HuggingFace, but I keep getting “HTTP 429 (Too Many Requests) - Server - AI:23”
I looked everywhere in the developer forum… I even tried adding the following header:
local headers = {
["Authorization"] = Bearerkey
}
And modified
local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false)
To
local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false, headers)
This is the entire code:
local NPC = script.Parent
local MyHuman = NPC:WaitForChild("Humanoid")
local MyRoot = NPC:WaitForChild("HumanoidRootPart")
local Gyro = MyRoot:WaitForChild("BodyGyro")
local chat = game:GetService("Chat")
local HttpService = game:GetService("HttpService")
local API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"
Gyro.MaxTorque = Vector3.zero
-- Function that sends the input to the chatbot and returns the response
local function conversate(payload)
-- Encode the payload as a JSON string
local jsonPayload = HttpService:JSONEncode(payload)
-- Send a POST request to the API URL with the headers and the payload
local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false)
-- Decode the response as a JSON table
local jsonResponse = HttpService:JSONDecode(response)
-- Return the JSON table
return jsonResponse
end
-- Main
game:GetService("Players").PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
Gyro.MaxTorque = Vector3.new(0,4000000,0)
Gyro.CFrame = CFrame.new(MyRoot.Position,rootPart.Position)
wait(2)
chat:Chat(NPC.Head,"Hey, "..player.Name..", welcome to my house!",Enum.ChatColor.White)
player.Chatted:Connect(function(message)
local data = {["inputs"] = message}
local response = conversate(data)
chat:Chat(NPC.Head,response,Enum.ChatColor.White)
Gyro.CFrame = CFrame.new(MyRoot.Position,rootPart.Position)
end)
end)