One moment, so I have figured it out and have potentially set it up so it can use tools, system message, and input,
local module = {}
local HttpService = game:GetService("HttpService")
local endpoint = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3" -- Replace with your actual endpoint
local apiKey = "" -- Replace with your actual API key
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
local tools =[[{
["type"] = "function",
["function"] = {
name = "gotoLocation",
description = "Move to a location specified by coordinates, call it when instructed to move somewhere",
parameters = {
type = "object",
properties = {
x = {
type = "integer",
description = "The X coordinate"
},
y = {
type = "integer",
description = "The Y coordinate"
},
z = {
type = "integer",
description = "The Z coordinate"
}
},
required = {"x", "y", "z"}
}
}
},
{
["type"] = "function",
["function"] = {
name = "setFollow",
description = "Sets the 'follow' state to true or false as instructed",
parameters = {
type = "object",
properties = {
follow = {
type = "boolean",
description = "The follow state to set (true or false)"
}
},
required = {"follow"}
}
}
}
]]
function module.query(input, system_message)
local messages = {
--{ role = "system", content = system_message },
{ role = "user", content = input }
}
local npcdata = {
-- {
inputs = "<|system|>\n "..system_message.. "</s>\n<|tools|>\n "..tools.. "</s>\n<|user|>\n "..input.."</s>\n<|assistant|>",
max_new_tokens = 512,
do_sample = true,
temperature = 0.7,
top_k = 50,
top_p = 0.95
}
local response = HttpService:RequestAsync({
Url = endpoint,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
["Authorization"] = apiKey
},
Body = HttpService:JSONEncode(npcdata),
})
print(format_response(response.Body))
return HttpService:JSONDecode(response.Body)
end
return module
I had some code lying around from working with a zephyr chatbot and it appears to work great!.
" \n Yes, I have two tools available to me. The first one is "gotoLocation", it takes three arguments ‘x’, ‘y’, and ‘z’ which represent the coordinates of a specific location. This tool allows me to move to a specified location. The second tool is "setFollow", it takes a single argument ‘follow’ that can be set to either true or false. This tool allows me to enable or disable following another entity.“”