So im trying to make a ai chatbot system (the system is a model by the way) but its giving me an error

okay so theres an error when ever i chat aka try to use the chat bot. heres a screen shot of the error

heres the line

image_2024-05-18_233919896

if anyone could take just a little time out of there day to help resolve this issue that would be great! thank you devs. anybody? :sob:

let me see the rest of the script β€Ž

wait hold on that showed something it shouldnt

local HttpService = game:GetService("HttpService")
local TextService = game:GetService("TextService")
local Chat = game:GetService("Chat")

local OpenAiUrl = "https://api.openai.com/v1/completions"
local AiModel = "text-davinci-003"
local UserKey = "------" --//generate key at https://platform.openai.com/account/api-keys IT WONT WORK UNLESS YOU GET A WORKING KEY!!!
local PrefixPromptInformation = [[]]
local SuffixPromptInformation = [[?]]

local ActivationDistance = 15
local MaxBubbleText = 150
local TimeBetweenTexts = 3

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if not Player.Character or not (Player:DistanceFromCharacter(script.Parent.Head.Position) <= ActivationDistance) then
			return
		end
		local Success, Error = pcall(function()
			local Response = HttpService:RequestAsync({
				Url = OpenAiUrl,
				Method = "POST",
				Headers = {
					["Content-Type"] = "application/json",
					["Authorization"] = `Bearer {UserKey}`
				},
				Body = HttpService:JSONEncode({
					model= AiModel,
					prompt = `{PrefixPromptInformation}{Message}{SuffixPromptInformation}`,
					max_tokens = 150,
					temperature =  .6,
					top_p = 1,
					presence_penalty = 1,
					frequency_penalty = 1,
				}),
			})
			local Body = HttpService:JSONDecode(Response["Body"])
			for _, Choice in Body.choices do
				local Text = TextService:FilterStringAsync(Choice.text, Player.UserId, Enum.TextFilterContext.PublicChat):GetNonChatStringForUserAsync(Player.UserId)
				local Bubbles = {}
				local CurrentInd = 1
				local CurrentLength = 0
				local AmountSinceLastSpace = ""
				local TextLen = string.len(Text)
				for First, Last in utf8.graphemes(Text) do
					local Char = Text:sub(First, Last)
					local Len = string.len(Char)
					if not (Char == " ") and not (Last == TextLen) then
						AmountSinceLastSpace ..= Char
						CurrentLength += Len
						continue
					end
					if CurrentLength > MaxBubbleText then
						CurrentInd += 1
						CurrentLength = 0
					end
					Bubbles[CurrentInd] = (Bubbles[CurrentInd] or "") .. AmountSinceLastSpace .. Char
					AmountSinceLastSpace = ""
				end
				for _, Bubble in Bubbles do
					Chat:Chat(script.Parent.Head, Bubble)
					task.wait(TimeBetweenTexts)
				end
			end
		end)
		if not Success then warn(Error) end
	end)
end)

sorry for spamming you with messages

if you want i could invite you to my studio

ay not to be rude but do you gotta go or something?

1 Like

aw alright thanks for trying to help

some feedback would be nice please

wtflipβ€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž

huh oh mb for spamming im not very patient

i was washing the dishes, and i also don’t know what’s causing this did you try removing that line?

no i didnt remove the line i tried to tho it didnt work though

try printing Body.choices you could just be trying to loop through something that doesn’t exist or something with NOTHING in it

how do i print body.choices mb im kinda slow

did you even code :sob:

print(Body.choices) -- assuming that Body must be a table or something

see if this works

ohhhhhh i thought you meant make it print that when the thing functions ik prints tho where should i put it? what line

also i didnt code a single bit of the script but imma give creds

before you loop Body.choicesβ€Ž β€Ž β€Ž β€Ž β€Ž

am i buggin or is there no loop in the script