Hello! I’m here to ask if there was a way for me to return back a text response from HuggingFace’s AI models. I’ve looked into this all day and all of them seems to be outdated. I’m aware that I need to use an API key. However all responses specifically being used from HuggingFace returns a 404 error. I specifically want to use HuggingFace due to it’s generous rate limit for free users. I also do not want to use ROBLOX’s text generation AI due to it’s extreme restricted filter and forcing you to set your game’s rating to moderate/restricted.
local HttpService = game:GetService("HttpService")
local Bearerkey = "Bearer (obviously not going to show my API key here)"
function AskQuestion(inputText)
-- Import the HttpService
-- Define the API URL
local API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"
-- Define the headers with your authorization key
local headers = {
["Authorization"] = Bearerkey
}
-- Define a function to query the API with a payload
local function query(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, headers)
-- Decode the response as a JSON table
local jsonResponse = HttpService:JSONDecode(response)
-- Return the JSON table
return jsonResponse
end
-- Define your input text
-- Query the API with your input text as the inputs field
local output = query({
["inputs"] = inputText
})
local generatedText = output[1].generated_text
-- or
local generatedText = output[1]["generated_text"]
return generatedText
-- Print the output
end
print(AskQuestion("Hello, How are you?"))