Demo code (Please double-check my implementation is accurate):
local HttpService = game:GetService("HttpService")
local TextGenerator = Instance.new("TextGenerator", workspace)
local RESPONSE_SCHEMA = {
type = "object",
properties = {
["animals"] = {
type = "number"
}
}
}
local function GetAnimalCountAsync(UserPrompt)
local Success, Response = pcall(function()
return TextGenerator:GenerateTextAsync({
UserPrompt = UserPrompt,
JsonSchema = HttpService:JSONEncode(RESPONSE_SCHEMA),
MaxTokens = 50
})
end)
if not Success then
warn(Response)
end
return Success, Success and Response.GeneratedText
end
print(GetAnimalCountAsync("2 dogs, and 1 cat"))
Using JSON schema returns the following error message
Error while making HTTP request: HTTP 400 (Bad Request)
