Module: ai

This module exposes various AI APIs.
So far it allows to create chats & images, more features will be added at some point.

ai

Functions

CreateChat ( ai self, string context ) aiChat

Creates a new AI chat with given context.

local ai = require("ai")
local chat = ai:CreateChat("You are a geography expert that answers with answers of 20 words maximum.")
chat:Say("Give me 5 random european countries.", function(err, message)
if err then print(err) return end
print("ai says: " .. message)
end)
CreateImage ( ai self, string prompt, table options, function callback )

Generates image considering prompt and options. Returns a Quad or Shape depending on options.

local ai = require("ai")

ai:CreateImage("a cute cat", function(err, quad)
if err then print(err) return end
quad:SetParent(World)
quad.Position = Player.Position
end)

-- Quad 512x512, default style
ai:CreateImage("a cute cat", { size=512, pixelart=false }, function(err, quad)
if err then print(err) return end
quad.Width = 30
quad.Height = 30
quad:SetParent(World)
quad.Position = Player.Position
end)

-- Quad 256x256, pixel art style
ai:CreateImage("a cute cat", { size=256, pixelart=true }, function(err, quad)
if err then print(err) return end
quad.Width = 30
quad.Height = 30
quad:SetParent(World)
quad.Position = Player.Position
end)

-- Shape, always 32x32 pixel art
ai:CreateImage("a cute cat", { output="Shape", pixelart=true }, function(err, shape)
if err then print(err) return end
shape:SetParent(World)
shape.Position = Player.Position
end)

-- Just URL, you can HTTP:Get the content in the server side and pass it to Client to generate a Shape or a Quad.
-- Useful for multiplayer sync to avoid storing all shapes in memory to send it to new players.
-- You can save URLs and retrieve each Shape/Quad when a new player joins
ai:CreateImage("a cute cat", { size=512, output="Quad", pixelart=false, asURL=true }, function(err, url)
if err then print(err) return end
print("retrieved url: "..url)
Dev:CopyToClipboard(url) -- copy URL to clipboard
end)

aiChat

Functions

Say ( aiChat self, string prompt, function callback )

Says something to aiChat and receives response through callback.

local ai = require("ai")
local chat = ai:CreateChat("You're a pirate, only answer like a grumpy pirate in 20 words max.")
chat:Say("Hey, how's life?", function(err, message)
if err then print(err) return end
print("ai says: " .. message)
end)
📃 Source