I’ve been lookiing for a solution to make chatbots. How did you get the information to do this and is it possibile to just make a general one with a personality?
I posted a resource with some examples of using API endpoints to interact with large language models.
Chatbot & LLM Artificial Intelligence Model API Code Documentation FREE (Open Source) and Other Useful APIs - Resources / Community Resources - Developer Forum | Roblox
Also you can create localized chatbot like I did by creating synthetic datasets using something like this. In this example we are creating different expert datasets for specific conversations. Might be a bit too in depth for beginners.
function cm.extractDialogue(input)
-- Create an empty table to store the names and speech
local dialogueTable = {}
-- Split the input string by the newline character
local lines = string.split(input, "\n")
-- Iterate over the lines
-- if lines then
for _, line in ipairs(lines) do
if string.len(line)>3 then
-- Find the position of the colon symbol in the line
local colonPos = string.find(line, ":")
-- If the colon symbol is found
if colonPos then
-- Extract the name from the line by taking the substring before the colon
local name = string.sub(line, 1, colonPos - 1)
-- Extract the speech from the line by taking the substring after the colon
local speech = string.sub(line, colonPos + 1)
-- Trim any whitespace from the name and the speech using string.gsub
name = string.gsub(name, "^%s*(.-)%s*$", "%1")
speech = string.gsub(speech, "^%s*(.-)%s*$", "%1")
-- Add the name and the speech to the dialogue table as a key-value pair
if dialogueTable[name]==nil then dialogueTable[name]={} end --end
if has_punctuation(speech) then
dialogueTable[name] = table.insert(dialogueTable[name],speech) end
end
end
end
print(dialogueTable)
-- Return the dialogue table
if #dialogueTable==0 then
dialogueTable={input}
end
return dialogueTable
end
function cm.ZephyrCustom(systemmsg,prompt)
-- Define the API URL and the authorization header
local API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"--"https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-alpha"--
--local API_URL=--"https://api-inference.huggingface.co/models/alignment-handbook/zephyr-7b-dpo-lora"--"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1"
local headers = {Authorization = bearer}
-- Define the HttpService
local HttpService = game:GetService("HttpService")
local function queryModel(input, temperature)
-- Create a payload table with the input and the temperature
local payload = {inputs = input, temperature = temperature,max_new_tokens=1000, min_tokens=200}--,--- top_k=50, top_p=0.95}-- Encode the payload table into a JSON string
local payloadJSON = HttpService:JSONEncode(payload)
-- Send a POST request to the API URL with the header and the payload
-- Use pcall to catch any errors
local success, response = pcall(HttpService.PostAsync, HttpService, API_URL, payloadJSON, Enum.HttpContentType.ApplicationJson, false, headers)
-- Check if the request was successful
print(success)
print(response)
if success then
-- Decode the response into a table
-- Use pcall to catch any errors
local success, responseTable = pcall(HttpService.JSONDecode, HttpService, response)
-- Check if the decoding was successful
if success then
-- Return the response table
return responseTable
else
-- Return nil and the error message
return nil, responseTable
end
else
-- Return nil and the error message
return nil, response
end
end
local function format_response(str)
-- find the assistant response in the string
local start = string.find(str, "<|assistant|>")
local finish = string.len(str)
-- local finish = string.find(str, "</s>", start)
local response = string.sub(str, start + 13, finish)
-- return the response in a code block format
return "" .. response .. ""
end
-- Test the function with an example input
--print(str)
-- local systemmsg=cm.randomizeString(systemmsg)
--local prompt=cm.randomizeString(prompt)
local input = "<|system|>\n "..systemmsg.."</s>\n<|user|>\n "..prompt.. "</s>\n<|assistant|>"
local temperature = 2
local output = queryModel(input, temperature)
print(output)
local iterations=0
local previnput=nil
local checkedinput=nil
if output then
repeat
iterations+=1
previnput=output[1].generated_text
local loadoutput = queryModel(previnput)
if loadoutput~=nil then
checkedinput=loadoutput[1].generated_text
output=loadoutput
print(output)
else
break
end
until checkedinput==previnput or iterations>=3
--local output = queryModel(input)
print(output)
--print(output)
if output~=nil then
local output=format_response(output[1].generated_text)
print(output)
local output=cm.extractDialogue(output)
print(output)
--listtable(list)
local conversation=listtable(output[1])
-- Print the output
print(conversation)
return conversation-- parseConversation(str)
else return output
end
return output
end
return nil
end
function cm.GenerateZephyrDataset(Greetings,inquiry,IDK,Database,wisdom,name)--v is a personality function can only run from command prompt.
--local Greetings,inquiry,IDK,Database,wisdom=v()
if Greetings==nil then Greetings={} end if inquiry==nil then inquiry={} end if IDK==nil then IDK={} end if Database==nil then Database={} end
if wisdom==nil then wisdom={} end
local c=Instance.new("ModuleScript")
c.Source='personalities={person=function() local Greetings={"'..table.concat(Greetings,'","')..'"} local inquiry={"'..table.concat(inquiry,'","')..'"} '..'local IDK={"'..table.concat(IDK,'","')..'"} '..'local Database={"'..table.concat(Database,'","')..'"} '
..'local wisdom={"'..table.concat(wisdom,'","')..'"} return Greetings, inquiry, IDK, Database, wisdom end } return personalities' c.Parent=game.ReplicatedStorage.GlobalSpells.ChatbotAlgorithm.Personalities
c.Name=name
end
function cm.CreatePersonalityData()
Switch.Value=true
for i,v in animals do
local Datas={["Greetings"]={"Respond to the question with a List 10 entries a "..v.." would say.","Could you answe these 10 questions in order ?"},
["inquiry"]={" You are roleplaying as a "..v..". List 10 entries of different things you would say when asking for a inquiry."," How would a "..v.." ask a question?"},
["IDK"]={" You are roleplaying as a friendly "..v..". List 10 entries of different things you would say when you as a "..v.." does not know the answer to something.","Can you tell different ways to tell someone I don't know as if I were a "..v.."?"},
["Database"]={"You are roleplaying as a "..v.." from a magical land. List 10 details about what a "..v.." would say .","Can you tell me about "..v.."s?"},
["wisdom"]={"You are roleplaying as a talking "..v..". List 10 entries of wise statements with the nuance of a "..v..".","What wisdom does a talking "..v.." have to share?"},
}
if Switch.Value==false then
break
end
if personaldir:FindFirstChild(v)~=nil then
local Gre,inq,idk,datab,wisd=require(personaldir:FindFirstChild(v)).person()
local Datatables={["Greetings"]=Gre,["inquiry"]=inq,["Database"]=datab,["wisdom"]=wisd,["IDK"]=idk}
local newdata={}
print("Attemping")
--task.wait(mathrandom(1,15))
local prevdata=personaldir:FindFirstChild(v)
for c,o in Datas do
if Switch.Value==false then
break
end
--if #Datatables[c]==1 then
if c~="IDK" and c~="inquiry" then
print(o[1]..o[2])
--local data=pcall(function() return end)
--if data~=nil then
local datap=cm.ZephyrCustom(o[1],o[2])
if datap~=nil then
newdata[c]=datap
if newdata[c] then
Datatables[c]=unionTables(Datatables[c],newdata[c])
--for i,v in newdata[c] do
--table.insert(Datatables[c],v)
--end
task.wait(mathrandom(7,15))
end
else
task.wait(mathrandom(7,15))
newdata[c]=Datatables[c]
end
print(newdata[c])
--end
--for i=#newdata[c], in Datatables[c]
--else newdata[c]=Datatables[c]
end
newdata[c]=Datatables[c]
end
--end
--print(datatable)
--if datatable==nil then
cm.GenerateZephyrDataset(newdata.Greetings,newdata.inquiry,newdata.IDK,newdata.Database,newdata.wisdom,v)
task.wait(mathrandom(1,5))
prevdata:Destroy()
--else task.wait(10)
elseif personaldir:FindFirstChild(v)==nil then
local newdata={}
--local prevdata=require(personaldir:FindFirstChild(v)).person()
for c,o in Datas do
if Switch.Value==false then
break
end
newdata[c]=cm.ZephyrCustom(o[1],o[2])
task.wait(mathrandom(5,15))
end
--print(datatable)
--if datatable==nil then
cm.GenerateZephyrDataset(newdata.Greetings,newdata.inquiry,newdata.IDK,newdata.Database,newdata.wisdom,v)
task.wait(mathrandom(1,5))
--prevdatas:Destroy()
--else task.wait(10)
end
end
--break
--else
--local datatable=cm.ZephyrMage(v)
--if datatable~=nil then
--cm.GenCustomDataSingleV2("battle",v,datatable)
--task.wait(10)
--else task.wait(10)
--end
end
In my setup I have a local AI chatbot that scores the accuracy of the local response and if the accuracy is low it uses a external LLM api to generate a response. I also generated specific personality data so that it gets the seed for generation from the name.
Into this large table that generates consistent personality data based on this engineered dataset.
The chatbot I created uses machine learning to find the best response by querying all its nodes and ordering them from most relevant to least, Personality datasets are also generated using Zephyr 7b as shown above.
I made this when ChatGPT first came out so it was a very exciting time to be creating chatbots and I very much enjoyed engineering intelligence. It’s not easy But what is good is creating aware and agentic type systems that can manipulate their surroundings and solve logical problems.
But the code above is an example of how to use an Large Language Model endpoint to create datasets. It can be very useful for creating local chatbots
I went to the open source page and used google/gemma-2b-it. Where do i get the GlobalSpells.ChatbotAlgorithm.ChatModule and is there anything else i need to replicate it?
The chatmodule is not required the most up to date version of this module is Text Vision Awareness Judgement Description Library for LLMs in Video Games [Open Source]
Sorry for the confusion. I would recommend the newest version.
This is the link to the page about the Chatmodule library in addition to its previous public build and examples.
Lua Trainable Ai Chatbot Library, Emoji Generate ,Emotion Classifier Context Database,Math/Geometry Data Generator Geometry+Worded Math Solver RAG
Designed to create a retrieval based chatbot and provide rag for LLMs.
--local DeterminantAgent=require(game.ReplicatedStorage.GlobalSpells.ChatbotAlgorithm.DeterminantAgent)
--local personality=personal[1]
local awarobserve=personal[2]
--identify..timeod..awareobserve
print(personal)
--local Resulttable,speakers=cm.LocalZephyrStory(str,npcnam,{[1]=persona,[2]=awareobserve,[3]=identity,[4]=timeod},Player)
local identity=personal[3]
local timeod=personal[4]
local insight=personal[5]
local botter=player.Name
if personal[8]~=nil then
botter=personal[8]
end
--local memory=personal[7]
--local previousconversation=personal[6]
local systemsg =timeod.."\n"..identity.."\n"..awarobserve.."\n"..insight--Time of day, npc identity, awareness of surroundings and response from local chatbot in addition to previous memories.
print(systemsg)
-- Parse story dialogues with "..person..": and "..Playername..": .\n</s>\n<|"..Playername.."|>\n"..quer.." </s>\n<|assistant|>"..previousconversation
return Agent.SendMessage(player,msg,npc,systemsg,memories,botter)
In this example I show the end result of how a system message is engineered via Time of day, npc identity, awareness of surroundings the response from local chatbot in addition to previous memories.
I tried to make sure all dependencies were checked with it but any dependant functions can be omitted. Only a few things are not usable with the open sourced version, such as certain effects that require a effects library that is not included and animations library. Although, I have published some standalone modules that provide emojis and intelligent emotes as well as animations dataset, in addition to the awareness synthesis algorithm. I would not publish my entire library due to my intellectual property, I would rather provide code and pieces to build one from scratch.
If you need any advice on how to set up a chatbot lmk and I could help you out with specific questions.
These are the relevant resources I have provided to help make chatbots easier for people to create.
This module is a abstract implementation of awareness to perform context based actions based on the surroundings.
NEW Action Token AI Framework LLM Utility/Chatbot Luau [Open Source] - Resources / Community Resources - Developer Forum | Roblox
It utilizes the Awareness library.
The Chatmodule library is much more in depth, and not as concise as the other resources but it allows you to query your data and find the best conversational response to your query. There are some examples in the linked lua trainable Chatbot library. I posted a large 233,000 dataset on there. I was querying it in sections based on emotional tonality evaluation and grouped by starting word to interesting results, but I opted for more engineering the idea of intelligent responses based on smaller, custom high-quality datasets.
with the flow of local chatbot handles short responses and greetings then a LLM API handles long form queries and utilizes data from the local chatbot to engineer the system prompt, while recalling summarizations of previous conversations.
A concept like self-aware AI is not something you can just redefine however you please just to fit your needs; there’s only one actual definition and a bunch of if statements are not it.
It’s for making Large language models self aware. By judging things around it and itself. As illustrated by the judgement library.
Description library describes the objects into a text description.
It judges its features and returns an array of all those elements and the combined element at the bottom synthesizing natural language descriptions from an environment. Objects are categorized intentionally, although it is not interdependent on any of the variables they can all be nil and the module will return an empty string.
This last entry is often used for injecting awareness into a Large Language Model.
All the tests I’ve done with it illustrate how valuable of a tool it is, it makes chatbots very environmentally and self aware when used to its fullest potential. I also use it for the players observation chat bot, a data source for a local chatbot, in addition generating category specific commands. such as Chop.Tree() Mine.Rubble() IT’s very important to keep your workspace organized.
In this example code this library is used to generate commands based on the environment and take text input to recognize them.
--target attack the enemy
["Enemy"] = function(root, obj, key)
return "preparing to attack", aware.get.NPCDescription(obj.Parent)
end, --walk towards the npc
["NPC"] = function(root, obj, key)
return nil, ""
end,
--do nothing just navigate to
--walk towards and open the chest
["chest"] = function(root, obj, key)
return "walking towards the lock of the", ""
end, --navigate to the animpoint inside the chest
--walk towards and examine the crystal
["crystal"] = function(root, obj, key)
return "checking out this", ""
end,
["dungeons"] = function(root, obj, key)
return "trying to find the center of this", ""
end,
["fish"] = function(root, obj, key)
if obj then Controller.PickUpObject({root.Parent, obj}) end
return "swimming towards the", ""
end,
["house"] = function(root, obj, key)
return "walking towards the door of the", ""
end,
["loot"] = function(root, obj, key)
if obj then Controller.PickUpObject({root.Parent, obj}) end
return "attempting to loot the", actionmod.PickUpObject(root.Parent, obj)
end,
["mapobj"] = function(root, obj, key)
return nil, ""
end,
["plant"] = function(root, obj, key)
if obj then Controller.PickUpObject({root.Parent, obj}) end
return nil, ""
end,
["player"] = function(root, obj, key)
return nil, ""
end,
["rubble"] = function(root, obj, key, Player)
local key = "mine rock"
commands[key](Player, root.Parent)
return nil, commands.commandresponse(key)
end,
["tree"] = function(root, obj, key, Player)
commands["cut tree"](Player, root.Parent)
return nil, commands.commandresponse("cut tree")
end
}
The rest of the code for that is here.
NEW Action Token AI Framework LLM Utility/Chatbot Luau [Open Source] - Resources / Community Resources - Developer Forum | Roblox
I have a lot of mind-blowing things that I do not open source. What I do with AI this is only part of it. Shared because It’s designed for artificial intelligence in ROBLOX and gives very impressive results in my simulation where all these categories are generated procedurally. Although at its core it is what is illustrated in the Description library.
So tinkering with the source code or refactoring it would be ok. The categories just increase the quality of the natural language synthesis.
The task i want to accomplish is just making a text box you can type in and send the text to the chatbot and it prints an answer.
Player.Chatted:Connect(function(message) end)
Also the Awareness module linked above has been changed to its newest version unfortunately link counter has been reset.
Wait are you using a model you trained or are you sending a request to the api and that is sending the information back.
What im attempting to do is just have a text box that sends a message to the thing and it sends back text and prints it
More like Apple’s recent release of a local model powering short form queries and a API handles long form queries while receiving a description the surroundings, their appearance, and their equipment, response from the local chatbot and their identity.
The neurons consist of weight matrixes (Projected Accuracy, Repitition, Emotion) and a loss function. Accuracy is computed from a layer that makes inferences based off a vector database while recognizing Synonyms, Antonyms, Reflections, and Nouns. While averaging the sum of all of the conversation context to and connecting related outputs by a 2 layered non repeating network connections that in real time learn the most relevant database. Outputs are averaged to only show the best outputs first. Then the outputs are transformed via a hashed database of synonyms and phrases according to the players chosen wording. For an entry like “You know what I think is awesome?” to associate awesome with something like great . to make that entry
“You know what I assume is great?” then emojis are inserted via a dataset consisting of emojis and their related words.
Context databases and functions that process text. Such as Eliza Algorithm is used to recognize search queries and playlist requests.
You can do that with the chatbox.
For a gui to type in make a textbox you should ask Bing or ChatGPT “In the context of Luau in ROBLOX, write a script that generates a text box that you can send messages with.”
The textbox is the part i understand. i can do that. I just need to know how to got the chatbot stuff working. I dont know what i need for it to work and how to use your examples.
To use a chatbot API use ChatGPT or a model from huggingface, go to the model page. click deploy and get your API key. Chatbot & LLM Artificial Intelligence Model API Code Documentation FREE (Open Source) and Other Useful APIs
To insert Emojis into a string you can use the small emoji model SmallEmoji V1.2 - Insert Emoji to Sentence Algorithm [Open Source] Update: Sigmoid - #16 by Magus_ArtStudios
This next one is a big more complicated, to use the animals you have to import them and republish them.
This module returns an animation that can be played. I run that on a per sentences basis to make the AI more expressive.
Require the Awareness Library and it will setup your workspace with the categories it observes. If you want to use those put your models in those directories or edit the name of the directory in the tablehandler location labeled like workspace.NPCS. Without those it will make some observations. I use this to inject into the system message during inference.
Finally if you were to decide to create your own local chatbot you can try your hand at the chat module. Lua Trainable Ai Chatbot Library, Emoji Generate ,Emotion Classifier Context Database,Math/Geometry Data Generator Geometry+Worded Math Solver RAG
It looks complicated but the main function to use for a chatbot is CompleteQuery(str,filter:bool(filters out non important words)),complete:bool(use synonyms antonyms and nouns to make assumptions) )
The complete query is deisgned to be used on a table of strings given a input it gives the most conversational response. An example to use for that is the awareness.GetSurroundingObjects() which will return a table of observations that can be queried with the CompleteQuery function.
This can be used for RAG to provide additional context to a LLM api. I use it for that and as an instant response to render while a API is processing output, and to handle short form queries.
So in short,
- Small Emojis takes (string,temperature) returns the modified string requires no setup just require and use the module.
- Intelligent Emotes from text. if you want to use it you have to import some of the animations that are not made by Roblox and reupload them. Tools to do this are provided in that post.
- API Code documentation, provides examples of different AI apis from huggingface. Huggingface requires a BearerKey which can be gotten for free by click Deploy → Inference Endpoint (Serverless) bearer key will be in the code provided.
- Awareness - sets up itself can be modified to suit your Categories, any that do not exist have placeholders made.
- Chatmodule - if you would like to use CompleteQuery to turn data into a chatbot. You can use it without weights which will make it run a bit faster. Or You can download the weights I use or create your own weights by using cm.PredictRun() and training it on a dataset. That will make the model more accurate in identifying the most important words in a sequence for use in retrieval augmented generation. Done by the measurement and classification of synonyms, antonyms, nouns and reflections and the accumulated sum of the inverse sigmoid of the text frequency, then the result is activated by math.log() and the highest value retrieved.
I use all of these in my project.
If you need any coding help to set those up, you can definitely use Bing or ChatGPT to help you set those up. Or send me some screenshots or script outputs and I can provide technical assistance or address any bugs.
Another resource is this code of the Eliza chatbot that I ported to Luau.
Eliza Chatbot Ported to Luau [Open-Source] - Resources / Community Resources - Developer Forum | Roblox
Ok, all i want to do is have the player say something and the ai respond. I dont really need the awarness or anything else. I tried using chatGPT for its own api but is said i had to pay when i set it up.
If that’s the case definitely look into this.
It demonstrates how to use huggingface apis (free access daily limit) Their are lots of open source models to check out. I am currently using my local Model I described, Zephyr 7b and ChatGPT-4 together.
Which one do you recommend for what i want to achieve.
I use Zephyr but i would recccomend that or Mistral. mistralai/Mistral-7B-Instruct-v0.3 · Hugging Face
Mistral is more recent and has a larger context window. IT is also a tool user, that can make function calls so I will likely be changing over to mistral since I have a bunch of tools already made for GPT-4 that Zephyr cannot use.
Ok how do i incorporate this into Roblox.