Zephyr is so good, this function is a good starting point. I have iterated it to use this function where it fire the prompt with 3 different system message and include text-vision awareness, personality and input from a smaller chatbot
function cm.ZephyrStory(person,personal,Playername,quer)
-- Define the API URL and the authorization header
local API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
local headers = {Authorization = bearer}
-- Define the HttpService
local HttpService = game:GetService("HttpService")
-- Define a function that takes an input and queries the model
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=250, top_k=100, top_p=0.11}
-- local payload = {inputs = input, temperature = temperature}
-- 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
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 response--Table-- return json
else
-- print()
-- Return nil and the error message
return nil, response--Table
end
else
-- Return nil and the error message
return nil, response
end
end
local personality=personal[1]
local awarobserve=personal[2]
--identify..timeod..awareobserve
--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 memory=personal[7]
--cm.LocalZephyrStory(str,NPC,{[1]=persona,[2]=awareobserve,[3]=identity,[4]=timeod,[5]="",[6]=conversation},Player)
local previousconversation=personal[6]
if previousconversation==nil then
previousconversation=""
else
previousconversation=previousconversation..""
--local function RebuildConversation(tbl,response)--reduce size of system message
----local tbl,speakers,str=cm.LocalZephyrDecode(response)
--local sum="" for i,v in tbl do for t,o in v do
--if t~="narrator" then
-- sum=sum.." \n\n "..t..": "..o
--else
-- sum=sum.." \n\n "..o
--end end print(sum)
--end
--sum=sum.." \n\n "..Playername..": "..response
--return sum
--end
--previousconversation=RebuildConversation(personal[6][1])
end
--awareobserve,timeod,identity
-- Test the function with an example input
--cachedconversation
--local instruction=
--insight
local function modify_string(input_string)
local modified_words = {}
for word in input_string:gmatch("[A-Z][^A-Z]*") do
local modified_word = word:gsub("^%l", string.upper)
table.insert(modified_words, modified_word)
end
-- Replace multiple spaces with a single space
local modified_string = table.concat(modified_words, " "):gsub("%s+", " ")
return modified_string
end
local input = "<|system|> "..modify_string(identity.."\n"..timeod.."\n"..awarobserve.."\n"..memory.."\n Parse story dialogues with ")..person..": and "..Playername..": \n</s>\n<|"..Playername.."|>\n"..quer.." </s>\n<|assistant|>"..person..":"--"..previousconversation
local temperature = 1.3--start with low
local output,Error = queryModel(input,temperature)
print(output)
local iterations=1
local function RebuildResponse(response)--reduce size of system message
local tbl,speakers,str=cm.LocalZephyrDecode(response)
local sum="" for i,v in tbl do for t,o in v do
if t~="narrator" then
if i~=1 then
sum=sum.." \n\n "..t..": "..o
else
sum=sum..""..t..": "..o
end
else
sum=sum.." \n\n "..o
end end print(sum)
end
local input = "<|system|>\n"..modify_string(memory..""..awarobserve.." Parse story dialogues with ")..person..": and "..Playername..": . </s>\n<|"..Playername.."|>\n"..quer.."</s><|assistant|>"..sum
if iterations==2 then --memory and observations
input = "<|system|>\n"..modify_string(identity..""..awarobserve).."</s>\n<|"..Playername.."|>\n"..quer.."</s><|assistant|>"..sum
elseif iterations==3 then--identity and memories
input = "<|system|>\n"..modify_string(identity).."</s>\n<|"..Playername.."|>\n"..quer.."</s>\n<|assistant|>"..sum
end
return input
end
if not Error then
local function iterateoutput(output)
local checkedinput
local loadoutput
local previnput
repeat
temperature=1.3-(math.min(.3,iterations/10))
iterations+=1
previnput=HttpService:JSONDecode(output)[1].generated_text
local loadoutput = queryModel(RebuildResponse(output),temperature)
if loadoutput~=nil then
checkedinput=HttpService:JSONDecode(loadoutput)[1].generated_text
if checkedinput then--only update output if valid
output=loadoutput
print(output)
else
break
end
else
break
end
until checkedinput==previnput or iterations>=3
return output
end
output=iterateoutput(output)
end
local permtable={}
local function DecodeResponse(response)--reduce size of system message
local tbl,speakers,str=cm.LocalZephyrDecode(response)
local sum="" for i,v in tbl do for t,o in v do
if t~="narrator" then
if i~=1 then
sum=sum.."\n"..t..": "..o
else sum=sum..""..t..": "..o
end
else
sum=sum.."\n"..o
end end print(sum)
end
return sum
end
local function iterateoutputLLama(output)
local checkedinput
local loadoutput
local previnput=output
repeat
iterations+=1
if output==nil then
return previnput end
previnput=HttpService:JSONDecode(output)[1].generated_text
local loadoutput =cm.TinyLlama(""..identity..timeod..insight..awarobserve..memory..". Parse dialogues with "..person..": and "..Playername..": ." ,quer,DecodeResponse(output))
if loadoutput~=nil then
checkedinput=HttpService:JSONDecode(loadoutput)[1].generated_text
if checkedinput then--only update output if valid
output=loadoutput
print(output)
else
break
end
else
break
end
until checkedinput==previnput or iterations>=3
return output
end